Skip to content

Commit

Permalink
refactor(email): template model (#1221)
Browse files Browse the repository at this point in the history
* refactor(chat)!: admin/router missing endpoints/query params/participants actions (#1135)

* refactor(chat): sendInvitation props as object

* fix(chat): missing populate query param from router

* fix(chat): missing search message regex matching

* chore(chat): cleanups

* fix(chat): router invitation token count

* refactor(chat): admin route createRoom participants logs, set creator

* refactor(chat): participants actions

* fix(chat): router query params id types

* feat(chat): router remove member from room route

* fix(chat): admin route getRooms missing params

* fix(chat): admin route deleteRooms missing audit-mode config check

* feat(chat): admin route removeUsers/addUsers/roomInvitations/roomById

* feat(chat): participants join log on invitation accept

* refactor(email): add editor-design JSON email template field
  • Loading branch information
Renc17 authored Nov 4, 2024
1 parent 39ce2ae commit 66c9d3d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions modules/email/src/Email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default class Email extends ManagedModule<Config> {
body: call.request.body,
variables: call.request.variables,
sender: call.request.sender,
jsonTemplate: call.request.jsonTemplate,
};
let errorMessage: string | null = null;
const template = await this.emailService
Expand Down
11 changes: 9 additions & 2 deletions modules/email/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export class AdminHandlers {
}

async createTemplate(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { _id, sender, externalManaged, name, subject, body } = call.request.params;
const { _id, sender, externalManaged, name, subject, body, jsonTemplate } =
call.request.params;

let externalId = undefined;
const body_vars = getHandleBarsValues(body);
Expand Down Expand Up @@ -115,6 +116,7 @@ export class AdminHandlers {
externalManaged,
sender,
externalId,
jsonTemplate,
})
.catch((e: Error) => {
throw new GrpcError(status.INTERNAL, e.message);
Expand Down Expand Up @@ -148,7 +150,10 @@ export class AdminHandlers {
}

const updatedTemplate = await EmailTemplate.getInstance()
.findByIdAndUpdate(call.request.params.id, templateDocument)
.findByIdAndUpdate(call.request.params.id, {
...templateDocument,
jsonTemplate: call.request.bodyParams.jsonTemplate,
})
.catch((e: Error) => {
throw new GrpcError(status.INTERNAL, e.message);
});
Expand Down Expand Up @@ -466,6 +471,7 @@ export class AdminHandlers {
body: ConduitString.Required,
sender: ConduitString.Optional,
externalManaged: ConduitBoolean.Optional,
jsonTemplate: ConduitString.Optional,
},
},
new ConduitRouteReturnDefinition('CreateTemplate', {
Expand All @@ -485,6 +491,7 @@ export class AdminHandlers {
name: ConduitString.Optional,
subject: ConduitString.Optional,
body: ConduitString.Optional,
jsonTemplate: ConduitString.Optional,
},
},
new ConduitRouteReturnDefinition('PatchTemplate', {
Expand Down
1 change: 1 addition & 0 deletions modules/email/src/email.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ message RegisterTemplateRequest {
string body = 3;
repeated string variables = 4;
optional string sender = 5;
optional string jsonTemplate = 6;
}

message RegisterTemplateResponse {
Expand Down
1 change: 1 addition & 0 deletions modules/email/src/interfaces/RegisterTemplateParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface IRegisterTemplateParams {
body: string;
sender?: string;
variables: string[];
jsonTemplate?: string;
}
5 changes: 5 additions & 0 deletions modules/email/src/models/EmailTemplate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const schema: ConduitModel = {
sender: {
type: TYPE.String,
},
jsonTemplate: {
type: TYPE.String,
sqlType: SQLDataType.TEXT,
},
externalManaged: {
type: TYPE.Boolean,
default: false,
Expand Down Expand Up @@ -61,6 +65,7 @@ export class EmailTemplate extends ConduitActiveSchema<EmailTemplate> {
variables?: string[];
sender?: string;
externalManaged: boolean;
jsonTemplate?: string;
externalId?: string;
createdAt: Date;
updatedAt: Date;
Expand Down
3 changes: 2 additions & 1 deletion modules/email/src/services/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class EmailService {
}

async registerTemplate(params: IRegisterTemplateParams) {
const { name, body, subject, variables, sender } = params;
const { name, body, subject, variables, sender, jsonTemplate } = params;

const existing = await EmailTemplate.getInstance().findOne({ name });
if (!isNil(existing)) return existing;
Expand All @@ -58,6 +58,7 @@ export class EmailService {
body,
sender,
variables,
jsonTemplate,
});
}

Expand Down

0 comments on commit 66c9d3d

Please sign in to comment.