Improve idnot api
This commit is contained in:
parent
7e679ae33f
commit
1465c9dfd2
@ -231,54 +231,62 @@ app.get('/api/v1/db/:tableName', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/notaries', async (req, res) => {
|
||||
const page = req.query.page || 1;
|
||||
const size = req.query.size || 10;
|
||||
const firstName = req.query.firstName || null;
|
||||
const lastName = req.query.lastName || null;
|
||||
// Returns all the office data for each rattachement of the user
|
||||
app.get('/api/v1/idnot/user/rattachements', async (req, res) => {
|
||||
const { idNot } = req.query;
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
key: 'ba557f84-0bf6-4dbf-844f-df2767555e3e'
|
||||
key: process.env.IDNOT_API_KEY,
|
||||
deleted: false
|
||||
});
|
||||
|
||||
try {
|
||||
let url = `https://qual-api.notaires.fr/annuaire/api/pp/v2/personnes?page=${page}&size=${size}`;
|
||||
if (firstName) {
|
||||
url += `&ctmPrenom=${firstName}`;
|
||||
}
|
||||
if (lastName) {
|
||||
url += `&ctmNomUsuel=${lastName}`;
|
||||
}
|
||||
const url = `${process.env.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/personnes/${idNot}/rattachements?` + searchParams;
|
||||
|
||||
const json = await (
|
||||
await fetch(`${url}&` + searchParams, {
|
||||
await fetch(url, {
|
||||
method: 'GET'
|
||||
})
|
||||
).json();
|
||||
|
||||
json.result = json.result.map(r => {
|
||||
return {
|
||||
id: r.uid,
|
||||
activity: r.activite,
|
||||
civility: getCivility(r.civility),
|
||||
lastName: r.nomUsuel,
|
||||
firstName: r.prenom,
|
||||
crpcen: r.numeroAdherentCrpcen,
|
||||
lastModified: r.lastModified,
|
||||
deleted: r.deleted
|
||||
// if json.result.length is 0, return 404
|
||||
if (json.result.length === 0) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: 'No rattachements found'
|
||||
});
|
||||
}
|
||||
|
||||
// Iterate over all results and get the office data by calling the entiteUrl endpoint
|
||||
const officeData = await Promise.all(json.result.map(async (result) => {
|
||||
const officeData = await (
|
||||
await fetch(`${process.env.IDNOT_ANNUARY_BASE_URL}${result.entiteUrl}?` + searchParams, {
|
||||
method: 'GET'
|
||||
})
|
||||
).json();
|
||||
return officeData;
|
||||
}));
|
||||
|
||||
res.json(officeData);
|
||||
});
|
||||
|
||||
json.totalPages = Math.ceil(json.totalResultCount / json.size);
|
||||
delete json.totalResultCount;
|
||||
// Returns the user data for each user rattached to an entity
|
||||
app.get('/api/v1/idnot/office/rattachements', async (req, res) => {
|
||||
const { idNot } = req.query;
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
key: process.env.IDNOT_API_KEY,
|
||||
deleted: false
|
||||
});
|
||||
|
||||
const url = `${process.env.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/entites/${idNot}/personnes?` + searchParams;
|
||||
|
||||
const json = await (
|
||||
await fetch(url, {
|
||||
method: 'GET'
|
||||
})
|
||||
).json();
|
||||
|
||||
res.json(json);
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
error: 'Internal Server Error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/v1/idnot/user/:code', async (req, res) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user