/var/www/qr4y.com/server/delivery/api/controllers
NameSizeModeActions
account/-0755rm
auth/-0755rm
country_code/-0755rm
delivery_server/-0755rm
iap/-0755rm
order/-0755rm
qr/-0755rm
system/-0755rm
branch.controller.js298690644editdlrm
branchApp.controller.js46860644editdlrm
branchReview.controller.js63210644editdlrm
company.controller.js251110644editdlrm
companyReview.controller.js63680644editdlrm
companyTypes.controller.js31340644editdlrm
delivery.controller.js28270644editdlrm
deliveryTypes.controller.js23820644editdlrm
driver.controller.js45800644editdlrm
gallery.controller.js79290644editdlrm
language.controller.js27090644editdlrm
orderCancelCause.controller.js34420644editdlrm
payTypes.controller.js23140644editdlrm
permission.controller.js25900644editdlrm
plan.controller.js36180644editdlrm
planConfig.controller.js34530644editdlrm
product.controller.js134020644editdlrm
productFilters.controller.js33010644editdlrm
productGroups.controller.js65380644editdlrm
productReview.controller.js61640644editdlrm
productTypeFilters.controller.js29640644editdlrm
productTypeFiltersValues.controller.js31490644editdlrm
productTypes.controller.js26900644editdlrm
role.controller.js39820644editdlrm
room.controller.js34430644editdlrm
table.controller.js154540644editdlrm
user.controller.js255020644editdlrm
userCart.controller.js58270644editdlrm
waiter.controller.js61670644editdlrm
Edit: /var/www/qr4y.com/server/delivery/api/controllers/plan.controller.js (3618B)
const logger = require('../../logger')({ service: 'PlanController' }) const checkPermission = require('../utils/checkPermission.util') const { isSet, isEmpty, minLength, isPhone, isEmail } = require('../utils/validator.util') const { NotFound, BadRequest } = require('../responseModels/errors') module.exports = function ({ db }) { this.List = async (req, res, next) => { logger.child({ path: req.path, request: req.query }).info() let t1 = performance.now() try { const { limit, page } = req.query let where = {} let offset = page > 0 ? (page - 1) * (limit || 10) : 0 const plans = await db.plan.findAll({ include: db.planConfig, where, offset, limit: parseInt(limit) || 10 }) if (plans.length == 0 || !plans) { throw new NotFound({ lang: req.user?.languageCode }) } const time = performance.now() - t1 return res.status(200).json({ list: plans, count: plans.length, time, page }) } catch (err) { next(err) } } this.Details = async (req, res, next) => { logger.child({ path: req.path, request: req.params }).info() try { const { id } = req.params if (!isSet(id) || isEmpty(id)) { throw new BadRequest({ lang: req.user?.languageCode }) } const plan = await db.plan.findOne({ include: db.planConfig, where: { id } }) if (!plan) { throw new NotFound({ lang: req.user?.languageCode }) } return res.status(200).json(plan) } catch (err) { next(err) } } this.Create = async (req, res, next) => { logger.child({ path: req.path, request: req.body }).info() try { const { active, name, key, description, image, cost, costYear } = req.body if (!isSet(active) || isEmpty(active)) { throw new BadRequest({ lang: req.user?.languageCode }) } if (!isSet(name) || isEmpty(name)) { throw new BadRequest({ lang: req.user?.languageCode }) } if (!isSet(key) || isEmpty(key)) { throw new BadRequest({ lang: req.user?.languageCode }) } if (!isSet(cost) || isEmpty(cost)) { throw new BadRequest({ lang: req.user?.languageCode }) } if (!isSet(costYear) || isEmpty(costYear)) { throw new BadRequest({ lang: req.user?.languageCode }) } const plan = await db.plan.create({ active, name, description, image, key, cost, costYear, }) return res.status(200).json({ status: 'success', id: plan.id }) } catch (err) { next(err) } } this.Edit = async (req, res, next) => { logger.child({ path: req.path, request: req.body }).info() try { const { id, active, name, key, description, image, cost, costYear } = req.body const plan = await db.plan.findOne({ where: { id } }) if (!plan) { throw new NotFound({ lang: req.user?.languageCode }) } plan.active = active ? active : plan.active plan.name = name ? name : plan.name plan.key = key ? key : plan.key plan.description = description ? description : plan.description plan.image = image ? image : plan.image plan.cost = cost ? cost : plan.cost plan.costYear = costYear ? costYear : plan.costYear await plan.save() return res.status(200).json(plan) } catch (err) { next(err) } } this.Delete = async (req, res, next) => { logger.child({ path: req.path, request: req.body }).info() try { const { id } = req.body const plan = await db.plan.findOne({ where: { id } }) if (!plan) { throw new NotFound({ lang: req.user?.languageCode }) } await db.plan.destroy({ where: { id } }) return res.status(200).json({ status: 'success', id }) } catch (err) { next(err) } } }