feat: add email template schema

This commit is contained in:
Lakhan Samani
2022-07-15 10:12:24 +05:30
parent fed092bb65
commit 14c74f6566
13 changed files with 756 additions and 0 deletions

View 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,
}
}

View File

@@ -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",
}
)

View File

@@ -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)

View File

@@ -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+"/") {