@@ -7,8 +7,6 @@ const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
const UserGPS = require('../models/GPS.User')
|
||||
const { generateRandomDigits
|
||||
} = require('../plugins/controllersHelperFunctions')
|
||||
const Notification = require('../models/GPS.Notif')
|
||||
|
||||
module.exports.login_with_pass = [
|
||||
[
|
||||
body('username')
|
||||
@@ -57,10 +55,6 @@ module.exports.login_with_pass = [
|
||||
})
|
||||
user.token = token
|
||||
await user.save()
|
||||
await Notification.create({
|
||||
userID:user._id,
|
||||
content:"test"
|
||||
})
|
||||
return res.status(200).json({ token })
|
||||
} catch (err) {
|
||||
return res.status(422).json({
|
||||
@@ -96,10 +90,6 @@ module.exports.login_with_otp = [
|
||||
})
|
||||
user.otp = generateRandomDigits(6)
|
||||
user.save()
|
||||
await Notification.create({
|
||||
userID:user._id,
|
||||
content:"test"
|
||||
})
|
||||
return res.status(200).json({ token })
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable no-lonely-if */
|
||||
const { body, param, validationResult } = require('express-validator')
|
||||
const { _sr } = require('../plugins/serverResponses')
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
@@ -15,29 +14,23 @@ module.exports.addCard = [
|
||||
try {
|
||||
const { holderName, PAN, IBAN } = req.body;
|
||||
const userData = await User.findById(req.user_id).select('id cardBank')
|
||||
if(userData?.cardBank && Array.isArray(userData?.cardBank) && userData?.cardBank.length >= 5){
|
||||
res.status(400).json({ msg: 'شما به حداکثر میزان مجاز رسیدید' })
|
||||
}else{
|
||||
if (userData?.cardBank && Array.isArray(userData?.cardBank)) {
|
||||
userData.cardBank.push({
|
||||
holderName,
|
||||
PAN,
|
||||
IBAN
|
||||
})
|
||||
userData.save()
|
||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||
} else {
|
||||
userData.cardBank = [{
|
||||
holderName,
|
||||
PAN,
|
||||
IBAN
|
||||
}];
|
||||
userData.save()
|
||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||
}
|
||||
if (userData?.cardBank && Array.isArray(userData?.cardBank)) {
|
||||
userData.cardBank.push({
|
||||
holderName,
|
||||
PAN,
|
||||
IBAN
|
||||
})
|
||||
userData.save()
|
||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||
} else {
|
||||
userData.cardBank = [{
|
||||
holderName,
|
||||
PAN,
|
||||
IBAN
|
||||
}];
|
||||
userData.save()
|
||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({ msg: error })
|
||||
|
||||
|
||||
@@ -44,71 +44,97 @@ module.exports.deviceRegistration = [
|
||||
module.exports.getAllForUser = async (req, res) => {
|
||||
let page;
|
||||
let rows;
|
||||
|
||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
rows = 10
|
||||
rows = 10;
|
||||
} else {
|
||||
rows = parseInt(req.query.rows)
|
||||
rows = parseInt(req.query.rows);
|
||||
}
|
||||
|
||||
if (!req.query?.page) {
|
||||
page = 0
|
||||
// eslint-disable-next-line eqeqeq
|
||||
} else if (req.query.page <= 1) {
|
||||
page = 0
|
||||
if (!req.query?.page || req.query.page <= 1) {
|
||||
page = 0;
|
||||
} else {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
page = (req.query.page - 1) * rows;
|
||||
}
|
||||
|
||||
const search = req.query?.search ? req.query.search : null
|
||||
let sort
|
||||
if(req.query?.sort){
|
||||
sort= req.query?.sort
|
||||
}else{
|
||||
sort= { created_at: -1 }
|
||||
const search = req.query?.search || null;
|
||||
|
||||
let sort = {};
|
||||
|
||||
if (req.query?.deviceId_dollarProfit) {
|
||||
sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit);
|
||||
}
|
||||
if (req.query?.status) {
|
||||
sort.status = parseInt(req.query.status);
|
||||
}
|
||||
if (req.query?.registerDate) {
|
||||
sort.registerDate = parseInt(req.query.registerDate);
|
||||
}
|
||||
|
||||
if (Object.keys(sort).length === 0) {
|
||||
sort = { 'created_at': -1 };
|
||||
}
|
||||
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
}
|
||||
if(search){
|
||||
filter.$or = [
|
||||
{ IMEI: { $regex: search } },
|
||||
]
|
||||
};
|
||||
|
||||
if (search) {
|
||||
filter.$or = [
|
||||
{ IMEI: { $regex: search, $options: 'i' } },
|
||||
];
|
||||
}
|
||||
|
||||
const data = await InstalledDevice.find(filter).skip(page).limit(rows).sort(sort).populate('deviceId')
|
||||
try {
|
||||
const data = await InstalledDevice.find(filter)
|
||||
.skip(page)
|
||||
.limit(rows)
|
||||
.sort(sort)
|
||||
.populate('deviceId');
|
||||
|
||||
const total = Math.ceil((await InstalledDevice.countDocuments(filter)))
|
||||
res.status(200).json({ data, total })
|
||||
const total = await InstalledDevice.countDocuments(filter);
|
||||
|
||||
}
|
||||
res.status(200).json({ data, total });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'An error occurred', error });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getAllForAdmin = async (req, res) => {
|
||||
// let page;
|
||||
// let rows;
|
||||
// if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
// rows = 10
|
||||
// } else {
|
||||
// rows = parseInt(req.query.rows)
|
||||
// }
|
||||
try {
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const rows = parseInt(req.query.rows) || 10;
|
||||
const search = req.query.search || "";
|
||||
const sortField = req.query.sortField || "status";
|
||||
const sortOrder = req.query.sortOrder === "desc" ? -1 : 1;
|
||||
|
||||
// if (!req.query?.page) {
|
||||
// page = 0
|
||||
// // eslint-disable-next-line eqeqeq
|
||||
// } else if (req.query.page <= 1) {
|
||||
// page = 0
|
||||
// } else {
|
||||
// page = req.query.page
|
||||
// page = page * rows - rows
|
||||
// }
|
||||
// const search = req.query?.search ? req.query.search : ""
|
||||
const skip = (page - 1) * rows;
|
||||
|
||||
const data = await InstalledDevice.find({}).sort({ status: 1 })
|
||||
.populate('deviceId')
|
||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
||||
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
const filter = {};
|
||||
if (search) {
|
||||
filter.$or = [
|
||||
{ IMEI: new RegExp(search, 'i') },
|
||||
{ 'userId.shopName': new RegExp(search, 'i') },
|
||||
{ 'userId.national_code': new RegExp(search, 'i') },
|
||||
];
|
||||
}
|
||||
|
||||
const data = await InstalledDevice.find(filter)
|
||||
.sort({ [sortField]: sortOrder })
|
||||
.populate('deviceId')
|
||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
||||
.skip(skip)
|
||||
.limit(rows);
|
||||
|
||||
const totalDocuments = await InstalledDevice.countDocuments(filter);
|
||||
const totalPages = Math.ceil(totalDocuments / rows);
|
||||
|
||||
res.status(200).json({ data, totalDocuments, totalPages });
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
res.status(500).json({ message: "Server Error", error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -127,10 +153,8 @@ module.exports.updateInstalled = [
|
||||
const device = await Device.findById(installedDevice.deviceId)
|
||||
switch (req.params.type) {
|
||||
case "accept": {
|
||||
|
||||
installedDevice.status = 1;
|
||||
installedDevice.installationDate = new Date();
|
||||
|
||||
device.status = 1;
|
||||
|
||||
user.walletBalance += device.profit
|
||||
@@ -167,7 +191,7 @@ module.exports.updateInstalled = [
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
res.status(404).json({ msg: "استاتوس اشتباه است" })
|
||||
res.status(404).json({ msg: "وضعیت اشتباه است" })
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,44 +9,52 @@ const User = require('../models/GPS.User')
|
||||
module.exports.getAll = async (req, res) => {
|
||||
let page;
|
||||
let rows;
|
||||
|
||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
rows = 10
|
||||
rows = 10;
|
||||
} else {
|
||||
rows = parseInt(req.query.rows)
|
||||
rows = parseInt(req.query.rows);
|
||||
}
|
||||
|
||||
if (!req.query?.page) {
|
||||
page = 0
|
||||
// eslint-disable-next-line eqeqeq
|
||||
page = 0;
|
||||
} else if (req.query.page <= 1) {
|
||||
page = 0
|
||||
page = 0;
|
||||
} else {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
page = req.query.page;
|
||||
page = page * rows - rows;
|
||||
}
|
||||
const search = req.query?.search ? req.query.search : null
|
||||
|
||||
let sort
|
||||
if(req.query?.sort){
|
||||
sort= req.query?.sort
|
||||
}else{
|
||||
sort= { created_at: -1 }
|
||||
const search = req.query?.search ? req.query.search : null;
|
||||
|
||||
let sort = {};
|
||||
|
||||
if (req.query?.created_at) {
|
||||
sort.created_at = parseInt(req.query.created_at);
|
||||
}
|
||||
|
||||
if (req.query?.score) {
|
||||
sort.score = parseInt(req.query.score);
|
||||
}
|
||||
|
||||
if (Object.keys(sort).length === 0) {
|
||||
sort = { created_at: -1 };
|
||||
}
|
||||
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
}
|
||||
};
|
||||
|
||||
if(search){
|
||||
filter.$or = [
|
||||
{ title: { $regex: search } },
|
||||
{ score: search },
|
||||
]
|
||||
if (search) {
|
||||
filter.$or = [
|
||||
{ title: new RegExp(search, 'i') },
|
||||
...(!isNaN(search) ? [{ score: Number(search) }] : []),
|
||||
];
|
||||
}
|
||||
|
||||
const score = await Score.find(filter).skip(page).limit(rows).sort(sort);
|
||||
const total = Math.ceil((await Score.countDocuments(filter)))
|
||||
const total = Math.ceil(await Score.countDocuments(filter));
|
||||
|
||||
const user = await User.findById(req.user_id).select('score')
|
||||
res.status(200).json({ data: score, score: user.score, total })
|
||||
}
|
||||
const user = await User.findById(req.user_id).select('score');
|
||||
res.status(200).json({ data: score, score: user.score, total });
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
const bcrypt = require('bcryptjs')
|
||||
const { body, validationResult, param } = require('express-validator')
|
||||
const uid = require('uuid')
|
||||
const User = require('../models/GPS.User')
|
||||
const { _sr } = require('../plugins/serverResponses')
|
||||
const { SMS } = require('../plugins/SMS_Module')
|
||||
@@ -130,6 +131,9 @@ module.exports.register_user = [
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
try {
|
||||
const provinceId = uid.v4()
|
||||
const cityId = uid.v4()
|
||||
|
||||
const {
|
||||
first_name,
|
||||
last_name,
|
||||
@@ -143,8 +147,8 @@ module.exports.register_user = [
|
||||
|
||||
const data = {
|
||||
last_name,
|
||||
province_name,
|
||||
city_name,
|
||||
province_name:{id:provinceId,provinceName:province_name},
|
||||
city_name:{id:cityId,cityName:city_name},
|
||||
shopName
|
||||
}
|
||||
data.first_name = nameOptimizer(first_name)
|
||||
@@ -250,7 +254,8 @@ module.exports.update_user = [
|
||||
req.params.id,
|
||||
data
|
||||
)
|
||||
return res.json({ message: _faSr.response.success_save })
|
||||
const user = await User.findById(req.params.id)
|
||||
return res.json({ message: _faSr.response.success_save ,user })
|
||||
} catch (err) {
|
||||
const registerFailurMsg = 'مشکلی در به روز رسانی پیش آمده، لطفا مجددا تلاش کنید'
|
||||
throw new Error(registerFailurMsg)
|
||||
@@ -383,7 +388,7 @@ module.exports.resetpass_otp = [
|
||||
module.exports.getCurrent = async (req, res) => {
|
||||
const user = await User.findById(req.user_id).select('-password -token -otp -seenByAdmin')
|
||||
if (!user || !user.active) return res.ststus(404).json({ msg: _sr.fa.not_found.user_id })
|
||||
else return res.status(200).json(user)
|
||||
else return res.status(200).json({user})
|
||||
}
|
||||
|
||||
module.exports.getUsersForAdmin = async (req, res) => {
|
||||
|
||||
@@ -49,71 +49,102 @@ module.exports.createRequest = [
|
||||
|
||||
|
||||
module.exports.getAllForUser = async (req, res) => {
|
||||
let page;
|
||||
let rows;
|
||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
rows = 10
|
||||
} else {
|
||||
rows = parseInt(req.query.rows)
|
||||
const rows = (!req.query?.rows || req.query?.rows <= 5) ? 10 : parseInt(req.query.rows);
|
||||
|
||||
let page = 0;
|
||||
if (req.query?.page && req.query.page > 1) {
|
||||
page = (req.query.page - 1) * rows;
|
||||
}
|
||||
|
||||
if (!req.query?.page) {
|
||||
page = 0
|
||||
// eslint-disable-next-line eqeqeq
|
||||
} else if (req.query.page <= 1) {
|
||||
page = 0
|
||||
} else {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
const search = req.query?.search || null;
|
||||
|
||||
let sort = {};
|
||||
|
||||
if (req.query?.created_at) {
|
||||
sort.created_at = parseInt(req.query.created_at);
|
||||
}
|
||||
const search = req.query?.search ? req.query.search : null
|
||||
let sort
|
||||
if(req.query?.sort){
|
||||
sort= req.query?.sort
|
||||
}else{
|
||||
sort= { created_at: -1 }
|
||||
|
||||
if (req.query?.updated_at) {
|
||||
sort.updated_at = parseInt(req.query.updated_at);
|
||||
}
|
||||
|
||||
if (req.query?.amount) {
|
||||
sort.amount = parseInt(req.query.amount);
|
||||
}
|
||||
|
||||
if (req.query?.status) {
|
||||
sort.status = parseInt(req.query.status);
|
||||
}
|
||||
|
||||
if (Object.keys(sort).length === 0) {
|
||||
sort = { created_at: 1 };
|
||||
}
|
||||
|
||||
const filter = {
|
||||
userId: req.user_id,
|
||||
}
|
||||
};
|
||||
|
||||
if(search){
|
||||
filter.$or = [
|
||||
if (search) {
|
||||
filter.$or = [
|
||||
{ amount: search },
|
||||
{ dollarAmount: search },
|
||||
{ trackingNumber: { $regex: search } },
|
||||
]
|
||||
{ trackingNumber: { $regex: search, $options: 'i' } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort);
|
||||
const total = await Withdraw.countDocuments(filter);
|
||||
|
||||
const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort);
|
||||
const total = Math.ceil((await Withdraw.countDocuments(filter)))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
res.status(200).json({ data, total });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'خطای سرور', error });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.getAllForAdmin = async (req, res) => {
|
||||
// let page;
|
||||
// let rows;
|
||||
// if (!req.query?.rows || req.query?.rows <= 5) {
|
||||
// rows = 10
|
||||
// } else {
|
||||
// rows = parseInt(req.query.rows)
|
||||
// }
|
||||
try {
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
const rows = parseInt(req.query.rows) || 10;
|
||||
const search = req.query.search || "";
|
||||
const sortField = req.query.sortField || "status";
|
||||
const sortOrder = req.query.sortOrder === "desc" ? -1 : 1;
|
||||
const skip = (page - 1) * rows;
|
||||
|
||||
// if (!req.query?.page) {
|
||||
// page = 0
|
||||
// // eslint-disable-next-line eqeqeq
|
||||
// } else if (req.query.page <= 1) {
|
||||
// page = 0
|
||||
// } else {
|
||||
// page = req.query.page
|
||||
// page = page * rows - rows
|
||||
// }
|
||||
const data = await Withdraw.find().sort({ status: 1 })
|
||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
||||
const total = Math.ceil((await Withdraw.estimatedDocumentCount()))
|
||||
res.status(200).json({ data, total })
|
||||
const matchStage = search ? {
|
||||
$or: [
|
||||
{ IMEI: new RegExp(search, 'i') },
|
||||
{ trackingNumber: new RegExp(search, 'i') }
|
||||
]
|
||||
} : {};
|
||||
|
||||
const aggregationPipeline = [
|
||||
{ $match: matchStage },
|
||||
{
|
||||
$lookup: {
|
||||
from: 'users',
|
||||
localField: 'userId',
|
||||
foreignField: '_id',
|
||||
as: 'userId'
|
||||
}
|
||||
},
|
||||
{ $unwind: "$userId" },
|
||||
{ $sort: { [sortField]: sortOrder } },
|
||||
{ $skip: skip },
|
||||
{ $limit: rows }
|
||||
];
|
||||
|
||||
const [data, totalDocuments] = await Promise.all([
|
||||
Withdraw.aggregate(aggregationPipeline),
|
||||
Withdraw.countDocuments(matchStage)
|
||||
]);
|
||||
|
||||
const totalPages = Math.ceil(totalDocuments / rows);
|
||||
|
||||
res.status(200).json({ data, totalDocuments, totalPages });
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "An error occurred, please try again.", error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ const updatebrand = [
|
||||
}
|
||||
|
||||
const linkAvailable = await Brand.findOne({ link });
|
||||
// eslint-disable-next-line eqeqeq
|
||||
if (linkAvailable && linkAvailable.id != req.params.id) {
|
||||
res.status(400).json(_sr.fa.duplicated.link);
|
||||
}
|
||||
|
||||
@@ -173,155 +173,148 @@ module.exports.add_representation = [
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const { user_id } = req
|
||||
const userData = await User.findById(user_id)
|
||||
|
||||
if (!userData || !userData.confirmed){
|
||||
res.status(400).json({msg:'اول شماره تلفن و ایمیل خود را تایید کنید'})
|
||||
|
||||
}else{
|
||||
const {
|
||||
representation_type,
|
||||
full_name,
|
||||
birth_date,
|
||||
id_number,
|
||||
place_of_issue,
|
||||
national_code,
|
||||
fathers_name,
|
||||
education_level,
|
||||
military_status,
|
||||
certificates,
|
||||
store_name,
|
||||
province_name,
|
||||
province_id,
|
||||
city_name,
|
||||
city_id,
|
||||
postal_code,
|
||||
mobile_number,
|
||||
tel_number,
|
||||
fax_number,
|
||||
economic_code,
|
||||
email,
|
||||
address,
|
||||
business_license,
|
||||
ownership_type,
|
||||
total_area,
|
||||
repair_area,
|
||||
stock_area,
|
||||
customer_reference_floor,
|
||||
place_location,
|
||||
geo_location,
|
||||
banner_info,
|
||||
repair_technicians,
|
||||
repair_masters,
|
||||
office_workers,
|
||||
bike_deliveries,
|
||||
computer_repair_exp,
|
||||
multimedia_repair_exp,
|
||||
business_exp,
|
||||
know_asanServ_from,
|
||||
introducer_info,
|
||||
asanServ_products_knowledge,
|
||||
computer_saling_exp,
|
||||
computer_saling_description,
|
||||
other_representations,
|
||||
more_descriptions
|
||||
} = req.body
|
||||
const data = {
|
||||
user_id,
|
||||
representation_type,
|
||||
full_name,
|
||||
birth_date,
|
||||
id_number,
|
||||
place_of_issue,
|
||||
national_code,
|
||||
fathers_name,
|
||||
education_level,
|
||||
military_status,
|
||||
certificates,
|
||||
store_name,
|
||||
province_name,
|
||||
province_id,
|
||||
city_name,
|
||||
city_id,
|
||||
postal_code,
|
||||
mobile_number,
|
||||
tel_number,
|
||||
fax_number,
|
||||
economic_code,
|
||||
email,
|
||||
address,
|
||||
business_license,
|
||||
ownership_type,
|
||||
total_area,
|
||||
repair_area,
|
||||
stock_area,
|
||||
customer_reference_floor,
|
||||
place_location,
|
||||
geo_location,
|
||||
banner_info,
|
||||
repair_technicians,
|
||||
repair_masters,
|
||||
office_workers,
|
||||
bike_deliveries,
|
||||
computer_repair_exp,
|
||||
multimedia_repair_exp,
|
||||
business_exp,
|
||||
know_asanServ_from,
|
||||
introducer_info,
|
||||
asanServ_products_knowledge,
|
||||
computer_saling_exp,
|
||||
computer_saling_description,
|
||||
other_representations,
|
||||
more_descriptions
|
||||
}
|
||||
|
||||
try {
|
||||
const checkUserRepresentations = await Representation.find({ user_id, archived: false })
|
||||
if (checkUserRepresentations.length)
|
||||
return res406(res, 'تا زمانی که درخواست قبلی توسط کارشناسان تعیین وضعیت نشود نمیتوانید درخواست جدیدی ثبت کنید.')
|
||||
const allRepresentations = await Representation.find()
|
||||
const representation_code =
|
||||
'ASAREP' +
|
||||
moment(Date.now()).format('jMMM').toUpperCase() +
|
||||
allRepresentations.length.toString().padStart(4, '0')
|
||||
|
||||
data.representation_code = representation_code
|
||||
|
||||
const representation = new Representation(data)
|
||||
const user = await User.findById(user_id)
|
||||
if(!user){
|
||||
res404(res,"آین کاربر در دیتای ما وجود ندارد")
|
||||
}else{
|
||||
await representation.save()
|
||||
}
|
||||
user.askedForRepresentation = true
|
||||
user.representation_code = representation_code
|
||||
await user.save()
|
||||
|
||||
const smsMessage = [
|
||||
' متقاضی گرامی درخواست شما با کد پیگیری ',
|
||||
representation_code,
|
||||
' در تاریخ ',
|
||||
SmsDateFormat(Date.now()),
|
||||
' در سامانه ثبت شد. ',
|
||||
'\n',
|
||||
' بعد از بررسی مدارک توسط کارشناسان نتیجه از طریق پیامک برای شما ارسال خواهد شد، همچنین میتوانید با کد پیگیری از طریق نشانی زیر وضعیت درخواست خود را بررسی کند. ',
|
||||
'\n',
|
||||
'https://asan-service.com/representation',
|
||||
'\n',
|
||||
phrases.signature
|
||||
]
|
||||
|
||||
const responseMsg = ['درخواست شما باموفقیت ثبت شد.', '\n', ' کد پیگیری: ', representation_code]
|
||||
|
||||
SMS([mobile_number], smsMessage.join(''))
|
||||
notifyAdmin('updateNewRepresentations')
|
||||
return res.json({ message: responseMsg.join('') })
|
||||
} catch (e) {
|
||||
return res500(res, e)
|
||||
}
|
||||
if (!user_id) throw new Error('invalid user id')
|
||||
const {
|
||||
representation_type,
|
||||
full_name,
|
||||
birth_date,
|
||||
id_number,
|
||||
place_of_issue,
|
||||
national_code,
|
||||
fathers_name,
|
||||
education_level,
|
||||
military_status,
|
||||
certificates,
|
||||
store_name,
|
||||
province_name,
|
||||
province_id,
|
||||
city_name,
|
||||
city_id,
|
||||
postal_code,
|
||||
mobile_number,
|
||||
tel_number,
|
||||
fax_number,
|
||||
economic_code,
|
||||
email,
|
||||
address,
|
||||
business_license,
|
||||
ownership_type,
|
||||
total_area,
|
||||
repair_area,
|
||||
stock_area,
|
||||
customer_reference_floor,
|
||||
place_location,
|
||||
geo_location,
|
||||
banner_info,
|
||||
repair_technicians,
|
||||
repair_masters,
|
||||
office_workers,
|
||||
bike_deliveries,
|
||||
computer_repair_exp,
|
||||
multimedia_repair_exp,
|
||||
business_exp,
|
||||
know_asanServ_from,
|
||||
introducer_info,
|
||||
asanServ_products_knowledge,
|
||||
computer_saling_exp,
|
||||
computer_saling_description,
|
||||
other_representations,
|
||||
more_descriptions
|
||||
} = req.body
|
||||
const data = {
|
||||
user_id,
|
||||
representation_type,
|
||||
full_name,
|
||||
birth_date,
|
||||
id_number,
|
||||
place_of_issue,
|
||||
national_code,
|
||||
fathers_name,
|
||||
education_level,
|
||||
military_status,
|
||||
certificates,
|
||||
store_name,
|
||||
province_name,
|
||||
province_id,
|
||||
city_name,
|
||||
city_id,
|
||||
postal_code,
|
||||
mobile_number,
|
||||
tel_number,
|
||||
fax_number,
|
||||
economic_code,
|
||||
email,
|
||||
address,
|
||||
business_license,
|
||||
ownership_type,
|
||||
total_area,
|
||||
repair_area,
|
||||
stock_area,
|
||||
customer_reference_floor,
|
||||
place_location,
|
||||
geo_location,
|
||||
banner_info,
|
||||
repair_technicians,
|
||||
repair_masters,
|
||||
office_workers,
|
||||
bike_deliveries,
|
||||
computer_repair_exp,
|
||||
multimedia_repair_exp,
|
||||
business_exp,
|
||||
know_asanServ_from,
|
||||
introducer_info,
|
||||
asanServ_products_knowledge,
|
||||
computer_saling_exp,
|
||||
computer_saling_description,
|
||||
other_representations,
|
||||
more_descriptions
|
||||
}
|
||||
|
||||
try {
|
||||
const checkUserRepresentations = await Representation.find({ user_id, archived: false })
|
||||
if (checkUserRepresentations.length)
|
||||
return res406(res, 'تا زمانی که درخواست قبلی توسط کارشناسان تعیین وضعیت نشود نمیتوانید درخواست جدیدی ثبت کنید.')
|
||||
const allRepresentations = await Representation.find()
|
||||
const representation_code =
|
||||
'ASAREP' +
|
||||
moment(Date.now()).format('jMMM').toUpperCase() +
|
||||
allRepresentations.length.toString().padStart(4, '0')
|
||||
|
||||
data.representation_code = representation_code
|
||||
|
||||
const representation = new Representation(data)
|
||||
const user = await User.findById(user_id)
|
||||
if(!user){
|
||||
res404(res,"آین کاربر در دیتای ما وجود ندارد")
|
||||
}else{
|
||||
await representation.save()
|
||||
}
|
||||
user.askedForRepresentation = true
|
||||
user.representation_code = representation_code
|
||||
await user.save()
|
||||
|
||||
const smsMessage = [
|
||||
' متقاضی گرامی درخواست شما با کد پیگیری ',
|
||||
representation_code,
|
||||
' در تاریخ ',
|
||||
SmsDateFormat(Date.now()),
|
||||
' در سامانه ثبت شد. ',
|
||||
'\n',
|
||||
' بعد از بررسی مدارک توسط کارشناسان نتیجه از طریق پیامک برای شما ارسال خواهد شد، همچنین میتوانید با کد پیگیری از طریق نشانی زیر وضعیت درخواست خود را بررسی کند. ',
|
||||
'\n',
|
||||
'https://asan-service.com/representation',
|
||||
'\n',
|
||||
phrases.signature
|
||||
]
|
||||
|
||||
const responseMsg = ['درخواست شما باموفقیت ثبت شد.', '\n', ' کد پیگیری: ', representation_code]
|
||||
|
||||
SMS([mobile_number], smsMessage.join(''))
|
||||
notifyAdmin('updateNewRepresentations')
|
||||
return res.json({ message: responseMsg.join('') })
|
||||
} catch (e) {
|
||||
return res500(res, e)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -570,17 +570,14 @@ module.exports.update_user = [
|
||||
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
|
||||
@@ -597,11 +594,10 @@ module.exports.update_user = [
|
||||
|
||||
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 })
|
||||
return res.json({ message: _faSr.response.success_save , data:user })
|
||||
} catch (e) {
|
||||
console.log('Arpa Error during update user --', e)
|
||||
return res500(res, _faSr.response.problem)
|
||||
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
const mongoose = require('mongoose')
|
||||
// mongodb database connection string. change it as per your needs. here "mydb" is the name of the database. You don't need to create DB from mongodb terminal. mongoose create the database automatically.
|
||||
const inHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@asan-service:27017/asanserv_database?authSource=admin'
|
||||
const inHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
|
||||
const outHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
|
||||
const init = ()=>{
|
||||
try {
|
||||
@@ -9,7 +9,9 @@ const init = ()=>{
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useFindAndModify: false,
|
||||
useCreateIndex: true
|
||||
useCreateIndex: true,
|
||||
connectTimeoutMS: 30000,
|
||||
socketTimeoutMS: 45000,
|
||||
})
|
||||
} catch (error) {
|
||||
init()
|
||||
|
||||
@@ -15,8 +15,8 @@ const UserSchema = mongoose.Schema({
|
||||
first_name: String,
|
||||
last_name: String,
|
||||
national_code: String,
|
||||
province_name: String,
|
||||
city_name: String,
|
||||
province_name: Object,
|
||||
city_name: Object,
|
||||
address: String,
|
||||
mobile_number: String,
|
||||
cell_number:String,
|
||||
|
||||
@@ -17,7 +17,7 @@ router.get('/notif', notif.setSeenAll)
|
||||
|
||||
/// /////////////// User
|
||||
router.get('/user/me', userGPS.getCurrent)
|
||||
router.put('/user/me', userGPS.update_user)
|
||||
router.put('/user/me/:id', userGPS.update_user)
|
||||
|
||||
router.post('/user/reset-pass', userGPS.update_user_password)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user