diff --git a/src/configuration/configuration.service.ts b/src/configuration/configuration.service.ts index 910da8b5af420bfd2c55204dd9642f72ceb852b9..5ccb5d1cf756dee1eb81aff5a60c3396240ae46c 100644 --- a/src/configuration/configuration.service.ts +++ b/src/configuration/configuration.service.ts @@ -6,6 +6,7 @@ import { configDev } from './config.dev'; import { configRec } from './config.rec'; export class ConfigurationService { private readonly _config; + private readonly _appUrl; constructor() { // Initializing conf with values from var env @@ -28,6 +29,7 @@ export class ConfigurationService { break; } this._config.templates = config.templates; // Add mail templates + this._appUrl = `${config.protocol}://${config.host}${config.port ? ':' + config.port : ''}`; dotenv.config(); } @@ -38,4 +40,8 @@ export class ConfigurationService { get config() { return this._config; } + + get appUrl() { + return this._appUrl; + } } diff --git a/src/mailer/mail-templates/apticStructureDuplication.ejs b/src/mailer/mail-templates/apticStructureDuplication.ejs index 0b30ee72bff6faf595b43702914c0e7bb204b269..78072331c7e08151cae80b81c6cc10b450cb7d1e 100644 --- a/src/mailer/mail-templates/apticStructureDuplication.ejs +++ b/src/mailer/mail-templates/apticStructureDuplication.ejs @@ -1,4 +1,6 @@ Bonjour,<br /> <br /> La fiche structure: <strong><%= name %></strong> a été créée après récupération des données aptic. Elle correspond -potientiellement à la structure existante : <strong><%= duplicatedStructureName %></strong>. +potentiellement à la structure existante : <strong><%= duplicatedStructureName %></strong>.<br /> +<br /> +<a href="<%= duplicatedStructureUrl %>">Aller vérifier la labellisation Pass Numérique de la structure existante</a> diff --git a/src/mailer/mailer.service.ts b/src/mailer/mailer.service.ts index 2914fd1383297e0f862b4405020ca8ed4b61e903..d59ca3d1e82cbf2666670b6838e3f2ffe263337f 100644 --- a/src/mailer/mailer.service.ts +++ b/src/mailer/mailer.service.ts @@ -90,11 +90,7 @@ export class MailerService { * @param html */ public addSignature(html: string): string { - html += `<br /><br /><p>L’équipe projet inclusion numérique.</p><img src="${this.config.protocol}://${ - this.config.host - }${ - this.config.port ? ':' + this.config.port : '' - }/assets/logos/resin.jpg" alt="Logo resin" width="168" height="58"><br /><br /><p>Ce mail est automatique. Merci de ne pas y répondre.</p>`; + html += `<br /><br /><p>L’équipe projet inclusion numérique.</p><img src="${this.configurationService.appUrl}/assets/logos/resin.jpg" alt="Logo resin" width="168" height="58"><br /><br /><p>Ce mail est automatique. Merci de ne pas y répondre.</p>`; return html; } } diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 978a2ecf9d3093ec35e75498b9c863db7cfd6113..24a26bdbd87c0e041fcca54fa6dbaf0e45a10d12 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -241,7 +241,7 @@ export class ApticStructuresService { }) .exec(); if (sameAddrStructure) { - this.userService.sendAdminApticStructureMail(createdStructure.structureName, sameAddrStructure.structureName); + this.userService.sendAdminApticStructureMail(createdStructure.structureName, sameAddrStructure); } } diff --git a/src/users/users.service.spec.ts b/src/users/users.service.spec.ts index 558492b5df107e51b0380755c3ab14a8f29b46af..3b830315abff451d576fcfbe961f40b24ae5dd60 100644 --- a/src/users/users.service.spec.ts +++ b/src/users/users.service.spec.ts @@ -8,6 +8,7 @@ import { HttpException, HttpStatus } from '@nestjs/common'; import { LoginDto } from '../auth/login-dto'; import { EmailChangeDto } from './dto/change-email.dto'; import * as bcrypt from 'bcrypt'; +import { ConfigurationModule } from '../configuration/configuration.module'; function hashPassword() { return bcrypt.hashSync(process.env.USER_PWD, process.env.SALT); @@ -18,7 +19,7 @@ describe('UsersService', () => { beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - imports: [MailerModule], + imports: [MailerModule, ConfigurationModule], providers: [ UsersService, { diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 325205d208ad02942929cf11fee0eddc64ee20b1..993ae82a4b9cd0e139190a81a1514da50763ca3d 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -13,10 +13,15 @@ import { EmailChangeDto } from './dto/change-email.dto'; import { PendingStructureDto } from '../admin/dto/pending-structure.dto'; import { OwnerDto } from './dto/owner.dto'; import { StructureDocument } from '../structures/schemas/structure.schema'; +import { ConfigurationService } from '../configuration/configuration.service'; @Injectable() export class UsersService { - constructor(@InjectModel(User.name) private userModel: Model<IUser>, private readonly mailerService: MailerService) {} + constructor( + @InjectModel(User.name) private userModel: Model<IUser>, + private readonly mailerService: MailerService, + private configurationService: ConfigurationService + ) {} /** * Create a user account @@ -142,7 +147,10 @@ export class UsersService { /** * Send to all admins mail for aptic duplicated data */ - public async sendAdminApticStructureMail(structureName: string, duplicatedStructureName: string): Promise<any> { + public async sendAdminApticStructureMail( + structureName: string, + duplicatedStructure: StructureDocument + ): Promise<any> { const config = this.mailerService.config; const ejsPath = this.mailerService.getTemplateLocation(config.templates.apticStructureDuplication.ejs); const jsonConfig = this.mailerService.loadJsonConfig(config.templates.apticStructureDuplication.json); @@ -150,7 +158,8 @@ export class UsersService { const html = await ejs.renderFile(ejsPath, { config, name: structureName, - duplicatedStructureName: duplicatedStructureName, + duplicatedStructureName: duplicatedStructure.structureName, + duplicatedStructureUrl: this.configurationService.appUrl + '/acteurs?id=' + duplicatedStructure._id, }); const admins = await this.getAdmins(); admins.forEach((admin) => {