Fix bug and update
This commit is contained in:
@@ -159,7 +159,8 @@ module.exports.updateUserOnArpa = (userData, arpa_businessID, db) => {
|
||||
Address: userData.address,
|
||||
PostalCode: userData.postal_code,
|
||||
BusinessCategoryId: BusinessCategoryId(db),
|
||||
BusinessID: arpa_businessID
|
||||
BusinessID: arpa_businessID,
|
||||
CheckExistNationalCode: true
|
||||
}
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
const EnvirementVariables = {
|
||||
// node envirements
|
||||
isDev: process.env.NODE_ENV === 'devServer',
|
||||
isDev: process.env.NODE_ENV === 'development',
|
||||
isProduction: process.env.NODE_ENV === 'production',
|
||||
|
||||
// server ports
|
||||
|
||||
@@ -33,13 +33,12 @@ module.exports.create = [
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const { title, caption, expireDate, isForAgents } = req.body
|
||||
const { title, caption, expireDate, isForAgents, publicx } = req.body
|
||||
const { user_id } = req
|
||||
const data = { title, caption, expireDate, isForAgents, _creator: user_id }
|
||||
|
||||
const data = { title, caption, expireDate, isForAgents, public: publicx, _creator: user_id }
|
||||
if (req.files?.image) {
|
||||
const image = req.files.image
|
||||
const fileName = 'TicketAttachment_' + Date.now() + '.' + image.mimetype.split('/')[1]
|
||||
const fileName = 'announcement' + Date.now() + '.' + image.name
|
||||
const acceptableFormats = ['png', 'jpg', 'jpeg', 'webp']
|
||||
if (!acceptableFormats.includes(image.mimetype.split('/')[1]))
|
||||
return res.status(422).json({ validation: { image: { msg: _faSr.format.image } } })
|
||||
@@ -97,6 +96,19 @@ module.exports.getNotifsForUsers = [
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.getNotifsForSite = [
|
||||
async (req, res) => {
|
||||
try {
|
||||
|
||||
const announcements = await Announcement.find({ public:true })
|
||||
|
||||
return res.json(announcements)
|
||||
} catch (e) {
|
||||
return res500(res, e)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.deleteAnnouncement = [
|
||||
(req, res) => {
|
||||
Announcement.findByIdAndRemove(req.params.id, (err, oldData) => {
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports.getRouteManager = [
|
||||
else return res.json(arpaRes.data)
|
||||
})
|
||||
.catch(err => {
|
||||
// console.log('🚀 ~ file: arpaConnectionController.js ~ getRouteManager ~ err', err)
|
||||
console.log('🚀 ~ file: arpaConnectionController.js ~ getRouteManager ~ err', err, "-------",url,db)
|
||||
return res.status(500).json({ message: 'WebService Error' })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ module.exports.create = [
|
||||
|
||||
module.exports.getAll = [
|
||||
(req, res) => {
|
||||
ContactPageMessage.find({})
|
||||
ContactPageMessage.find({}).sort({created_at:1})
|
||||
.select('-message')
|
||||
.then(messages => {
|
||||
return res.json(messages)
|
||||
|
||||
@@ -149,6 +149,7 @@ module.exports.get_all_tickets_for_admin = [
|
||||
(req, res) => {
|
||||
TicketConversation.find()
|
||||
.sort({created_at: -1})
|
||||
.limit(400)
|
||||
.populate('user_id', userIdPopulation)
|
||||
.exec((err, data) => {
|
||||
if (err) return res500(res, err)
|
||||
|
||||
@@ -1047,6 +1047,198 @@ module.exports.change_panatech_info_by_admin = [
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.update_user_by_admin = [
|
||||
[
|
||||
body('first_name')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.first_name)
|
||||
.bail()
|
||||
.isLength({ min: 2 })
|
||||
.withMessage(_faSr.min_char.min2)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
if (removeWhiteSpaces(value).length < 2) return Promise.reject(_faSr.min_char.min2)
|
||||
if (!isPersian(value)) return Promise.reject(new Error('لطفا با حروف فارسی تایپ کنید'))
|
||||
else return true
|
||||
}),
|
||||
|
||||
body('last_name')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.first_name)
|
||||
.bail()
|
||||
.isLength({ min: 2 })
|
||||
.withMessage(_faSr.min_char.min2)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
if (removeWhiteSpaces(value).length < 2) return Promise.reject(_faSr.min_char.min2)
|
||||
if (!isPersian(value)) return Promise.reject(new Error('لطفا با حروف فارسی تایپ کنید'))
|
||||
else return true
|
||||
}),
|
||||
|
||||
body('national_code')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.national_code)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
if (checkNationalCode(value)) return true
|
||||
else return Promise.reject(_faSr.format.national_code)
|
||||
})
|
||||
.custom((value, { req }) => {
|
||||
const nationalCode = value.trim()
|
||||
return User.findOne({ national_code: nationalCode }).then(user => {
|
||||
if (user && user.national_code === nationalCode && user._id.toString() !== req.body._id)
|
||||
return Promise.reject(new Error('کاربر با این کد ملی از قبل وجود دارد'))
|
||||
else return true
|
||||
})
|
||||
}),
|
||||
|
||||
body('province_id').notEmpty().withMessage(_faSr.required.province),
|
||||
|
||||
body('city_id').notEmpty().withMessage(_faSr.required.city),
|
||||
|
||||
body('address')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.address)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
if (!isPersianWithDigits(value)) return Promise.reject(new Error('لطفا با حروف فارسی تایپ کنید'))
|
||||
else return true
|
||||
}),
|
||||
|
||||
body('postal_code')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.postal_code)
|
||||
.bail()
|
||||
.isNumeric()
|
||||
.withMessage(_faSr.format.number),
|
||||
|
||||
body('tel_number')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.phone_number)
|
||||
.bail()
|
||||
.isNumeric()
|
||||
.withMessage(_faSr.format.phone_number),
|
||||
|
||||
body('mobile_number')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.phone_number)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const mobileNStatus = checkMobileNumber(value)
|
||||
if (!mobileNStatus) return Promise.reject(_faSr.format.phone_number)
|
||||
else return Promise.resolve()
|
||||
})
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const mobileNumber = value.trim()
|
||||
return User.findOne({ mobile_number: mobileNumber }).then(user => {
|
||||
if (user && user.mobile_number === mobileNumber && user._id.toString() !== req.body._id)
|
||||
return Promise.reject(new Error('کاربر با این شماره موبایل از قبل وجود دارد'))
|
||||
else return true
|
||||
})
|
||||
}),
|
||||
|
||||
body('email')
|
||||
.notEmpty()
|
||||
.withMessage(_faSr.required.email)
|
||||
.bail()
|
||||
.isEmail()
|
||||
.withMessage(_faSr.format.email)
|
||||
.bail()
|
||||
.custom((value, { req }) => {
|
||||
const email = value.trim().toLowerCase()
|
||||
return User.findOne({ email }).then(user => {
|
||||
if (user && user.email === email && user._id.toString() !== req.body._id)
|
||||
return Promise.reject(_faSr.duplicated.email)
|
||||
else return true
|
||||
})
|
||||
})
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const {
|
||||
first_name,
|
||||
last_name,
|
||||
national_code,
|
||||
province_id,
|
||||
province_name,
|
||||
city_id,
|
||||
city_name,
|
||||
address,
|
||||
postal_code,
|
||||
tel_number,
|
||||
mobile_number,
|
||||
email,
|
||||
store_name
|
||||
} = req.body
|
||||
|
||||
const MongoData = {
|
||||
last_name,
|
||||
province_id,
|
||||
province_name,
|
||||
city_id,
|
||||
city_name,
|
||||
address,
|
||||
postal_code,
|
||||
tel_number,
|
||||
store_name
|
||||
}
|
||||
MongoData.first_name = nameOptimizer(first_name)
|
||||
MongoData.national_code = national_code.trim()
|
||||
MongoData.mobile_number = normalizeMobileNumber(mobile_number)
|
||||
MongoData.email = email.trim().toLowerCase()
|
||||
|
||||
try {
|
||||
const user_id = req.params.id
|
||||
const user = await User.findById(user_id)
|
||||
if (!user) {
|
||||
return res404(res, _faSr.not_found.user_id)
|
||||
}
|
||||
|
||||
|
||||
// check if need to ferify email or mobile
|
||||
const newEmail = user.email !== MongoData.email
|
||||
const newMobile = user.mobile_number !== MongoData.mobile_number
|
||||
if (newEmail) user.email_confirmed = false
|
||||
if (newMobile) user.mobile_confirmed = false
|
||||
|
||||
// save new info to arpa
|
||||
await updateUserOnArpa(MongoData, user.verity_businessID, 'verity')
|
||||
await updateUserOnArpa(MongoData, user.panatech_businessID, 'panatech')
|
||||
|
||||
// save new info to user
|
||||
user.first_name = MongoData.first_name
|
||||
user.last_name = MongoData.last_name
|
||||
user.national_code = MongoData.national_code
|
||||
user.province_id = MongoData.province_id
|
||||
user.province_name = MongoData.province_name
|
||||
user.city_id = MongoData.city_id
|
||||
user.city_name = MongoData.city_name
|
||||
user.address = MongoData.address
|
||||
user.postal_code = MongoData.postal_code
|
||||
user.tel_number = MongoData.tel_number
|
||||
user.store_name = MongoData.store_name
|
||||
user.mobile_number = MongoData.mobile_number
|
||||
user.email = MongoData.email
|
||||
|
||||
|
||||
|
||||
await user.save()
|
||||
|
||||
// send confirmation key after user saved
|
||||
if (newEmail) await sendConfirmationEmail(user_id)
|
||||
if (newMobile) await sendConfirmationSMS(user_id)
|
||||
|
||||
return res.json({ message: _faSr.response.success_save })
|
||||
} catch (e) {
|
||||
console.log('Arpa Error during update user --', e)
|
||||
return res500(res, _faSr.response.problem)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
/// //////////////////////////////////////////////////////////////////// authentication
|
||||
|
||||
/// //////// Login
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ const inHostUrl = 'mongodb://asanserv_admin:admin1234@localhost:27017/asanserv_d
|
||||
const outHostUrl =
|
||||
'mongodb://asanserv_admin:admin1234@www.asan-service.com:27017/asanserv_database?serverSelectionTimeoutMS=5000&connectTimeoutMS=10000&authSource=asanserv_database'
|
||||
const locaUrl = 'mongodb://localhost:27017/AsanService'
|
||||
mongoose.connect(locaUrl, {
|
||||
mongoose.connect(outHostUrl, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useFindAndModify: false,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
function image(img) {
|
||||
if (img) return '/uploads/images/announcement/' + img
|
||||
}
|
||||
|
||||
const AnnouncementSchema = mongoose.Schema({
|
||||
title: String,
|
||||
@@ -11,7 +8,8 @@ const AnnouncementSchema = mongoose.Schema({
|
||||
expireDate: Number,
|
||||
expired: { type: Boolean, default: false },
|
||||
isForAgents: { type: Boolean, default: false },
|
||||
image: { type: String, get: image },
|
||||
image: { type: String},
|
||||
public:{ type: Boolean, default:false },
|
||||
_creator: { type: mongoose.ObjectId, ref: 'User' }
|
||||
})
|
||||
|
||||
|
||||
@@ -85,6 +85,8 @@ router.get('/user/:id', hasPermission('customers'), userController.get_one_user_
|
||||
router.put('/user/:id', hasPermission('customers'), userController.updateUserByAdmin)
|
||||
router.put('/user/changeVerityInfo/:id', hasPermission('customers'), userController.change_verity_info_by_admin)
|
||||
router.put('/user/changePanatechInfo/:id', hasPermission('customers'), userController.change_panatech_info_by_admin)
|
||||
router.put('/user/update/:id', hasPermission('customers'), userController.update_user_by_admin)
|
||||
|
||||
|
||||
/// ///////////// serials exel file
|
||||
router.post('/addExel', hasPermission('serials-exel'), serialsExelController.addExel)
|
||||
|
||||
@@ -14,6 +14,7 @@ const helpController = require('../controllers/helpController')
|
||||
const lotteryPopUpController = require('../controllers/lotteryPopUpController')
|
||||
const lotteryController = require('../controllers/lotteryController')
|
||||
const representationController = require('../controllers/representationController')
|
||||
const announcementController = require('../controllers/announcementController')
|
||||
|
||||
/// //////////////////////////////////////////////////////// routes
|
||||
/// ///////////// warranty terms
|
||||
@@ -57,4 +58,8 @@ router.get('/lotteryPopUp', lotteryPopUpController.getPopUpInfo)
|
||||
router.get('/lastLottery', lotteryController.getLastLottery)
|
||||
router.post('/enrollParticipant', lotteryController.enrollParticipant)
|
||||
|
||||
/// //////////// announcement
|
||||
router.get('/announcement', announcementController.getNotifsForSite)
|
||||
|
||||
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user