From ed7edef021f4fe49cc33909b66ef6c4aff824e1a Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Mon, 18 Aug 2025 17:54:18 +0200 Subject: [PATCH] Fix some issues --- src/server.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 004cf32..99c7a98 100644 --- a/src/server.js +++ b/src/server.js @@ -143,7 +143,7 @@ app.get('/api/v1/db/:tableName', async (req, res) => { if (tableName === 'rules_groups') { const rulesGroups = await Promise.all((await Database.query(`SELECT * FROM ${tableName} ORDER BY 1 LIMIT $1 OFFSET $2`, [limit, offset])).rows.map(async (ruleGroup) => { - const result = await Database.query(`SELECT a.* FROM rules AS a JOIN "_RulesGroupsHasRules" as b ON a.uid = b."A" AND b."B" = '${ruleGroup.uid}';`); + const result = await Database.query(`SELECT a.* FROM rules AS a JOIN "_RulesGroupsHasRules" as b ON b."A" = a.uid AND b."B" = '${ruleGroup.uid}';`); return { uid: ruleGroup.uid, name: ruleGroup.name, @@ -171,6 +171,39 @@ app.get('/api/v1/db/:tableName', async (req, res) => { table: tableName, timestamp: new Date().toISOString() }); + } else if (tableName === 'office_roles') { + const officeRoles = await Promise.all((await Database.query(`SELECT * FROM ${tableName} ORDER BY 1 LIMIT $1 OFFSET $2`, [limit, offset])).rows.map(async (officeRole) => { + const result = await Database.query(`SELECT a.* FROM rules AS a JOIN "_OfficeRolesHasRules" as b ON b."B" = a.uid AND b."A" = '${officeRole.uid}';`); + return { + uid: officeRole.uid, + name: officeRole.name, + office: { + uid: officeRole.office_uid + }, + rules: result.rows.map((rule) => { + return { + uid: rule.uid + } + }), + created_at: officeRole.created_at, + updated_at: officeRole.updated_at + }; + })); + + res.json({ + success: true, + data: officeRoles, + pagination: { + page, + limit, + total, + totalPages: Math.ceil(total / limit), + hasNextPage: page < Math.ceil(total / limit), + hasPrevPage: page > 1 + }, + table: tableName, + timestamp: new Date().toISOString() + }); } else { const result = await Database.query(`SELECT * FROM ${tableName} ORDER BY 1 LIMIT $1 OFFSET $2`, [limit, offset]); @@ -198,6 +231,54 @@ 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; + + const searchParams = new URLSearchParams({ + key: 'ba557f84-0bf6-4dbf-844f-df2767555e3e' + }); + + 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 result = await ( + await fetch(`${url}&` + searchParams, { + method: 'GET' + }) + ).json(); + + result.result = result.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, + delete: r.delete + } + }); + result.totalPages = Math.ceil(result.totalResultCount / result.size); + + res.json(result); + } catch (error) { + res.status(500).json({ + error: 'Internal Server Error', + message: error.message + }); + } +}); + app.post('/api/v1/idnot/user/:code', async (req, res) => { const code = req.params.code;