main #2
@ -2,7 +2,7 @@ name: Build and Push to Registry
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ test ]
|
branches: [ main ]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: git.4nkweb.com
|
REGISTRY: git.4nkweb.com
|
@ -15,5 +15,5 @@ RUN adduser -D appuser --uid 10000 && \
|
|||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
# Configuration du port et démarrag
|
# Configuration du port et démarrag
|
||||||
EXPOSE 3001
|
EXPOSE 8080
|
||||||
CMD ["npm", "start"]
|
CMD ["npm", "start"]
|
145
src/server.js
145
src/server.js
@ -4,7 +4,7 @@ const fetch = require('node-fetch');
|
|||||||
|
|
||||||
// Initialisation de l'application Express
|
// Initialisation de l'application Express
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3001;
|
const PORT = process.env.PORT || 8080;
|
||||||
|
|
||||||
// Configuration CORS
|
// Configuration CORS
|
||||||
const corsOptions = {
|
const corsOptions = {
|
||||||
@ -16,6 +16,55 @@ const corsOptions = {
|
|||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
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';
|
||||||
|
default:
|
||||||
|
return 'DESACTIVATED';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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' };
|
||||||
|
default:
|
||||||
|
return { name: 'default', label: 'Défaut' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCivility(civility) {
|
||||||
|
switch (civility) {
|
||||||
|
case 'Monsieur':
|
||||||
|
return 'MALE';
|
||||||
|
case 'Madame':
|
||||||
|
return 'FEMALE';
|
||||||
|
default:
|
||||||
|
return 'OTHERS';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.get('/api/v1/health', (req, res) => {
|
app.get('/api/v1/health', (req, res) => {
|
||||||
res.json({ message: 'OK' });
|
res.json({ message: 'OK' });
|
||||||
});
|
});
|
||||||
@ -32,19 +81,91 @@ app.post('/api/v1/idnot/user/:code', async (req, res) => {
|
|||||||
code: code
|
code: code
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch('https://qual-connexion.idnot.fr/user/IdPOAuth2/token/idnot_idp_v1', {
|
const tokens = await (
|
||||||
method: 'POST',
|
await fetch('https://qual-connexion.idnot.fr/user/IdPOAuth2/token/idnot_idp_v1', {
|
||||||
headers: {
|
method: 'POST',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
headers: {
|
||||||
},
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
body: new URLSearchParams(params).toString()
|
},
|
||||||
|
body: new URLSearchParams(params).toString()
|
||||||
|
})
|
||||||
|
).json();
|
||||||
|
|
||||||
|
const jwt = tokens.id_token;
|
||||||
|
if (!jwt) {
|
||||||
|
console.error('jwt not defined');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const payload = JSON.parse(Buffer.from(jwt.split('.')[1], 'base64').toString('utf8'));
|
||||||
|
|
||||||
|
const searchParams = new URLSearchParams({
|
||||||
|
key: 'ba557f84-0bf6-4dbf-844f-df2767555e3e'
|
||||||
});
|
});
|
||||||
|
|
||||||
const json = await response.json();
|
let userData;
|
||||||
res.json({
|
try {
|
||||||
accessToken: json.id_token,
|
userData = await (
|
||||||
refreshToken: json.access_token
|
await fetch(`https://qual-api.notaires.fr/annuaire/api/pp/v2/rattachements/${payload.profile_idn}?` + searchParams, {
|
||||||
});
|
method: 'GET'
|
||||||
|
})
|
||||||
|
).json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching ' + `https://qual-api.notaires.fr/annuaire/api/pp/v2/rattachements/${payload.profile_idn}`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!userData || !userData.statutDuRattachement || userData.entite.typeEntite.name !== 'office') {
|
||||||
|
console.error('User not attached to an office (May be a partner)');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let officeLocationData;
|
||||||
|
try {
|
||||||
|
officeLocationData = (await (
|
||||||
|
await fetch(`https://qual-api.notaires.fr/annuaire${userData.entite.locationsUrl}?` + searchParams,
|
||||||
|
{
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
).json());
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching' + `https://qual-api.notaires.fr/annuaire${userData.entite.locationsUrl}`, error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!officeLocationData || !officeLocationData.result || officeLocationData.result.length === 0) {
|
||||||
|
console.error('Office location data not found');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const idnotUser = {
|
||||||
|
idNot: payload.sub,
|
||||||
|
office: {
|
||||||
|
idNot: payload.entity_idn,
|
||||||
|
name: userData.entite.denominationSociale ?? userData.entite.codeCrpcen,
|
||||||
|
crpcen: userData.entite.codeCrpcen,
|
||||||
|
office_status: getOfficeStatus(userData.entite.statutEntite.name),
|
||||||
|
address: {
|
||||||
|
address: officeLocationData.result[0].adrGeo4,
|
||||||
|
city: officeLocationData.result[0].adrGeoVille.split(' ')[0] ?? officeLocationData.result[0].adrGeoVille,
|
||||||
|
zip_code: Number(officeLocationData.result[0].adrGeoCodePostal)
|
||||||
|
},
|
||||||
|
status: 'ACTIVE'
|
||||||
|
},
|
||||||
|
role: getRole(userData.typeLien.name),
|
||||||
|
contact: {
|
||||||
|
first_name: userData.personne.prenom,
|
||||||
|
last_name: userData.personne.nomUsuel,
|
||||||
|
email: userData.mailRattachement,
|
||||||
|
phone_number: userData.numeroTelephone,
|
||||||
|
cell_phone_number: userData.numeroMobile ?? userData.numeroTelephone,
|
||||||
|
civility: getCivility(userData.personne.civilite)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!idnotUser.contact.email) {
|
||||||
|
console.error("User pro email empty");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(idnotUser);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
error: 'Internal Server Error',
|
error: 'Internal Server Error',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user