From 8a8b21ba8540fe2c2a0350f8940b4e70ce00fafa Mon Sep 17 00:00:00 2001 From: Ninjdai Date: Tue, 12 Dec 2023 13:55:35 +0100 Subject: [PATCH] Add contact list and deletion --- src/html/pages/api/contacts/delete.js | 2 +- src/html/pages/dashboard/contacts/list.js | 41 +++++++++++++++++++++++ www/dashboard/contacts/create.html | 2 +- www/dashboard/contacts/list.html | 31 +++++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/html/pages/dashboard/contacts/list.js create mode 100644 www/dashboard/contacts/list.html diff --git a/src/html/pages/api/contacts/delete.js b/src/html/pages/api/contacts/delete.js index bc37cc2..620ee7b 100644 --- a/src/html/pages/api/contacts/delete.js +++ b/src/html/pages/api/contacts/delete.js @@ -8,7 +8,7 @@ export default { async execute(request, response) { const { phone } = request.params; const contact = await global.database.contacts.findOne({ - where: { phone: phone }, + where: { phone: phone.replaceAll("%20", " ") }, }); if (!contact) return response.status(404).send({ message: "Contact does not exist" }); diff --git a/src/html/pages/dashboard/contacts/list.js b/src/html/pages/dashboard/contacts/list.js new file mode 100644 index 0000000..b8276a3 --- /dev/null +++ b/src/html/pages/dashboard/contacts/list.js @@ -0,0 +1,41 @@ +import { navbar } from '../../../../../utils/navbar.js'; +import { readFile } from 'fs/promises'; +import { permissionBits, checkPermissions } from '../../../../../utils/permissions.js'; + +export default { + path: "/dashboard/contacts/list", + requiresLogin: true, + permissions: permissionBits.ADMIN, + type: "get", + async execute(request, response) { + const contactList = await global.database.contacts.findAll(); + const contactTable = genContactTable(contactList); + const html = await readFile(`${process.env.WWW}/dashboard/contacts/list.html`); + return await response.send(html.toString() + .replace('', navbar(request.session)) + .replace('', contactTable) + ); + }, +} + +function genContactTable(contacts) { + let res = ` + + + + + + + `; + for(const contact of contacts) { + res += ` + + + + + + `; + } + res += `
TéléphonePrénomNomAction
${contact.phone}${contact.firstName}${contact.firstName}
`; + return res +} diff --git a/www/dashboard/contacts/create.html b/www/dashboard/contacts/create.html index 472ccdd..b4eadd7 100644 --- a/www/dashboard/contacts/create.html +++ b/www/dashboard/contacts/create.html @@ -30,7 +30,7 @@ body { } /* Full-width input fields */ -input[type=text], input[type=password] { +input[type=text], input[type=password], input[type=tel] { width: 100%; padding: 15px; margin: 5px 0 22px 0; diff --git a/www/dashboard/contacts/list.html b/www/dashboard/contacts/list.html new file mode 100644 index 0000000..c6358bc --- /dev/null +++ b/www/dashboard/contacts/list.html @@ -0,0 +1,31 @@ + + + + Utilisateurs + + + + + + + + +

Retour

+ +