Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
9f14ae59ff | |||
![]() |
ce2c399055 | ||
698256cd24 | |||
b6e089e00c | |||
5d7baeb433 | |||
1b522c0df4 |
@ -14,7 +14,8 @@
|
|||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"ovh": "^2.0.3",
|
"ovh": "^2.0.3",
|
||||||
"stripe": "^18.3.0"
|
"stripe": "^18.3.0",
|
||||||
|
"uuid": "^11.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"nodemon": "^3.0.1"
|
"nodemon": "^3.0.1"
|
||||||
|
154
src/server.js
154
src/server.js
@ -1,6 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const ovh = require('ovh');
|
const ovh = require('ovh');
|
||||||
const mailchimp = require('@mailchimp/mailchimp_transactional');
|
const mailchimp = require('@mailchimp/mailchimp_transactional');
|
||||||
const Stripe = require('stripe');
|
const Stripe = require('stripe');
|
||||||
@ -12,7 +13,7 @@ const PORT = process.env.PORT || 8080;
|
|||||||
|
|
||||||
// Configuration CORS
|
// Configuration CORS
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
origin: ['http://local.lecoffreio.4nkweb:3000', 'http://localhost:3000'],
|
origin: ['http://local.lecoffreio.4nkweb:3000', 'http://localhost:3000', 'https://lecoffreio.4nkweb.com'],
|
||||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
allowedHeaders: ['Content-Type', 'Authorization']
|
allowedHeaders: ['Content-Type', 'Authorization']
|
||||||
};
|
};
|
||||||
@ -20,52 +21,99 @@ const corsOptions = {
|
|||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
app.use(express.json());
|
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) {
|
function getOfficeStatus(statusName) {
|
||||||
switch (statusName) {
|
switch (statusName) {
|
||||||
case 'Pourvu':
|
case "Pourvu":
|
||||||
return 'ACTIVATED';
|
return EOfficeStatus.ACTIVATED;
|
||||||
case 'Pourvu mais décédé':
|
case "Pourvu mais décédé":
|
||||||
return 'ACTIVATED';
|
return EOfficeStatus.ACTIVATED;
|
||||||
case 'Sans titulaire':
|
case "Sans titulaire":
|
||||||
return 'ACTIVATED';
|
return EOfficeStatus.ACTIVATED;
|
||||||
case 'Vacance':
|
case "Vacance":
|
||||||
return 'ACTIVATED';
|
return EOfficeStatus.ACTIVATED;
|
||||||
case 'En activité':
|
case "En activité":
|
||||||
return 'ACTIVATED';
|
return EOfficeStatus.ACTIVATED;
|
||||||
default:
|
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) {
|
function getRole(roleName) {
|
||||||
switch (roleName) {
|
switch (roleName) {
|
||||||
case 'Notaire titulaire':
|
case EIdnotRole.NOTAIRE_TITULAIRE:
|
||||||
return { name: 'admin', label: 'Administrateur' };
|
return { name: 'admin' };
|
||||||
case 'Notaire associé':
|
case EIdnotRole.NOTAIRE_ASSOCIE:
|
||||||
return { name: 'admin', label: 'Administrateur' };
|
return { name: 'admin' };
|
||||||
case 'Notaire salarié':
|
case EIdnotRole.NOTAIRE_SALARIE:
|
||||||
return { name: 'notary', label: 'Notaire' };
|
return { name: 'notary' };
|
||||||
case 'Collaborateur':
|
case EIdnotRole.COLLABORATEUR:
|
||||||
return { name: 'notary', label: 'Notaire' };
|
return { name: 'notary' };
|
||||||
case 'Suppléant':
|
case EIdnotRole.SUPPLEANT:
|
||||||
return { name: 'notary', label: 'Notaire' };
|
return { name: 'notary' };
|
||||||
case 'Administrateur':
|
case EIdnotRole.ADMINISTRATEUR:
|
||||||
return { name: 'admin', label: 'Administrateur' };
|
return { name: 'admin' };
|
||||||
case 'Curateur':
|
case EIdnotRole.CURATEUR:
|
||||||
return { name: 'notary', label: 'Notaire' };
|
return { name: 'notary' };
|
||||||
default:
|
default:
|
||||||
return { name: 'default', label: 'Défaut' };
|
return { name: 'default' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCivility(civility) {
|
function getCivility(civility) {
|
||||||
switch (civility) {
|
switch (civility) {
|
||||||
case 'Monsieur':
|
case 'Monsieur':
|
||||||
return 'MALE';
|
return ECivility.MALE;
|
||||||
case 'Madame':
|
case 'Madame':
|
||||||
return 'FEMALE';
|
return ECivility.FEMALE;
|
||||||
default:
|
default:
|
||||||
return 'OTHERS';
|
return ECivility.OTHERS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +187,7 @@ app.post('/api/v1/idnot/user/:code', async (req, res) => {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const idnotUser = {
|
const idNotUser = {
|
||||||
idNot: payload.sub,
|
idNot: payload.sub,
|
||||||
office: {
|
office: {
|
||||||
idNot: payload.entity_idn,
|
idNot: payload.entity_idn,
|
||||||
@ -161,15 +209,19 @@ app.post('/api/v1/idnot/user/:code', async (req, res) => {
|
|||||||
phone_number: userData.numeroTelephone,
|
phone_number: userData.numeroTelephone,
|
||||||
cell_phone_number: userData.numeroMobile ?? userData.numeroTelephone,
|
cell_phone_number: userData.numeroMobile ?? userData.numeroTelephone,
|
||||||
civility: getCivility(userData.personne.civilite)
|
civility: getCivility(userData.personne.civilite)
|
||||||
}
|
},
|
||||||
|
office_role: getOfficeRole(userData.typeLien.name)
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!idnotUser.contact.email) {
|
if (!idNotUser.contact.email) {
|
||||||
console.error("User pro email empty");
|
console.error('User pro email empty');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(idnotUser);
|
const authToken = uuidv4();
|
||||||
|
authTokens.push({ idNot: idNotUser.idNot, authToken });
|
||||||
|
|
||||||
|
res.json({ idNotUser, authToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: 'Internal Server Error',
|
error: 'Internal Server Error',
|
||||||
@ -215,7 +267,7 @@ class SmsService {
|
|||||||
message: message,
|
message: message,
|
||||||
receivers: [phoneNumber],
|
receivers: [phoneNumber],
|
||||||
senderForResponse: false,
|
senderForResponse: false,
|
||||||
sender: "not.IT Fact",
|
sender: 'not.IT Fact',
|
||||||
noStopClause: true
|
noStopClause: true
|
||||||
}, (error, result) => {
|
}, (error, result) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -613,6 +665,36 @@ app.post('/api/subscribe-to-list', validateEmail, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.post('/api/send_reminder', async (req, res) => {
|
||||||
|
const { office, customer } = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const to = customer.contact.email;
|
||||||
|
|
||||||
|
const templateVariables = {
|
||||||
|
office_name: office.name,
|
||||||
|
last_name: customer.contact.last_name || '',
|
||||||
|
first_name: customer.contact.first_name || '',
|
||||||
|
link: `${process.env.APP_HOST}`
|
||||||
|
};
|
||||||
|
|
||||||
|
await EmailService.sendTransactionalEmail(
|
||||||
|
to,
|
||||||
|
ETemplates.DOCUMENT_REMINDER,
|
||||||
|
'Vous avez des documents à déposer pour votre dossier.',
|
||||||
|
templateVariables
|
||||||
|
);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Email envoyé avec succès'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Automatic retry system
|
// Automatic retry system
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
EmailService.retryFailedEmails();
|
EmailService.retryFailedEmails();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user