Skip to content
Snippets Groups Projects
Commit 2dd8cdae authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

Merge branch 'feat/report-structure-error' into 'dev'

Feat/report structure error

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_server!57
parents 0d2e5996 f720d131
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!62Dev,!57Feat/report structure error
......@@ -49,5 +49,9 @@ export const config = {
ejs: 'adminStructureCreate.ejs',
json: 'adminStructureCreate.json',
},
structureErrorReport: {
ejs: 'structureErrorReport.ejs',
json: 'structureErrorReport.json',
},
},
};
Bonjour<br />
<br />
Un utilisateur de Res'in a relevé une erreur sur la fiche de votre structure (<%= structureName %>).
<br />
Voici le message:<br />
<br />
<strong><%= content %></strong><br />
<br />
<a href="<%= config.protocol %>://<%= config.host %><%= config.port ? ':' + config.port : '' %>/acteurs?id=<%= id %>"
>Acceder à votre structure</a
>.
{
"subject": "Une erreur a été remontée sur votre structure, Réseau des Acteurs de la Médiation Numérique de la Métropole de Lyon"
}
......@@ -21,15 +21,15 @@ export class MailerService {
* @param {string} html
* @param {string} text
*/
public async send(to: string, subject: string, html: string): Promise<AxiosResponse<any>> {
public async send(to: string | { email: string }[], subject: string, html: string): Promise<AxiosResponse<any>> {
const emailsToSend = typeof to === 'string' ? [{ email: to }] : to;
const formData = new FormData();
const data = JSON.stringify({
// eslint-disable-next-line camelcase
from_email: this.config.from,
// eslint-disable-next-line camelcase
from_name: this.config.from_name,
to: [{ email: to }],
to: emailsToSend,
reply_to: 'inclusionnumerique@grandlyon.com',
subject: subject,
content: this.addSignature(html),
......
......@@ -316,7 +316,7 @@ export class StructuresService {
return this.userService.getStructureOwners(structureId);
}
public async updateAccountVerified(idStructure: string, emailUser: string): Promise<Structure> {
public async updateAccountVerified(idStructure: string): Promise<Structure> {
const structureLinked = await this.findOne(idStructure);
const structure = new this.structureModel(structureLinked);
if (!structure) {
......@@ -338,4 +338,31 @@ export class StructuresService {
const owners = await this.userService.getStructureOwnersMails(idStructure, emailUser);
return { structure: structure, owners: owners };
}
public async reportStructureError(structureId: string, content: string) {
const structure = await this.findOne(structureId);
if (!structure) {
throw new HttpException('Invalid structure id', HttpStatus.BAD_REQUEST);
}
const owners = await this.userService.getStructureOwnersMails(structure._id, '');
const admins = await this.userService.getAdmins();
const emails = owners.map((owner) => owner.email).concat(admins.map((admin) => admin.email));
const uniqueEmails = [...new Set(emails)];
const emailsObject: { email: string }[] = uniqueEmails.map((item) => {
return { email: item };
});
const config = this.mailerService.config;
const ejsPath = this.mailerService.getTemplateLocation(config.templates.structureErrorReport.ejs);
const jsonConfig = this.mailerService.loadJsonConfig(config.templates.structureErrorReport.json);
const html = await ejs.renderFile(ejsPath, {
config,
content: content,
id: structure._id,
structureName: structure.structureName,
});
this.mailerService.send(emailsObject, jsonConfig.subject, html);
}
}
......@@ -63,11 +63,8 @@ export class StructuresController {
}
@Put('updateAfterOwnerVerify/:id')
public async updateAfterOwnerVerify(
@Param('id') id: string,
@Body() body: { emailUser: string }
): Promise<Structure> {
return this.structureService.updateAccountVerified(id, body.emailUser);
public async updateAfterOwnerVerify(@Param('id') id: string): Promise<Structure> {
return this.structureService.updateAccountVerified(id);
}
@Put(':id')
......@@ -235,4 +232,9 @@ export class StructuresController {
}
this.userService.removeFromStructureLinked(userFromDb.email, id);
}
@Post('reportStructureError')
public async reportStructureError(@Body() data: { structureId: string; content: string }): Promise<void> {
return await this.structureService.reportStructureError(data.structureId, data.content);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment