Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
fix coupons
Browse files Browse the repository at this point in the history
  • Loading branch information
tovade committed May 2, 2022
1 parent 03e5f37 commit cecb7f4
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions handlers/api/create_coupon.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-mixed-operators */
module.exports.load = async function (app, ifValidAPI, ejs) {
app.post("/api/coupons/create_coupon", async (req, res) => {
app.post('/api/coupons/create_coupon', async (req, res) => {
if (
(req.session.data && req.session.data.panelinfo.root_admin) ||
ifValidAPI(req, res, "create coupon")
ifValidAPI(req, res, 'create coupon')
) {
if (typeof req.body !== "object")
if (typeof req.body !== 'object')
return res.json({
error: process.api_messages.core.bodymustbeanobject,
});
Expand All @@ -15,7 +15,7 @@ module.exports.load = async function (app, ifValidAPI, ejs) {
});

let coupon = req.body.coupon;
if (typeof coupon !== "string")
if (typeof coupon !== 'string')
coupon =
Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15);
Expand All @@ -29,11 +29,6 @@ module.exports.load = async function (app, ifValidAPI, ejs) {
const disk = req.body.disk;
const cpu = req.body.cpu;
const servers = req.body.servers;
const uses = req.body.uses;

if (!uses || typeof uses !== "number") {
return res.json({ error: process.api_messages.coupons.invaliduses });
}

const couponinfo = {
code: coupon,
Expand All @@ -46,42 +41,42 @@ module.exports.load = async function (app, ifValidAPI, ejs) {
};

if (
typeof coins === "number" ||
typeof memory === "number" ||
typeof disk === "number" ||
typeof cpu === "number" ||
typeof servers === "number"
typeof coins === 'number' ||
typeof memory === 'number' ||
typeof disk === 'number' ||
typeof cpu === 'number' ||
typeof servers === 'number'
) {
// ok I got lazy. please don't make fun of this sh*t code. - Two
if (typeof coins === "number")
if (typeof coins === 'number')
couponinfo.coins =
Math.round(coins) < 1
? null
: Math.round(coins) > 1073741823
? 1073741823
: Math.round(coins);
if (typeof memory === "number")
if (typeof memory === 'number')
couponinfo.memory =
Math.round(memory) < 1
? null
: Math.round(memory) > 1073741823
? 1073741823
: Math.round(memory);
if (typeof disk === "number")
if (typeof disk === 'number')
couponinfo.disk =
Math.round(disk) < 1
? null
: Math.round(disk) > 1073741823
? 1073741823
: Math.round(disk);
if (typeof cpu === "number")
if (typeof cpu === 'number')
couponinfo.cpu =
Math.round(cpu) < 1
? null
: Math.round(cpu) > 1073741823
? 1073741823
: Math.round(cpu);
if (typeof servers === "number")
if (typeof servers === 'number')
couponinfo.servers =
Math.round(servers) < 1
? null
Expand All @@ -94,8 +89,7 @@ module.exports.load = async function (app, ifValidAPI, ejs) {
couponinfo.memory == null &&
couponinfo.disk == null &&
couponinfo.cpu == null &&
couponinfo.servers == null &&
couponinfo.uses
couponinfo.servers == null
)
return res.json({
error: process.api_messages.coupons.nopropervalueshavebeenprovided,
Expand All @@ -107,8 +101,7 @@ module.exports.load = async function (app, ifValidAPI, ejs) {
couponinfo.memory,
couponinfo.disk,
couponinfo.cpu,
couponinfo.servers,
couponinfo.uses
couponinfo.servers
);

return res.json({
Expand Down

0 comments on commit cecb7f4

Please sign in to comment.