Skip to content

Commit

Permalink
fix: mail templates wording and add referent (#2242)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturlg committed Mar 29, 2024
1 parent 59494d5 commit 25e5b6c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 15 deletions.
18 changes: 9 additions & 9 deletions packages/app/src/api/core-domain/infra/mail/templates.tsx
Expand Up @@ -169,7 +169,7 @@ export const declaration_receipt = (url: string, { declaration }: DeclarationOpm
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos indicateurs et de votre niveau de résultat en matière d’écart de rémunération entre les femmes et les hommes pour l'année ${
declaration.year.getValue() + 1
} au titre des données ${declaration.year.getValue()} conformément aux dispositions de l’article D.1142-5 du code du travail. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
} au titre des données ${declaration.year.getValue()} conformément aux dispositions de l’article D.1142-5 du code du travail. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
Vous avez déclaré un index global ${
declaration.index?.getValue() ? `de ${declaration.index.getValue()}` : "non calculable"
Expand Down Expand Up @@ -232,8 +232,8 @@ Les services de l’administration du travail.
votre niveau de résultat en matière d’écart de rémunération entre les femmes et les hommes pour l'année{" "}
{declaration.year.getValue() + 1} au titre des données {declaration.year.getValue()} conformément aux
dispositions de l’article D.1142-5 du code du travail. L’administration du travail accuse réception par le
présent message de votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre
déclaration.
présent message de votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de
votre déclaration.
</p>

<p>
Expand Down Expand Up @@ -310,7 +310,7 @@ export const opmc_receipt = (): MailTemplate => ({
"Egapro - Déclaration des objectifs de progression et mesures de correction de l’index égalité professionnelle femmes-hommes",
text: `Madame, Monsieur,
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de progression et mesures de correction. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de progression et mesures de correction. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
Pour tout renseignement utile, vous pouvez contacter votre référent égalité professionnelle femmes-hommes au sein de votre DREETS en répondant à ce message.
Expand All @@ -329,7 +329,7 @@ Les services de l’administration du travail.
<p>
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de
progression et mesures de correction. L’administration du travail accuse réception par le présent message de
votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
</p>
<p>
Pour tout renseignement utile, vous pouvez contacter votre référent égalité professionnelle femmes-hommes au
Expand All @@ -346,7 +346,7 @@ export const op_receipt = (): MailTemplate => ({
subject: "Egapro - Déclaration des objectifs de progression de l’index égalité professionnelle femmes-homme",
text: `Madame, Monsieur,
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de progression. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de progression. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
Pour tout renseignement utile, vous pouvez contacter votre référent égalité professionnelle femmes-hommes au sein de votre DREETS en répondant à ce message.
Expand All @@ -365,7 +365,7 @@ Les services de l’administration du travail.
<p>
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos objectifs de
progression. L’administration du travail accuse réception par le présent message de votre due transmission.
Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
</p>
<p>
Pour tout renseignement utile, vous pouvez contacter votre référent égalité professionnelle femmes-hommes au
Expand All @@ -384,7 +384,7 @@ export const balancedRepresentation_receipt = (url: string, year: number): MailT
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos écarts éventuels de représentation entre les femmes et les hommes pour l'année ${
year + 1
} au titre des données ${year}. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé réception ne vaut pas contrôle de conformité de votre déclaration.
} au titre des données ${year}. L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé de réception ne vaut pas contrôle de conformité de votre déclaration.
Si vous souhaitez visualiser ou modifier votre déclaration, veuillez cliquer sur le lien suivant :
Expand All @@ -406,7 +406,7 @@ Les services de l’administration du travail.
<p>
Vous venez de procéder à la transmission aux services du ministre chargé du travail de vos écarts éventuels
de représentation entre les femmes et les hommes pour l'année {year + 1} au titre des données {year}.
L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé
L’administration du travail accuse réception par le présent message de votre due transmission. Cet accusé de
réception ne vaut pas contrôle de conformité de votre déclaration.
</p>
<p>
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/api/core-domain/repo/IReferentRepo.ts
@@ -1,6 +1,8 @@
import { type Referent } from "@common/core-domain/domain/Referent";
import { type Region } from "@common/core-domain/domain/valueObjects/Region";
import { type BulkRepo } from "@common/shared-domain";

export interface IReferentRepo extends BulkRepo<Referent> {
getOneByRegion(region?: Region): Promise<Referent | null>;
truncate(): Promise<void>;
}
@@ -1,6 +1,7 @@
import { type ReferentRaw } from "@api/core-domain/infra/db/raw";
import { sql } from "@api/shared-domain/infra/db/postgres";
import { type Referent } from "@common/core-domain/domain/Referent";
import { type Region } from "@common/core-domain/domain/valueObjects/Region";
import { referentMap } from "@common/core-domain/mappers/referentMap";
import { UnexpectedRepositoryError } from "@common/shared-domain";
import { UniqueID } from "@common/shared-domain/domain/valueObjects";
Expand Down Expand Up @@ -46,6 +47,14 @@ export class PostgresReferentRepo implements IReferentRepo {
return referentMap.toDomain(raw);
}

public async getOneByRegion(region?: Region): Promise<Referent | null> {
if (!region) return null;
const [raw] = await this.sql`select * from ${this.table} where region = ${region.getValue()} limit 1`;

if (!raw) return null;
return referentMap.toDomain(raw);
}

public async save(item: Referent): Promise<UniqueID> {
const raw = referentMap.toPersistence(item);

Expand Down
@@ -1,12 +1,14 @@
import { type IJsxPdfService } from "@api/shared-domain/infra/pdf/IJsxPdfService";
import { config } from "@common/config";
import { ReferentType } from "@common/core-domain/domain/valueObjects/referent/ReferentType";
import { Siren } from "@common/core-domain/domain/valueObjects/Siren";
import { AppError, type UseCase } from "@common/shared-domain";
import { PositiveNumber } from "@common/shared-domain/domain/valueObjects";

import { type IGlobalMailerService } from "../infra/mail/IGlobalMailerService";
import { DeclarationReceipt } from "../infra/pdf/templates/DeclarationReceipt";
import { type IDeclarationRepo } from "../repo/IDeclarationRepo";
import { type IReferentRepo } from "../repo/IReferentRepo";

interface Input {
email: string;
Expand All @@ -17,6 +19,7 @@ interface Input {
export class SendDeclarationReceipt implements UseCase<Input, void> {
constructor(
private readonly declarationRepo: IDeclarationRepo,
private readonly referentRepo: IReferentRepo,
private readonly globalMailerService: IGlobalMailerService,
private readonly jsxPdfService: IJsxPdfService,
) {}
Expand All @@ -31,6 +34,7 @@ export class SendDeclarationReceipt implements UseCase<Input, void> {
throw new SendDeclarationReceiptNotFoundError(`No declaration found with siren ${siren} and year ${year}`);
}

const referent = await this.referentRepo.getOneByRegion(declaration.declaration?.company?.region);
const buffer = await this.jsxPdfService.buffer(DeclarationReceipt(declaration));

const url = `${config.host}/index-egapro/declaration/${siren}/${year}`;
Expand All @@ -39,6 +43,10 @@ export class SendDeclarationReceipt implements UseCase<Input, void> {
"declaration_receipt",
{
to: email,
replyTo:
referent?.value?.getValue() && referent?.type.getValue() === ReferentType.Enum.EMAIL
? referent?.value?.getValue()
: undefined,
attachments: [
{
content: buffer,
Expand Down
12 changes: 12 additions & 0 deletions packages/app/src/api/core-domain/useCases/SendOpmcReceipt.ts
@@ -1,4 +1,6 @@
import { type IReferentRepo } from "@api/core-domain/repo/IReferentRepo";
import { type IJsxPdfService } from "@api/shared-domain/infra/pdf/IJsxPdfService";
import { ReferentType } from "@common/core-domain/domain/valueObjects/referent/ReferentType";
import { Siren } from "@common/core-domain/domain/valueObjects/Siren";
import { AppError, type UseCase } from "@common/shared-domain";
import { PositiveNumber } from "@common/shared-domain/domain/valueObjects";
Expand All @@ -16,6 +18,7 @@ interface Input {
export class SendOpmcReceipt implements UseCase<Input, void> {
constructor(
private readonly declarationRepo: IDeclarationRepo,
private readonly referentRepo: IReferentRepo,
private readonly globalMailerService: IGlobalMailerService,
private readonly jsxPdfService: IJsxPdfService,
) {}
Expand All @@ -30,13 +33,18 @@ export class SendOpmcReceipt implements UseCase<Input, void> {
throw new SendOpmcReceiptNotFoundError(`No declaration found with siren ${siren} and year ${year}`);
}

const referent = await this.referentRepo.getOneByRegion(declarationOpmc.declaration?.company?.region);
const buffer = await this.jsxPdfService.buffer(DeclarationReceipt(declarationOpmc));

await this.globalMailerService.init();
let rejected;
if ((declarationOpmc?.declaration?.index?.getValue() || 0) < 75) {
[, rejected] = await this.globalMailerService.sendMail("opmc_receipt", {
to: email,
replyTo:
referent?.value?.getValue() && referent?.type.getValue() === ReferentType.Enum.EMAIL
? referent?.value?.getValue()
: undefined,
attachments: [
{
content: buffer,
Expand All @@ -48,6 +56,10 @@ export class SendOpmcReceipt implements UseCase<Input, void> {
} else {
[, rejected] = await this.globalMailerService.sendMail("op_receipt", {
to: email,
replyTo:
referent?.value?.getValue() && referent?.type.getValue() === ReferentType.Enum.EMAIL
? referent?.value?.getValue()
: undefined,
attachments: [
{
content: buffer,
Expand Down
@@ -1,5 +1,7 @@
import { type IReferentRepo } from "@api/core-domain/repo/IReferentRepo";
import { type IJsxPdfService } from "@api/shared-domain/infra/pdf/IJsxPdfService";
import { config } from "@common/config";
import { ReferentType } from "@common/core-domain/domain/valueObjects/referent/ReferentType";
import { Siren } from "@common/core-domain/domain/valueObjects/Siren";
import { AppError, type UseCase } from "@common/shared-domain";
import { PositiveNumber } from "@common/shared-domain/domain/valueObjects";
Expand All @@ -17,6 +19,7 @@ interface Input {
export class SendRepresentationEquilibreeReceipt implements UseCase<Input, void> {
constructor(
private readonly representationEquilibreeRepo: IRepresentationEquilibreeRepo,
private readonly referentRepo: IReferentRepo,
private readonly globalMailerService: IGlobalMailerService,
private readonly jsxPdfService: IJsxPdfService,
) {}
Expand All @@ -33,6 +36,7 @@ export class SendRepresentationEquilibreeReceipt implements UseCase<Input, void>
);
}

const referent = await this.referentRepo.getOneByRegion(representationEquilibree.company?.region);
const buffer = await this.jsxPdfService.buffer(
RepresentationEquilibreeReceipt({ repEq: representationEquilibree }),
);
Expand All @@ -43,6 +47,10 @@ export class SendRepresentationEquilibreeReceipt implements UseCase<Input, void>
"balancedRepresentation_receipt",
{
to: email,
replyTo:
referent?.value?.getValue() && referent?.type.getValue() === ReferentType.Enum.EMAIL
? referent?.value?.getValue()
: undefined,
attachments: [
{
content: buffer,
Expand Down
Expand Up @@ -2,7 +2,7 @@

import { globalMailerService } from "@api/core-domain/infra/mail";
import { entrepriseService } from "@api/core-domain/infra/services";
import { declarationRepo } from "@api/core-domain/repo";
import { declarationRepo, referentRepo } from "@api/core-domain/repo";
import { GetDeclarationBySirenAndYear } from "@api/core-domain/useCases/GetDeclarationBySirenAndYear";
import { SaveDeclaration } from "@api/core-domain/useCases/SaveDeclaration";
import { SendDeclarationReceipt } from "@api/core-domain/useCases/SendDeclarationReceipt";
Expand Down Expand Up @@ -50,7 +50,12 @@ export async function saveDeclaration(
const useCase = new SaveDeclaration(declarationRepo, entrepriseService);
await useCase.execute({ declaration, override: session?.user?.staff });

const receiptUseCase = new SendDeclarationReceipt(declarationRepo, globalMailerService, jsxPdfService);
const receiptUseCase = new SendDeclarationReceipt(
declarationRepo,
referentRepo,
globalMailerService,
jsxPdfService,
);

assert(siren, "Siren is required");
assert(year, "Year is required");
Expand Down Expand Up @@ -92,7 +97,7 @@ export async function sendDeclarationReceipt(siren: string, year: number) {
staff: true,
});

const useCase = new SendDeclarationReceipt(declarationRepo, globalMailerService, jsxPdfService);
const useCase = new SendDeclarationReceipt(declarationRepo, referentRepo, globalMailerService, jsxPdfService);

await useCase.execute({ siren, year, email: session.user.email });
}
Expand Up @@ -2,7 +2,7 @@

import { authConfig } from "@api/core-domain/infra/auth/config";
import { globalMailerService } from "@api/core-domain/infra/mail";
import { declarationRepo } from "@api/core-domain/repo";
import { declarationRepo, referentRepo } from "@api/core-domain/repo";
import { GetDeclarationOpmcBySirenAndYear } from "@api/core-domain/useCases/GetDeclarationOpmcBySirenAndYear";
import { SendOpmcReceipt } from "@api/core-domain/useCases/SendOpmcReceipt";
import { UpdateDeclarationWithOpMc } from "@api/core-domain/useCases/UpdateDeclarationWithOpMc";
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function updateDeclarationOpmc({
const useCase = new UpdateDeclarationWithOpMc(declarationRepo);
await useCase.execute({ opmc, siren, year });

const receiptUseCase = new SendOpmcReceipt(declarationRepo, globalMailerService, jsxPdfService);
const receiptUseCase = new SendOpmcReceipt(declarationRepo, referentRepo, globalMailerService, jsxPdfService);

assert(siren, "Siren is required");
assert(year, "Year is required");
Expand Down
Expand Up @@ -2,7 +2,7 @@

import { globalMailerService } from "@api/core-domain/infra/mail";
import { entrepriseService } from "@api/core-domain/infra/services";
import { representationEquilibreeRepo } from "@api/core-domain/repo";
import { referentRepo, representationEquilibreeRepo } from "@api/core-domain/repo";
import { GetRepresentationEquilibreeBySirenAndYear } from "@api/core-domain/useCases/GetRepresentationEquilibreeBySirenAndYear";
import { SaveRepresentationEquilibree } from "@api/core-domain/useCases/SaveRepresentationEquilibree";
import {
Expand Down Expand Up @@ -43,6 +43,7 @@ export async function saveRepresentationEquilibree(repEq: CreateRepresentationEq

const receiptUseCase = new SendRepresentationEquilibreeReceipt(
representationEquilibreeRepo,
referentRepo,
globalMailerService,
jsxPdfService,
);
Expand All @@ -65,6 +66,7 @@ export async function sendRepresentationEquilibreeReceipt(siren: string, year: n

const useCase = new SendRepresentationEquilibreeReceipt(
representationEquilibreeRepo,
referentRepo,
globalMailerService,
jsxPdfService,
);
Expand Down

0 comments on commit 25e5b6c

Please sign in to comment.