insatller fee

This commit is contained in:
morteza-mortezai
2025-11-26 09:37:16 +03:30
parent 1a98067f1a
commit 7b501107cf
11 changed files with 224 additions and 63 deletions
+25
View File
@@ -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)
}