Added liking and security measures

This commit is contained in:
Sven laptop
2026-07-31 15:11:57 +02:00
parent 494b583cbc
commit ab73eecfec
25 changed files with 1095 additions and 91 deletions
+18
View File
@@ -62,6 +62,17 @@ async function create_people(req, res) {
const person = req.person;
let db_id;
const existing = await pool
.query('SELECT 1 FROM people WHERE username = $1 OR email = $2 LIMIT 1', [
person.username,
person.email,
])
.catch(() => null);
if (existing && existing.rowCount > 0) {
res.status(409).send('Username or email is already in use');
return;
}
try {
db_id = await insert_db(
person.name,
@@ -71,6 +82,10 @@ async function create_people(req, res) {
);
}
catch (err) {
if (err.code === '23505') {
res.status(409).send('Username or email is already in use');
return;
}
res.status(500).send('Data was not pushed to database, request failed');
return;
}
@@ -80,6 +95,9 @@ async function create_people(req, res) {
res.status(201).json({ id: db_id });
}
catch (err) {
// Compensate the SQL insert so the user does not exist in one database
// but not the other.
await pool.query('DELETE FROM people WHERE id = $1', [db_id]).catch(() => {});
res.status(500).send('Data was not pushed to graph database, request failed');
}
};