Add supplement and amount type verification

This commit is contained in:
asyncnomi 2022-12-15 10:50:07 +01:00
parent 5e873f2e63
commit 401d793da4

View file

@ -19,6 +19,7 @@ let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy"
let UsersToken = {};
let TokenDurationSecond = 3600;
let MaxAmountCrepe = 10;
let Supplements = ["nature", "sucre", "nutella", "confiture"];
var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json"));
var LDAP = new LdapAuth({
@ -115,13 +116,26 @@ fastify.post('/addPrank', async (request, reply) => {
if ("where" in content
&& "amount" in content
&& "supplement" in content) {
if (amound < MaxAmountCrepe) {
let amount = parseInt(content.amount)
if (isNaN(amount)) {
return {
success: false,
why: "Unable to parse the amount as integer"
}
}
if (!Supplements.contains(content.supplement)) {
return {
success: false,
why: "This supplement isn't available"
}
}
if (amount < MaxAmountCrepe) {
let prankUid = makeid(16);
PrankData[prankUid] = {
creator: content.uid,
type: content.type,
where: content.where,
amount: content.amount,
amount: amount,
supplement: content.supplement,
note: content.note,
state: "Pending",