Add supplement and amount type verification
This commit is contained in:
parent
5e873f2e63
commit
401d793da4
1 changed files with 16 additions and 2 deletions
18
index.js
18
index.js
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue