diff --git a/src/configuration/config.ts b/src/configuration/config.ts index e9d940409b5b8b927e138bb8b33a9e2ff6935743..3d6969e35463dda86086db80ee2bd8f9c762132a 100644 --- a/src/configuration/config.ts +++ b/src/configuration/config.ts @@ -45,5 +45,9 @@ export const config = { ejs: 'structureJoinRequest.ejs', json: 'structureJoinRequest.json', }, + adminStructureCreate: { + ejs: 'adminStructureCreate.ejs', + json: 'adminStructureCreate.json', + }, }, }; diff --git a/src/mailer/mail-templates/adminStructureCreate.ejs b/src/mailer/mail-templates/adminStructureCreate.ejs new file mode 100644 index 0000000000000000000000000000000000000000..41d58470fa059925b790e440caec3c5606dbda1c --- /dev/null +++ b/src/mailer/mail-templates/adminStructureCreate.ejs @@ -0,0 +1,3 @@ +Bonjour<br /> +<br /> +Une nouvelle structure a été créé: <strong><%= name %></strong>. diff --git a/src/mailer/mail-templates/adminStructureCreate.json b/src/mailer/mail-templates/adminStructureCreate.json new file mode 100644 index 0000000000000000000000000000000000000000..6411161d61c43167af972468e272bc69847c581a --- /dev/null +++ b/src/mailer/mail-templates/adminStructureCreate.json @@ -0,0 +1,3 @@ +{ + "subject": "Nouvelle structure" +} diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index ac2e32d264a55e171b5e4802dd6e48ef4168ca08..5f1f1fec7da52bd97fd2e3f4c0091186d2123c01 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -40,6 +40,9 @@ export class StructuresService { user.structuresLink.push(createdStructure._id); user.save(); + // Senc admin notification mail + this.userService.sendAdminNewStructureMail(createdStructure.structureName); + return createdStructure; } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 3086c0c10fb5d0e8cb86e9e4fc7d5ece08973784..e4a081cb3fb15b0d1f88bb68abb706069729be9e 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -140,7 +140,7 @@ export class UsersService { /** * Send to all admins validation email for structures - * a new account. + * new account. */ private async sendAdminStructureValidationMail(): Promise<any> { const config = this.mailerService.config; @@ -156,6 +156,24 @@ export class UsersService { }); } + /** + * Send to all admins notification email for new structures + */ + public async sendAdminNewStructureMail(structureName: string): Promise<any> { + const config = this.mailerService.config; + const ejsPath = this.mailerService.getTemplateLocation(config.templates.adminStructureCreate.ejs); + const jsonConfig = this.mailerService.loadJsonConfig(config.templates.adminStructureCreate.json); + + const html = await ejs.renderFile(ejsPath, { + config, + name: structureName, + }); + const admins = await this.getAdmins(); + admins.forEach((admin) => { + this.mailerService.send(admin.email, jsonConfig.subject, html); + }); + } + /** * Send to all admins mail for aptic duplicated data */ @@ -509,8 +527,6 @@ export class UsersService { } public async searchUsers(searchString: string) { - return this.userModel - .find( {email: new RegExp(searchString, 'i') }) - .exec(); + return this.userModel.find({ email: new RegExp(searchString, 'i') }).exec(); } }