Compare commits
No commits in common. "main" and "stripe" have entirely different histories.
@ -14,8 +14,7 @@
|
|||||||
"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,7 +1,6 @@
|
|||||||
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');
|
||||||
@ -13,7 +12,7 @@ const PORT = process.env.PORT || 8080;
|
|||||||
|
|
||||||
// Configuration CORS
|
// Configuration CORS
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
origin: ['http://local.lecoffreio.4nkweb:3000', 'http://localhost:3000', 'https://lecoffreio.4nkweb.com'],
|
origin: ['http://local.lecoffreio.4nkweb:3000', 'http://localhost:3000'],
|
||||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
allowedHeaders: ['Content-Type', 'Authorization']
|
allowedHeaders: ['Content-Type', 'Authorization']
|
||||||
};
|
};
|
||||||
@ -21,99 +20,52 @@ 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 EOfficeStatus.ACTIVATED;
|
return 'ACTIVATED';
|
||||||
case "Pourvu mais décédé":
|
case 'Pourvu mais décédé':
|
||||||
return EOfficeStatus.ACTIVATED;
|
return 'ACTIVATED';
|
||||||
case "Sans titulaire":
|
case 'Sans titulaire':
|
||||||
return EOfficeStatus.ACTIVATED;
|
return 'ACTIVATED';
|
||||||
case "Vacance":
|
case 'Vacance':
|
||||||
return EOfficeStatus.ACTIVATED;
|
return 'ACTIVATED';
|
||||||
case "En activité":
|
case 'En activité':
|
||||||
return EOfficeStatus.ACTIVATED;
|
return 'ACTIVATED';
|
||||||
default:
|
default:
|
||||||
return EOfficeStatus.DESACTIVATED;
|
return '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 EIdnotRole.NOTAIRE_TITULAIRE:
|
case 'Notaire titulaire':
|
||||||
return { name: 'admin' };
|
return { name: 'admin', label: 'Administrateur' };
|
||||||
case EIdnotRole.NOTAIRE_ASSOCIE:
|
case 'Notaire associé':
|
||||||
return { name: 'admin' };
|
return { name: 'admin', label: 'Administrateur' };
|
||||||
case EIdnotRole.NOTAIRE_SALARIE:
|
case 'Notaire salarié':
|
||||||
return { name: 'notary' };
|
return { name: 'notary', label: 'Notaire' };
|
||||||
case EIdnotRole.COLLABORATEUR:
|
case 'Collaborateur':
|
||||||
return { name: 'notary' };
|
return { name: 'notary', label: 'Notaire' };
|
||||||
case EIdnotRole.SUPPLEANT:
|
case 'Suppléant':
|
||||||
return { name: 'notary' };
|
return { name: 'notary', label: 'Notaire' };
|
||||||
case EIdnotRole.ADMINISTRATEUR:
|
case 'Administrateur':
|
||||||
return { name: 'admin' };
|
return { name: 'admin', label: 'Administrateur' };
|
||||||
case EIdnotRole.CURATEUR:
|
case 'Curateur':
|
||||||
return { name: 'notary' };
|
return { name: 'notary', label: 'Notaire' };
|
||||||
default:
|
default:
|
||||||
return { name: 'default' };
|
return { name: 'default', label: 'Défaut' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCivility(civility) {
|
function getCivility(civility) {
|
||||||
switch (civility) {
|
switch (civility) {
|
||||||
case 'Monsieur':
|
case 'Monsieur':
|
||||||
return ECivility.MALE;
|
return 'MALE';
|
||||||
case 'Madame':
|
case 'Madame':
|
||||||
return ECivility.FEMALE;
|
return 'FEMALE';
|
||||||
default:
|
default:
|
||||||
return ECivility.OTHERS;
|
return 'OTHERS';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +139,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,
|
||||||
@ -209,19 +161,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
const authToken = uuidv4();
|
res.json(idnotUser);
|
||||||
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',
|
||||||
@ -267,7 +215,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) {
|
||||||
@ -665,36 +613,6 @@ 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