diff --git a/src/configuration/config.ts b/src/configuration/config.ts index 97ab675e89c54d4e224c3ebec86ed372bbb45ce9..de4534cc695b6e734ed862ee60d283319a03253e 100644 --- a/src/configuration/config.ts +++ b/src/configuration/config.ts @@ -61,5 +61,9 @@ export const config = { ejs: 'structureDeletionNotification.ejs', json: 'structureDeletionNotification.json', }, + newApticStructure: { + ejs: 'newApticStructure.ejs', + json: 'newApticStructure.json', + }, }, }; diff --git a/src/mailer/mail-templates/newApticStructure.ejs b/src/mailer/mail-templates/newApticStructure.ejs new file mode 100644 index 0000000000000000000000000000000000000000..1f5c3901157ced708715dc239df047b4ad522cbb --- /dev/null +++ b/src/mailer/mail-templates/newApticStructure.ejs @@ -0,0 +1,6 @@ +Bonjour,<br /> +<br /> +Une nouvelle structure a été crée via Aptic. Ses caractéristiques sont : <br /> +- Nom: <%= name %><br /> +- Adresse: <%= address %><br /> +- Description: <%= description %><br /> diff --git a/src/mailer/mail-templates/newApticStructure.json b/src/mailer/mail-templates/newApticStructure.json new file mode 100644 index 0000000000000000000000000000000000000000..60799afdae187f6af93b9f977b52990466399a29 --- /dev/null +++ b/src/mailer/mail-templates/newApticStructure.json @@ -0,0 +1,3 @@ +{ + "subject": "Nouvelle structure Aptic" +} diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 1833e57fbba23f4a35b652fe641eb9ae60ef7547..46098d0e83ec09f6217ff562f3318f7c77b1c89f 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -97,6 +97,7 @@ export class ApticStructuresService { createdStructure.save(); this.structuresSearchService.indexStructure(createdStructure); // Send admin weird structure mail + this.userService.sendAdminApticNewStructureMail(createdStructure); this.verifyDuplication(createdStructure); } }); diff --git a/src/users/users.service.ts b/src/users/users.service.ts index f44e5f52c246e74d832facc5a1239883b2ecaddc..325205d208ad02942929cf11fee0eddc64ee20b1 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -158,6 +158,26 @@ export class UsersService { }); } + /** + * Send to all admins mail for aptic duplicated data + */ + public async sendAdminApticNewStructureMail(structure: StructureDocument): Promise<any> { + const config = this.mailerService.config; + const ejsPath = this.mailerService.getTemplateLocation(config.templates.newApticStructure.ejs); + const jsonConfig = this.mailerService.loadJsonConfig(config.templates.newApticStructure.json); + + const html = await ejs.renderFile(ejsPath, { + config, + name: structure.structureName, + address: `${structure.address.numero} ${structure.address.street} ${structure.address.commune}`, + description: structure.otherDescription, + }); + const admins = await this.getAdmins(); + admins.forEach((admin) => { + this.mailerService.send(admin.email, jsonConfig.subject, html); + }); + } + /** * Send approval email for user * a new account.