From 34fbdad4bc0757db237ac886bb57269da6ef1588 Mon Sep 17 00:00:00 2001 From: Swift Date: Mon, 26 Feb 2024 18:01:31 +0330 Subject: [PATCH] fix --- server/controllers/complaintController.js | 11 ++++++++++- server/controllers/surveyController.js | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/controllers/complaintController.js b/server/controllers/complaintController.js index 00b5034..ce4fd28 100644 --- a/server/controllers/complaintController.js +++ b/server/controllers/complaintController.js @@ -2,6 +2,8 @@ const { body, validationResult } = require('express-validator') const Complaint = require('../models/Complaint') +const Transaction = require('../models/Transaction') + const { _sr } = require('../plugins/serverResponses') const { checkValidations } = require('../plugins/controllersHelperFunctions') const _faSr = _sr.fa @@ -13,7 +15,14 @@ module.exports.create = [ body('national').notEmpty().withMessage(_faSr.required.national_code), body('phoneNumber').notEmpty().isMobilePhone('ir-IR').withMessage(_faSr.required.phone_number), body('email').notEmpty().isEmail().withMessage(_faSr.required.email), - body('receptionCode').notEmpty().withMessage(_faSr.required.field), + body('receptionCode').notEmpty().withMessage(_faSr.required.field).custom(async(value, { req }) => { + const check = await Transaction.findOne({ItemReceptionTransDate:value}) + if(!check){ + return Promise.reject(new Error("کد پذیرش معتبر نیست")) + }else{ + return Promise.resolve() + } + }), body('caption').notEmpty().withMessage(_faSr.required.caption), body('callType').notEmpty().isBoolean().withMessage(_faSr.required.field), body('brand').notEmpty().isBoolean().withMessage(_faSr.required.field), diff --git a/server/controllers/surveyController.js b/server/controllers/surveyController.js index 988934f..efd7846 100644 --- a/server/controllers/surveyController.js +++ b/server/controllers/surveyController.js @@ -4,6 +4,7 @@ const { res404, res500 } = require('../plugins/controllersHelperFunctions') const _faSr = _sr.fa const { checkValidations } = require('../plugins/controllersHelperFunctions') const Survey = require('../models/Survey') +const Transaction = require('../models/Transaction') module.exports.create = [ (req, res) => { @@ -47,6 +48,18 @@ module.exports.createPublic = [ body('national').notEmpty().withMessage(_faSr.required.national_code), body('phoneNumber').notEmpty().isMobilePhone('ir-IR').withMessage(_faSr.required.phone_number), body('email').notEmpty().isEmail().withMessage(_faSr.required.email), + body('code').custom(async(value, { req }) => { + if(value){ + const check = await Transaction.findOne({ItemReceptionTransDate:value}) + if(!check){ + return Promise.reject(new Error("کد پذیرش معتبر نیست")) + }else{ + return Promise.resolve() + } + }else{ + return Promise.resolve() + } + }), ], checkValidations(validationResult), (req, res) => {