@@ -17,11 +17,9 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
1717 emailTemplate .ID = uuid .New ().String ()
1818 emailTemplate .Key = emailTemplate .ID
1919 }
20-
2120 emailTemplate .Key = emailTemplate .ID
2221 emailTemplate .CreatedAt = time .Now ().Unix ()
2322 emailTemplate .UpdatedAt = time .Now ().Unix ()
24-
2523 emailTemplateCollection , _ := p .db .Collection (ctx , models .Collections .EmailTemplate )
2624 _ , err := emailTemplateCollection .CreateDocument (ctx , emailTemplate )
2725 if err != nil {
@@ -33,13 +31,11 @@ func (p *provider) AddEmailTemplate(ctx context.Context, emailTemplate *models.E
3331// UpdateEmailTemplate to update EmailTemplate
3432func (p * provider ) UpdateEmailTemplate (ctx context.Context , emailTemplate * models.EmailTemplate ) (* model.EmailTemplate , error ) {
3533 emailTemplate .UpdatedAt = time .Now ().Unix ()
36-
3734 emailTemplateCollection , _ := p .db .Collection (ctx , models .Collections .EmailTemplate )
3835 meta , err := emailTemplateCollection .UpdateDocument (ctx , emailTemplate .Key , emailTemplate )
3936 if err != nil {
4037 return nil , err
4138 }
42-
4339 emailTemplate .Key = meta .Key
4440 emailTemplate .ID = meta .ID .String ()
4541 return emailTemplate .AsAPIEmailTemplate (), nil
@@ -57,22 +53,18 @@ func (p *provider) ListEmailTemplate(ctx context.Context, pagination *model.Pagi
5753 defer cursor .Close ()
5854 paginationClone := pagination
5955 paginationClone .Total = cursor .Statistics ().FullCount ()
60-
6156 for {
6257 var emailTemplate * models.EmailTemplate
6358 meta , err := cursor .ReadDocument (ctx , & emailTemplate )
64-
6559 if arangoDriver .IsNoMoreDocuments (err ) {
6660 break
6761 } else if err != nil {
6862 return nil , err
6963 }
70-
7164 if meta .Key != "" {
7265 emailTemplates = append (emailTemplates , emailTemplate .AsAPIEmailTemplate ())
7366 }
7467 }
75-
7668 return & model.EmailTemplates {
7769 Pagination : paginationClone ,
7870 EmailTemplates : emailTemplates ,
@@ -86,16 +78,14 @@ func (p *provider) GetEmailTemplateByID(ctx context.Context, emailTemplateID str
8678 bindVars := map [string ]interface {}{
8779 "email_template_id" : emailTemplateID ,
8880 }
89-
9081 cursor , err := p .db .Query (ctx , query , bindVars )
9182 if err != nil {
9283 return nil , err
9384 }
9485 defer cursor .Close ()
95-
9686 for {
9787 if ! cursor .HasMore () {
98- if emailTemplate . Key == "" {
88+ if emailTemplate == nil {
9989 return nil , fmt .Errorf ("email template not found" )
10090 }
10191 break
@@ -115,16 +105,14 @@ func (p *provider) GetEmailTemplateByEventName(ctx context.Context, eventName st
115105 bindVars := map [string ]interface {}{
116106 "event_name" : eventName ,
117107 }
118-
119108 cursor , err := p .db .Query (ctx , query , bindVars )
120109 if err != nil {
121110 return nil , err
122111 }
123112 defer cursor .Close ()
124-
125113 for {
126114 if ! cursor .HasMore () {
127- if emailTemplate . Key == "" {
115+ if emailTemplate == nil {
128116 return nil , fmt .Errorf ("email template not found" )
129117 }
130118 break
0 commit comments