Altered API, read more

I moved /auth/account/privilege to /admin/privilege

I also fixed PATCH and DELETE on /account
This commit is contained in:
2021-03-14 04:34:46 +11:00
parent 61ddd5b38f
commit b2bf1aaf92
8 changed files with 40 additions and 28 deletions
+52
View File
@@ -0,0 +1,52 @@
//libraries
const utils = require('util');
const bcrypt = require('bcryptjs');
var cron = require('node-cron');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const { accounts } = require('../database/models');
//auth/deletion
const route = async (req, res) => {
const account = await accounts.findOne({
where: {
id: req.user.id
}
});
//compare the user's password
const compare = utils.promisify(bcrypt.compare);
const match = await compare(req.body.password || '', account.hash);
if (!match) {
return res.status(401).send('incorrect password');
}
//set the deletion time (2 days from now)
const interval = new Date(new Date().setDate(new Date().getDate() + 2)); //wow
await accounts.update({
deletion: interval
},
{
where: {
id: req.user.id
}
});
//finally
return res.status(200).end();
};
//actually delete the accounts
cron.schedule('0 * * * *', async () => {
await accounts.destroy({
where: {
deletion: {
[Op.lt]: Sequelize.fn('NOW')
}
}
});
});
module.exports = route;