Backend
This commit is contained in:
parent
15d4e2f126
commit
edcd4dcaa0
15 changed files with 1195 additions and 82 deletions
|
|
@ -1,18 +1,37 @@
|
|||
module.exports = (req, res) => {
|
||||
const { eventId, personId } = req.params;
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
const { eventId, personName } = req.params;
|
||||
const { person } = req.body;
|
||||
|
||||
if (eventId) {
|
||||
if (personId) {
|
||||
if (person) {
|
||||
res.send(person);
|
||||
try {
|
||||
const query = req.datastore.createQuery('Person')
|
||||
.filter('eventId', eventId)
|
||||
.filter('name', personName);
|
||||
let 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');
|
||||
}
|
||||
}
|
||||
|
||||
personResult.availability = person.availability;
|
||||
|
||||
await req.datastore.upsert(personResult);
|
||||
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
res.sendStatus(400);
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(404);
|
||||
}
|
||||
} else {
|
||||
res.sendStatus(404);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
res.sendStatus(400);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue