update: change the type
This commit is contained in:
@@ -37,9 +37,18 @@ module.exports.add_representation = [
|
||||
.withMessage('نوع نمایندگی را مشخص کنید')
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const acceptedValues = ['verity', 'panatech', 'both']
|
||||
if (!acceptedValues.includes(value)) return Promise.reject(new Error('invalid value'))
|
||||
else return true
|
||||
const acceptedValues = [
|
||||
'mobile_accessories',
|
||||
'computer_accessories',
|
||||
'memory_products',
|
||||
'car_audio_video',
|
||||
'home_products'
|
||||
]
|
||||
if (!Array.isArray(value)) return Promise.reject(new Error('نوع نمایندگی باید به صورت آرایه باشد'))
|
||||
if (value.length === 0) return Promise.reject(new Error('حداقل یک نوع نمایندگی را انتخاب کنید'))
|
||||
const isValid = value.every(item => acceptedValues.includes(item))
|
||||
if (!isValid) return Promise.reject(new Error('مقدار نامعتبر برای نوع نمایندگی'))
|
||||
return true
|
||||
}),
|
||||
|
||||
body('full_name')
|
||||
@@ -325,9 +334,18 @@ module.exports.edit_representation_by_user = [
|
||||
.withMessage('نوع نمایندگی را مشخص کنید')
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const acceptedValues = ['verity', 'panatech', 'both']
|
||||
if (!acceptedValues.includes(value)) return Promise.reject(new Error('invalid value'))
|
||||
else return true
|
||||
const acceptedValues = [
|
||||
'mobile_accessories',
|
||||
'computer_accessories',
|
||||
'memory_products',
|
||||
'car_audio_video',
|
||||
'home_products'
|
||||
]
|
||||
if (!Array.isArray(value)) return Promise.reject(new Error('نوع نمایندگی باید به صورت آرایه باشد'))
|
||||
if (value.length === 0) return Promise.reject(new Error('حداقل یک نوع نمایندگی را انتخاب کنید'))
|
||||
const isValid = value.every(item => acceptedValues.includes(item))
|
||||
if (!isValid) return Promise.reject(new Error('مقدار نامعتبر برای نوع نمایندگی'))
|
||||
return true
|
||||
}),
|
||||
|
||||
body('full_name')
|
||||
@@ -867,9 +885,18 @@ module.exports.update_representation_by_admin = [
|
||||
.withMessage('نوع نمایندگی را مشخص کنید')
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const acceptedValues = ['verity', 'panatech', 'both']
|
||||
if (!acceptedValues.includes(value)) return Promise.reject(new Error('invalid value'))
|
||||
else return true
|
||||
const acceptedValues = [
|
||||
'mobile_accessories',
|
||||
'computer_accessories',
|
||||
'memory_products',
|
||||
'car_audio_video',
|
||||
'home_products'
|
||||
]
|
||||
if (!Array.isArray(value)) return Promise.reject(new Error('نوع نمایندگی باید به صورت آرایه باشد'))
|
||||
if (value.length === 0) return Promise.reject(new Error('حداقل یک نوع نمایندگی را انتخاب کنید'))
|
||||
const isValid = value.every(item => acceptedValues.includes(item))
|
||||
if (!isValid) return Promise.reject(new Error('مقدار نامعتبر برای نوع نمایندگی'))
|
||||
return true
|
||||
}),
|
||||
|
||||
body('full_name')
|
||||
@@ -1144,7 +1171,13 @@ module.exports.add_agent_by_admin = [
|
||||
|
||||
const data = {
|
||||
user_id,
|
||||
representation_type: 'both',
|
||||
representation_type: [
|
||||
'mobile_accessories',
|
||||
'computer_accessories',
|
||||
'memory_products',
|
||||
'car_audio_video',
|
||||
'home_products'
|
||||
],
|
||||
full_name: '', // todo
|
||||
birth_date: '',
|
||||
id_number: '',
|
||||
@@ -1199,9 +1232,9 @@ module.exports.add_agent_by_admin = [
|
||||
moment(Date.now()).format('jMMM').toUpperCase() +
|
||||
allRepresentations.length.toString().padStart(4, '0')
|
||||
|
||||
// generate agent code
|
||||
// generate agent code with new format
|
||||
const agentsCount = await Representation.find({ status: 'accepted' })
|
||||
data.agent_code = 'ASG' + agentsCount.length.toString().padStart(2, '0')
|
||||
data.agent_code = 'ASG' + moment(Date.now()).format('YY') + agentsCount.length.toString().padStart(3, '0')
|
||||
|
||||
data.representation_code = representation_code
|
||||
|
||||
|
||||
Reference in New Issue
Block a user