Refactor backend to import/export syntax and update deps

This commit is contained in:
Ben Grant 2022-08-20 21:35:38 +10:00
parent 1463773480
commit 7d0f3898de
20 changed files with 3168 additions and 685 deletions

View file

@ -1,37 +1,40 @@
const bcrypt = require('bcrypt');
import bcrypt from 'bcrypt'
module.exports = async (req, res) => {
const { eventId, personName } = req.params;
const { person } = req.body;
const updatePerson = async (req, res) => {
const { eventId, personName } = req.params
const { person } = req.body
try {
const query = req.datastore.createQuery(req.types.person)
.filter('eventId', eventId)
.filter('name', personName);
let personResult = (await req.datastore.runQuery(query))[0][0];
try {
const query = req.datastore.createQuery(req.types.person)
.filter('eventId', eventId)
.filter('name', personName)
const personResult = (await req.datastore.runQuery(query))[0][0]
if (personResult) {
if (person && person.availability) {
if (personResult.password) {
const passwordsMatch = person.password && await bcrypt.compare(person.password, personResult.password);
if (!passwordsMatch) {
return res.status(401).send('Incorrect password');
}
}
if (personResult) {
if (person && person.availability) {
if (personResult.password) {
const passwordsMatch = person.password && await bcrypt.compare(person.password, personResult.password)
if (!passwordsMatch) {
return res.status(401).send('Incorrect password')
}
}
personResult.availability = person.availability;
await req.datastore.upsert({
...personResult,
availability: person.availability,
})
await req.datastore.upsert(personResult);
res.sendStatus(200)
} else {
res.sendStatus(400)
}
} else {
res.sendStatus(404)
}
} catch (e) {
console.error(e)
res.sendStatus(400)
}
}
res.sendStatus(200);
} else {
res.sendStatus(400);
}
} else {
res.sendStatus(404);
}
} catch (e) {
console.error(e);
res.sendStatus(400);
}
};
export default updatePerson