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) => {
|
// Returns all the office data for each rattachement of the user
|
||||||
const page = req.query.page || 1;
|
app.get('/api/v1/idnot/user/rattachements', async (req, res) => {
|
||||||
const size = req.query.size || 10;
|
const { idNot } = req.query;
|
||||||
const firstName = req.query.firstName || null;
|
|
||||||
const lastName = req.query.lastName || null;
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
key: 'ba557f84-0bf6-4dbf-844f-df2767555e3e'
|
key: process.env.IDNOT_API_KEY,
|
||||||
|
deleted: false
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
const url = `${process.env.IDNOT_ANNUARY_BASE_URL}/api/pp/v2/personnes/${idNot}/rattachements?` + searchParams;
|
||||||
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 json = await (
|
const json = await (
|
||||||
await fetch(`${url}&` + searchParams, {
|
await fetch(url, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
).json();
|
).json();
|
||||||
|
|
||||||
json.result = json.result.map(r => {
|
// if json.result.length is 0, return 404
|
||||||
return {
|
if (json.result.length === 0) {
|
||||||
id: r.uid,
|
return res.status(404).json({
|
||||||
activity: r.activite,
|
success: false,
|
||||||
civility: getCivility(r.civility),
|
message: 'No rattachements found'
|
||||||
lastName: r.nomUsuel,
|
});
|
||||||
firstName: r.prenom,
|
|
||||||
crpcen: r.numeroAdherentCrpcen,
|
|
||||||
lastModified: r.lastModified,
|
|
||||||
deleted: r.deleted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
// Returns the user data for each user rattached to an entity
|
||||||
delete json.totalResultCount;
|
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);
|
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) => {
|
app.post('/api/v1/idnot/user/:code', async (req, res) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user