insatller fee
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
const { body, validationResult } = require('express-validator')
|
||||
const Fee = require('../models/GPS.Fee')
|
||||
const titleKey = 'install_fee'
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
|
||||
module.exports.setFee = [
|
||||
[body('amount').notEmpty().isInt().withMessage('مقدار هزینه را وارد کنید')],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const { amount } = req.body
|
||||
const fee = await Fee.findOne({ title: titleKey })
|
||||
if (fee) {
|
||||
fee.amount = amount
|
||||
await fee.save()
|
||||
return res.status(200).json(fee)
|
||||
}
|
||||
const newFee = await Fee.create({ title: titleKey, amount })
|
||||
res.status(201).json(newFee)
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.getFee = async (req, res) => {
|
||||
const fee = await Fee.findOne({ title: titleKey })
|
||||
res.status(200).json(fee)
|
||||
}
|
||||
Reference in New Issue
Block a user