Browse Source

Add supplement and amount type verification

pull/1/head
asyncnomi 3 years ago
parent
commit
401d793da4
  1. 18
      index.js

18
index.js

@ -19,6 +19,7 @@ let AdminUsersUid = ["asyncnomi", "johan", "enthalpine", "fas", "arina", "billy"
let UsersToken = {}; let UsersToken = {};
let TokenDurationSecond = 3600; let TokenDurationSecond = 3600;
let MaxAmountCrepe = 10; let MaxAmountCrepe = 10;
let Supplements = ["nature", "sucre", "nutella", "confiture"];
var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json")); var ldapConf = JSON.parse(fs.readFileSync("ldap-conf.json"));
var LDAP = new LdapAuth({ var LDAP = new LdapAuth({
@ -115,13 +116,26 @@ fastify.post('/addPrank', async (request, reply) => {
if ("where" in content if ("where" in content
&& "amount" in content && "amount" in content
&& "supplement" 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); let prankUid = makeid(16);
PrankData[prankUid] = { PrankData[prankUid] = {
creator: content.uid, creator: content.uid,
type: content.type, type: content.type,
where: content.where, where: content.where,
amount: content.amount, amount: amount,
supplement: content.supplement, supplement: content.supplement,
note: content.note, note: content.note,
state: "Pending", state: "Pending",

Loading…
Cancel
Save