feat: add email template schema
This commit is contained in:
32
server/db/models/email_templates.go
Normal file
32
server/db/models/email_templates.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||
)
|
||||
|
||||
// EmailTemplate model for database
|
||||
type EmailTemplate struct {
|
||||
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty"` // for arangodb
|
||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id"`
|
||||
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name"`
|
||||
Template string `gorm:"type:text" json:"endpoint" bson:"endpoint" cql:"endpoint"`
|
||||
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||
}
|
||||
|
||||
// AsAPIEmailTemplate to return email template as graphql response object
|
||||
func (e *EmailTemplate) AsAPIEmailTemplate() *model.EmailTemplate {
|
||||
id := e.ID
|
||||
if strings.Contains(id, Collections.EmailTemplate+"/") {
|
||||
id = strings.TrimPrefix(id, Collections.EmailTemplate+"/")
|
||||
}
|
||||
return &model.EmailTemplate{
|
||||
ID: id,
|
||||
EventName: e.EventName,
|
||||
Template: e.Template,
|
||||
CreatedAt: &e.CreatedAt,
|
||||
UpdatedAt: &e.UpdatedAt,
|
||||
}
|
||||
}
|
@@ -8,6 +8,7 @@ type CollectionList struct {
|
||||
Env string
|
||||
Webhook string
|
||||
WebhookLog string
|
||||
EmailTemplate string
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,5 +22,6 @@ var (
|
||||
Env: Prefix + "env",
|
||||
Webhook: Prefix + "webhook",
|
||||
WebhookLog: Prefix + "webhook_log",
|
||||
EmailTemplate: Prefix + "email_template",
|
||||
}
|
||||
)
|
||||
|
@@ -21,6 +21,7 @@ type Webhook struct {
|
||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||
}
|
||||
|
||||
// AsAPIWebhook to return webhook as graphql response object
|
||||
func (w *Webhook) AsAPIWebhook() *model.Webhook {
|
||||
headersMap := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(w.Headers), &headersMap)
|
||||
|
@@ -20,6 +20,7 @@ type WebhookLog struct {
|
||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at"`
|
||||
}
|
||||
|
||||
// AsAPIWebhookLog to return webhook log as graphql response object
|
||||
func (w *WebhookLog) AsAPIWebhookLog() *model.WebhookLog {
|
||||
id := w.ID
|
||||
if strings.Contains(id, Collections.WebhookLog+"/") {
|
||||
|
Reference in New Issue
Block a user