Fix some issues
All checks were successful
Build and Push to Registry / build-and-push (push) Successful in 31s

This commit is contained in:
Anthony Janin 2025-07-23 12:12:32 +02:00
parent 3855c739bc
commit 1632720e1b
2 changed files with 442 additions and 322 deletions

View File

@ -13,7 +13,8 @@
"dotenv": "^17.2.0",
"express": "^4.18.2",
"node-fetch": "^2.6.7",
"ovh": "^2.0.3"
"ovh": "^2.0.3",
"uuid": "^11.1.0"
},
"devDependencies": {
"nodemon": "^3.0.1"

View File

@ -1,6 +1,7 @@
const express = require('express');
const cors = require('cors');
const fetch = require('node-fetch');
const { v4: uuidv4 } = require('uuid');
const ovh = require('ovh');
const mailchimp = require('@mailchimp/mailchimp_transactional');
require('dotenv').config();
@ -19,52 +20,99 @@ const corsOptions = {
app.use(cors(corsOptions));
app.use(express.json());
const authTokens = [];
const ECivility = {
MALE: 'MALE',
FEMALE: 'FEMALE',
OTHERS: 'OTHERS'
};
const EOfficeStatus = {
ACTIVATED: 'ACTIVATED',
DESACTIVATED: 'DESACTIVATED'
};
const EIdnotRole = {
DIRECTEUR: "Directeur général du CSN",
NOTAIRE_TITULAIRE: "Notaire titulaire",
NOTAIRE_ASSOCIE: "Notaire associé",
NOTAIRE_SALARIE: "Notaire salarié",
COLLABORATEUR: "Collaborateur",
SECRETAIRE_GENERAL: "Secrétaire général",
SUPPLEANT: "Suppléant",
ADMINISTRATEUR: "Administrateur",
RESPONSABLE: "Responsable",
CURATEUR: "Curateur",
}
function getOfficeStatus(statusName) {
switch (statusName) {
case 'Pourvu':
return 'ACTIVATED';
case 'Pourvu mais décédé':
return 'ACTIVATED';
case 'Sans titulaire':
return 'ACTIVATED';
case 'Vacance':
return 'ACTIVATED';
case 'En activité':
return 'ACTIVATED';
case "Pourvu":
return EOfficeStatus.ACTIVATED;
case "Pourvu mais décédé":
return EOfficeStatus.ACTIVATED;
case "Sans titulaire":
return EOfficeStatus.ACTIVATED;
case "Vacance":
return EOfficeStatus.ACTIVATED;
case "En activité":
return EOfficeStatus.ACTIVATED;
default:
return 'DESACTIVATED';
return EOfficeStatus.DESACTIVATED;
}
}
function getOfficeRole(roleName) {
switch (roleName) {
case EIdnotRole.NOTAIRE_TITULAIRE:
return { name: 'Notaire' };
case EIdnotRole.NOTAIRE_ASSOCIE:
return { name: 'Notaire' };
case EIdnotRole.NOTAIRE_SALARIE:
return { name: 'Notaire' };
case EIdnotRole.COLLABORATEUR:
return { name: 'Collaborateur' };
case EIdnotRole.SUPPLEANT:
return { name: 'Collaborateur' };
case EIdnotRole.ADMINISTRATEUR:
return { name: 'Collaborateur' };
case EIdnotRole.CURATEUR:
return { name: 'Collaborateur' };
default:
return null;
}
}
function getRole(roleName) {
switch (roleName) {
case 'Notaire titulaire':
return { name: 'admin', label: 'Administrateur' };
case 'Notaire associé':
return { name: 'admin', label: 'Administrateur' };
case 'Notaire salarié':
return { name: 'notary', label: 'Notaire' };
case 'Collaborateur':
return { name: 'notary', label: 'Notaire' };
case 'Suppléant':
return { name: 'notary', label: 'Notaire' };
case 'Administrateur':
return { name: 'admin', label: 'Administrateur' };
case 'Curateur':
return { name: 'notary', label: 'Notaire' };
case EIdnotRole.NOTAIRE_TITULAIRE:
return { name: 'admin' };
case EIdnotRole.NOTAIRE_ASSOCIE:
return { name: 'admin' };
case EIdnotRole.NOTAIRE_SALARIE:
return { name: 'notary' };
case EIdnotRole.COLLABORATEUR:
return { name: 'notary' };
case EIdnotRole.SUPPLEANT:
return { name: 'notary' };
case EIdnotRole.ADMINISTRATEUR:
return { name: 'admin' };
case EIdnotRole.CURATEUR:
return { name: 'notary' };
default:
return { name: 'default', label: 'Défaut' };
return { name: 'default' };
}
}
function getCivility(civility) {
switch (civility) {
case 'Monsieur':
return 'MALE';
return ECivility.MALE;
case 'Madame':
return 'FEMALE';
return ECivility.FEMALE;
default:
return 'OTHERS';
return ECivility.OTHERS;
}
}
@ -138,7 +186,7 @@ app.post('/api/v1/idnot/user/:code', async (req, res) => {
return null;
}
const idnotUser = {
const idNotUser = {
idNot: payload.sub,
office: {
idNot: payload.entity_idn,
@ -160,15 +208,19 @@ app.post('/api/v1/idnot/user/:code', async (req, res) => {
phone_number: userData.numeroTelephone,
cell_phone_number: userData.numeroMobile ?? userData.numeroTelephone,
civility: getCivility(userData.personne.civilite)
}
},
office_role: getOfficeRole(userData.typeLien.name)
};
if (!idnotUser.contact.email) {
console.error("User pro email empty");
if (!idNotUser.contact.email) {
console.error('User pro email empty');
return null;
}
res.json(idnotUser);
const authToken = uuidv4();
authTokens.push({ idNot: idNotUser.idNot, authToken });
res.json({ idNotUser, authToken });
} catch (error) {
res.status(500).json({
error: 'Internal Server Error',
@ -214,7 +266,7 @@ class SmsService {
message: message,
receivers: [phoneNumber],
senderForResponse: false,
sender: "not.IT Fact",
sender: 'not.IT Fact',
noStopClause: true
}, (error, result) => {
if (error) {
@ -612,6 +664,73 @@ app.post('/api/subscribe-to-list', validateEmail, async (req, res) => {
}
});
app.post('/api/:uid/send_reminder', validateEmail, async (req, res) => {
const { email, documentsUid } = req.body;
try {
const uid = req.params["uid"];
if (!uid) {
//this.httpBadRequest(response, "No uid provided");
return;
}
if (!documentsUid || !Array.isArray(documentsUid)) {
//this.httpBadRequest(response, "Invalid or missing documents");
return;
}
/*
const documentEntities: Documents[] = [];
//For each document uid, use DocumentsService.getByUid to get the document entity and add it to the documents array
for (const documentUid of documentsUid) {
const documentEntity = await this.documentsService.getByUid(documentUid, { document_type: true, folder: true });
if (!documentEntity) {
this.httpBadRequest(response, "Document not found");
return;
}
documentEntities.push(documentEntity);
}
const customerEntity = await this.customersService.getByUid(uid, { contact: true, office: true });
if (!customerEntity) {
this.httpNotFoundRequest(response, "customer not found");
return;
}
//Hydrate ressource with prisma entity
const customer = Customer.hydrate < Customer > (customerEntity, { strategy: "excludeAll" });
// Call service to send reminder with documents
await this.customersService.sendDocumentsReminder(customer, documentEntities);
*/
const templateVariables = {
first_name: 'firstName' || '',
last_name: 'lastName' || '',
office_name: 'officeName' || '',
link: `${process.env.APP_HOST}`
};
const result = await EmailService.sendTransactionalEmail(
email,
ETemplates.DOCUMENT_REMINDER,
'Votre notaire vous envoie un message',
templateVariables
);
console.log(result);
res.json({
success: true,
message: 'Email envoyé avec succès'
});
} catch (error) {
console.log(error);
return;
}
});
// Automatic retry system
setInterval(() => {
EmailService.retryFailedEmails();