Merge
This commit is contained in:
@@ -7,8 +7,6 @@ const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
|||||||
const UserGPS = require('../models/GPS.User')
|
const UserGPS = require('../models/GPS.User')
|
||||||
const { generateRandomDigits
|
const { generateRandomDigits
|
||||||
} = require('../plugins/controllersHelperFunctions')
|
} = require('../plugins/controllersHelperFunctions')
|
||||||
const Notification = require('../models/GPS.Notif')
|
|
||||||
|
|
||||||
module.exports.login_with_pass = [
|
module.exports.login_with_pass = [
|
||||||
[
|
[
|
||||||
body('username')
|
body('username')
|
||||||
@@ -57,10 +55,6 @@ module.exports.login_with_pass = [
|
|||||||
})
|
})
|
||||||
user.token = token
|
user.token = token
|
||||||
await user.save()
|
await user.save()
|
||||||
await Notification.create({
|
|
||||||
userID:user._id,
|
|
||||||
content:"test"
|
|
||||||
})
|
|
||||||
return res.status(200).json({ token })
|
return res.status(200).json({ token })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(422).json({
|
return res.status(422).json({
|
||||||
@@ -96,10 +90,6 @@ module.exports.login_with_otp = [
|
|||||||
})
|
})
|
||||||
user.otp = generateRandomDigits(6)
|
user.otp = generateRandomDigits(6)
|
||||||
user.save()
|
user.save()
|
||||||
await Notification.create({
|
|
||||||
userID:user._id,
|
|
||||||
content:"test"
|
|
||||||
})
|
|
||||||
return res.status(200).json({ token })
|
return res.status(200).json({ token })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable no-lonely-if */
|
|
||||||
const { body, param, validationResult } = require('express-validator')
|
const { body, param, validationResult } = require('express-validator')
|
||||||
const { _sr } = require('../plugins/serverResponses')
|
const { _sr } = require('../plugins/serverResponses')
|
||||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||||
@@ -15,29 +14,23 @@ module.exports.addCard = [
|
|||||||
try {
|
try {
|
||||||
const { holderName, PAN, IBAN } = req.body;
|
const { holderName, PAN, IBAN } = req.body;
|
||||||
const userData = await User.findById(req.user_id).select('id cardBank')
|
const userData = await User.findById(req.user_id).select('id cardBank')
|
||||||
if(userData?.cardBank && Array.isArray(userData?.cardBank) && userData?.cardBank.length >= 5){
|
if (userData?.cardBank && Array.isArray(userData?.cardBank)) {
|
||||||
res.status(400).json({ msg: 'شما به حداکثر میزان مجاز رسیدید' })
|
userData.cardBank.push({
|
||||||
}else{
|
holderName,
|
||||||
if (userData?.cardBank && Array.isArray(userData?.cardBank)) {
|
PAN,
|
||||||
userData.cardBank.push({
|
IBAN
|
||||||
holderName,
|
})
|
||||||
PAN,
|
userData.save()
|
||||||
IBAN
|
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||||
})
|
} else {
|
||||||
userData.save()
|
userData.cardBank = [{
|
||||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
holderName,
|
||||||
} else {
|
PAN,
|
||||||
userData.cardBank = [{
|
IBAN
|
||||||
holderName,
|
}];
|
||||||
PAN,
|
userData.save()
|
||||||
IBAN
|
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||||
}];
|
|
||||||
userData.save()
|
|
||||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ msg: error })
|
res.status(500).json({ msg: error })
|
||||||
|
|
||||||
|
|||||||
@@ -44,71 +44,97 @@ module.exports.deviceRegistration = [
|
|||||||
module.exports.getAllForUser = async (req, res) => {
|
module.exports.getAllForUser = async (req, res) => {
|
||||||
let page;
|
let page;
|
||||||
let rows;
|
let rows;
|
||||||
|
|
||||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||||
rows = 10
|
rows = 10;
|
||||||
} else {
|
} else {
|
||||||
rows = parseInt(req.query.rows)
|
rows = parseInt(req.query.rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.query?.page) {
|
if (!req.query?.page || req.query.page <= 1) {
|
||||||
page = 0
|
page = 0;
|
||||||
// eslint-disable-next-line eqeqeq
|
|
||||||
} else if (req.query.page <= 1) {
|
|
||||||
page = 0
|
|
||||||
} else {
|
} else {
|
||||||
page = req.query.page
|
page = (req.query.page - 1) * rows;
|
||||||
page = page * rows - rows
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const search = req.query?.search ? req.query.search : null
|
const search = req.query?.search || null;
|
||||||
let sort
|
|
||||||
if(req.query?.sort){
|
let sort = {};
|
||||||
sort= req.query?.sort
|
|
||||||
}else{
|
if (req.query?.deviceId_dollarProfit) {
|
||||||
sort= { created_at: -1 }
|
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 = {
|
const filter = {
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
}
|
};
|
||||||
if(search){
|
|
||||||
filter.$or = [
|
if (search) {
|
||||||
{ IMEI: { $regex: 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)))
|
const total = await InstalledDevice.countDocuments(filter);
|
||||||
res.status(200).json({ data, total })
|
|
||||||
|
|
||||||
}
|
res.status(200).json({ data, total });
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ message: 'An error occurred', error });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.getAllForAdmin = async (req, res) => {
|
module.exports.getAllForAdmin = async (req, res) => {
|
||||||
// let page;
|
try {
|
||||||
// let rows;
|
const page = parseInt(req.query.page) || 1;
|
||||||
// if (!req.query?.rows || req.query?.rows <= 5) {
|
const rows = parseInt(req.query.rows) || 10;
|
||||||
// rows = 10
|
const search = req.query.search || "";
|
||||||
// } else {
|
const sortField = req.query.sortField || "status";
|
||||||
// rows = parseInt(req.query.rows)
|
const sortOrder = req.query.sortOrder === "desc" ? -1 : 1;
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!req.query?.page) {
|
const skip = (page - 1) * rows;
|
||||||
// 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 data = await InstalledDevice.find({}).sort({ status: 1 })
|
const filter = {};
|
||||||
.populate('deviceId')
|
if (search) {
|
||||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
filter.$or = [
|
||||||
const total = Math.ceil((await InstalledDevice.estimatedDocumentCount()))
|
{ IMEI: new RegExp(search, 'i') },
|
||||||
res.status(200).json({ data, total })
|
{ '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)
|
const device = await Device.findById(installedDevice.deviceId)
|
||||||
switch (req.params.type) {
|
switch (req.params.type) {
|
||||||
case "accept": {
|
case "accept": {
|
||||||
|
|
||||||
installedDevice.status = 1;
|
installedDevice.status = 1;
|
||||||
installedDevice.installationDate = new Date();
|
installedDevice.installationDate = new Date();
|
||||||
|
|
||||||
device.status = 1;
|
device.status = 1;
|
||||||
|
|
||||||
user.walletBalance += device.profit
|
user.walletBalance += device.profit
|
||||||
@@ -167,7 +191,7 @@ module.exports.updateInstalled = [
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
res.status(404).json({ msg: "استاتوس اشتباه است" })
|
res.status(404).json({ msg: "وضعیت اشتباه است" })
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,44 +9,52 @@ const User = require('../models/GPS.User')
|
|||||||
module.exports.getAll = async (req, res) => {
|
module.exports.getAll = async (req, res) => {
|
||||||
let page;
|
let page;
|
||||||
let rows;
|
let rows;
|
||||||
|
|
||||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
if (!req.query?.rows || req.query?.rows <= 5) {
|
||||||
rows = 10
|
rows = 10;
|
||||||
} else {
|
} else {
|
||||||
rows = parseInt(req.query.rows)
|
rows = parseInt(req.query.rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.query?.page) {
|
if (!req.query?.page) {
|
||||||
page = 0
|
page = 0;
|
||||||
// eslint-disable-next-line eqeqeq
|
|
||||||
} else if (req.query.page <= 1) {
|
} else if (req.query.page <= 1) {
|
||||||
page = 0
|
page = 0;
|
||||||
} else {
|
} else {
|
||||||
page = req.query.page
|
page = req.query.page;
|
||||||
page = page * rows - rows
|
page = page * rows - rows;
|
||||||
}
|
}
|
||||||
const search = req.query?.search ? req.query.search : null
|
|
||||||
|
|
||||||
let sort
|
const search = req.query?.search ? req.query.search : null;
|
||||||
if(req.query?.sort){
|
|
||||||
sort= req.query?.sort
|
let sort = {};
|
||||||
}else{
|
|
||||||
sort= { created_at: -1 }
|
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 = {
|
const filter = {
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
}
|
};
|
||||||
|
|
||||||
if(search){
|
if (search) {
|
||||||
filter.$or = [
|
filter.$or = [
|
||||||
{ title: { $regex: search } },
|
{ title: new RegExp(search, 'i') },
|
||||||
{ score: search },
|
...(!isNaN(search) ? [{ score: Number(search) }] : []),
|
||||||
]
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
const score = await Score.find(filter).skip(page).limit(rows).sort(sort);
|
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')
|
const user = await User.findById(req.user_id).select('score');
|
||||||
res.status(200).json({ data: score, score: user.score, total })
|
res.status(200).json({ data: score, score: user.score, total });
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
const bcrypt = require('bcryptjs')
|
const bcrypt = require('bcryptjs')
|
||||||
const { body, validationResult, param } = require('express-validator')
|
const { body, validationResult, param } = require('express-validator')
|
||||||
|
const uid = require('uuid')
|
||||||
const User = require('../models/GPS.User')
|
const User = require('../models/GPS.User')
|
||||||
const { _sr } = require('../plugins/serverResponses')
|
const { _sr } = require('../plugins/serverResponses')
|
||||||
const { SMS } = require('../plugins/SMS_Module')
|
const { SMS } = require('../plugins/SMS_Module')
|
||||||
@@ -130,6 +131,9 @@ module.exports.register_user = [
|
|||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const provinceId = uid.v4()
|
||||||
|
const cityId = uid.v4()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
@@ -143,8 +147,8 @@ module.exports.register_user = [
|
|||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
last_name,
|
last_name,
|
||||||
province_name,
|
province_name:{id:provinceId,provinceName:province_name},
|
||||||
city_name,
|
city_name:{id:cityId,cityName:city_name},
|
||||||
shopName
|
shopName
|
||||||
}
|
}
|
||||||
data.first_name = nameOptimizer(first_name)
|
data.first_name = nameOptimizer(first_name)
|
||||||
@@ -250,7 +254,8 @@ module.exports.update_user = [
|
|||||||
req.params.id,
|
req.params.id,
|
||||||
data
|
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) {
|
} catch (err) {
|
||||||
const registerFailurMsg = 'مشکلی در به روز رسانی پیش آمده، لطفا مجددا تلاش کنید'
|
const registerFailurMsg = 'مشکلی در به روز رسانی پیش آمده، لطفا مجددا تلاش کنید'
|
||||||
throw new Error(registerFailurMsg)
|
throw new Error(registerFailurMsg)
|
||||||
@@ -383,7 +388,7 @@ module.exports.resetpass_otp = [
|
|||||||
module.exports.getCurrent = async (req, res) => {
|
module.exports.getCurrent = async (req, res) => {
|
||||||
const user = await User.findById(req.user_id).select('-password -token -otp -seenByAdmin')
|
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 })
|
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) => {
|
module.exports.getUsersForAdmin = async (req, res) => {
|
||||||
|
|||||||
@@ -49,71 +49,102 @@ module.exports.createRequest = [
|
|||||||
|
|
||||||
|
|
||||||
module.exports.getAllForUser = async (req, res) => {
|
module.exports.getAllForUser = async (req, res) => {
|
||||||
let page;
|
const rows = (!req.query?.rows || req.query?.rows <= 5) ? 10 : parseInt(req.query.rows);
|
||||||
let rows;
|
|
||||||
if (!req.query?.rows || req.query?.rows <= 5) {
|
let page = 0;
|
||||||
rows = 10
|
if (req.query?.page && req.query.page > 1) {
|
||||||
} else {
|
page = (req.query.page - 1) * rows;
|
||||||
rows = parseInt(req.query.rows)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.query?.page) {
|
const search = req.query?.search || null;
|
||||||
page = 0
|
|
||||||
// eslint-disable-next-line eqeqeq
|
let sort = {};
|
||||||
} else if (req.query.page <= 1) {
|
|
||||||
page = 0
|
if (req.query?.created_at) {
|
||||||
} else {
|
sort.created_at = parseInt(req.query.created_at);
|
||||||
page = req.query.page
|
|
||||||
page = page * rows - rows
|
|
||||||
}
|
}
|
||||||
const search = req.query?.search ? req.query.search : null
|
|
||||||
let sort
|
if (req.query?.updated_at) {
|
||||||
if(req.query?.sort){
|
sort.updated_at = parseInt(req.query.updated_at);
|
||||||
sort= req.query?.sort
|
}
|
||||||
}else{
|
|
||||||
sort= { created_at: -1 }
|
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 = {
|
const filter = {
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
}
|
};
|
||||||
|
|
||||||
if(search){
|
if (search) {
|
||||||
filter.$or = [
|
filter.$or = [
|
||||||
{ amount: search },
|
{ amount: search },
|
||||||
{ dollarAmount: 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 data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort);
|
||||||
const total = Math.ceil((await Withdraw.countDocuments(filter)))
|
const total = 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) => {
|
module.exports.getAllForAdmin = async (req, res) => {
|
||||||
// let page;
|
try {
|
||||||
// let rows;
|
const page = parseInt(req.query.page) || 1;
|
||||||
// if (!req.query?.rows || req.query?.rows <= 5) {
|
const rows = parseInt(req.query.rows) || 10;
|
||||||
// rows = 10
|
const search = req.query.search || "";
|
||||||
// } else {
|
const sortField = req.query.sortField || "status";
|
||||||
// rows = parseInt(req.query.rows)
|
const sortOrder = req.query.sortOrder === "desc" ? -1 : 1;
|
||||||
// }
|
const skip = (page - 1) * rows;
|
||||||
|
|
||||||
// if (!req.query?.page) {
|
const matchStage = search ? {
|
||||||
// page = 0
|
$or: [
|
||||||
// // eslint-disable-next-line eqeqeq
|
{ IMEI: new RegExp(search, 'i') },
|
||||||
// } else if (req.query.page <= 1) {
|
{ trackingNumber: new RegExp(search, 'i') }
|
||||||
// page = 0
|
]
|
||||||
// } else {
|
} : {};
|
||||||
// page = req.query.page
|
|
||||||
// page = page * rows - rows
|
const aggregationPipeline = [
|
||||||
// }
|
{ $match: matchStage },
|
||||||
const data = await Withdraw.find().sort({ status: 1 })
|
{
|
||||||
.populate('userId', 'shopName national_code first_name last_name mobile_number city_name province_name')
|
$lookup: {
|
||||||
const total = Math.ceil((await Withdraw.estimatedDocumentCount()))
|
from: 'users',
|
||||||
res.status(200).json({ data, total })
|
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 });
|
const linkAvailable = await Brand.findOne({ link });
|
||||||
|
// eslint-disable-next-line eqeqeq
|
||||||
if (linkAvailable && linkAvailable.id != req.params.id) {
|
if (linkAvailable && linkAvailable.id != req.params.id) {
|
||||||
res.status(400).json(_sr.fa.duplicated.link);
|
res.status(400).json(_sr.fa.duplicated.link);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,155 +173,148 @@ module.exports.add_representation = [
|
|||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { user_id } = req
|
const { user_id } = req
|
||||||
const userData = await User.findById(user_id)
|
if (!user_id) throw new Error('invalid user id')
|
||||||
|
const {
|
||||||
if (!userData || !userData.confirmed){
|
representation_type,
|
||||||
res.status(400).json({msg:'اول شماره تلفن و ایمیل خود را تایید کنید'})
|
full_name,
|
||||||
|
birth_date,
|
||||||
}else{
|
id_number,
|
||||||
const {
|
place_of_issue,
|
||||||
representation_type,
|
national_code,
|
||||||
full_name,
|
fathers_name,
|
||||||
birth_date,
|
education_level,
|
||||||
id_number,
|
military_status,
|
||||||
place_of_issue,
|
certificates,
|
||||||
national_code,
|
store_name,
|
||||||
fathers_name,
|
province_name,
|
||||||
education_level,
|
province_id,
|
||||||
military_status,
|
city_name,
|
||||||
certificates,
|
city_id,
|
||||||
store_name,
|
postal_code,
|
||||||
province_name,
|
mobile_number,
|
||||||
province_id,
|
tel_number,
|
||||||
city_name,
|
fax_number,
|
||||||
city_id,
|
economic_code,
|
||||||
postal_code,
|
email,
|
||||||
mobile_number,
|
address,
|
||||||
tel_number,
|
business_license,
|
||||||
fax_number,
|
ownership_type,
|
||||||
economic_code,
|
total_area,
|
||||||
email,
|
repair_area,
|
||||||
address,
|
stock_area,
|
||||||
business_license,
|
customer_reference_floor,
|
||||||
ownership_type,
|
place_location,
|
||||||
total_area,
|
geo_location,
|
||||||
repair_area,
|
banner_info,
|
||||||
stock_area,
|
repair_technicians,
|
||||||
customer_reference_floor,
|
repair_masters,
|
||||||
place_location,
|
office_workers,
|
||||||
geo_location,
|
bike_deliveries,
|
||||||
banner_info,
|
computer_repair_exp,
|
||||||
repair_technicians,
|
multimedia_repair_exp,
|
||||||
repair_masters,
|
business_exp,
|
||||||
office_workers,
|
know_asanServ_from,
|
||||||
bike_deliveries,
|
introducer_info,
|
||||||
computer_repair_exp,
|
asanServ_products_knowledge,
|
||||||
multimedia_repair_exp,
|
computer_saling_exp,
|
||||||
business_exp,
|
computer_saling_description,
|
||||||
know_asanServ_from,
|
other_representations,
|
||||||
introducer_info,
|
more_descriptions
|
||||||
asanServ_products_knowledge,
|
} = req.body
|
||||||
computer_saling_exp,
|
const data = {
|
||||||
computer_saling_description,
|
user_id,
|
||||||
other_representations,
|
representation_type,
|
||||||
more_descriptions
|
full_name,
|
||||||
} = req.body
|
birth_date,
|
||||||
const data = {
|
id_number,
|
||||||
user_id,
|
place_of_issue,
|
||||||
representation_type,
|
national_code,
|
||||||
full_name,
|
fathers_name,
|
||||||
birth_date,
|
education_level,
|
||||||
id_number,
|
military_status,
|
||||||
place_of_issue,
|
certificates,
|
||||||
national_code,
|
store_name,
|
||||||
fathers_name,
|
province_name,
|
||||||
education_level,
|
province_id,
|
||||||
military_status,
|
city_name,
|
||||||
certificates,
|
city_id,
|
||||||
store_name,
|
postal_code,
|
||||||
province_name,
|
mobile_number,
|
||||||
province_id,
|
tel_number,
|
||||||
city_name,
|
fax_number,
|
||||||
city_id,
|
economic_code,
|
||||||
postal_code,
|
email,
|
||||||
mobile_number,
|
address,
|
||||||
tel_number,
|
business_license,
|
||||||
fax_number,
|
ownership_type,
|
||||||
economic_code,
|
total_area,
|
||||||
email,
|
repair_area,
|
||||||
address,
|
stock_area,
|
||||||
business_license,
|
customer_reference_floor,
|
||||||
ownership_type,
|
place_location,
|
||||||
total_area,
|
geo_location,
|
||||||
repair_area,
|
banner_info,
|
||||||
stock_area,
|
repair_technicians,
|
||||||
customer_reference_floor,
|
repair_masters,
|
||||||
place_location,
|
office_workers,
|
||||||
geo_location,
|
bike_deliveries,
|
||||||
banner_info,
|
computer_repair_exp,
|
||||||
repair_technicians,
|
multimedia_repair_exp,
|
||||||
repair_masters,
|
business_exp,
|
||||||
office_workers,
|
know_asanServ_from,
|
||||||
bike_deliveries,
|
introducer_info,
|
||||||
computer_repair_exp,
|
asanServ_products_knowledge,
|
||||||
multimedia_repair_exp,
|
computer_saling_exp,
|
||||||
business_exp,
|
computer_saling_description,
|
||||||
know_asanServ_from,
|
other_representations,
|
||||||
introducer_info,
|
more_descriptions
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
const user = await User.findById(user_id)
|
||||||
if (!user) return res404(res, _faSr.not_found.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 newEmail = user.email !== MongoData.email
|
||||||
const newMobile = user.mobile_number !== MongoData.mobile_number
|
const newMobile = user.mobile_number !== MongoData.mobile_number
|
||||||
if (newEmail) user.email_confirmed = false
|
if (newEmail) user.email_confirmed = false
|
||||||
if (newMobile) user.mobile_confirmed = false
|
if (newMobile) user.mobile_confirmed = false
|
||||||
|
|
||||||
// save new info to arpa
|
|
||||||
await updateUserOnArpa(MongoData, user.verity_businessID, 'verity')
|
await updateUserOnArpa(MongoData, user.verity_businessID, 'verity')
|
||||||
await updateUserOnArpa(MongoData, user.panatech_businessID, 'panatech')
|
await updateUserOnArpa(MongoData, user.panatech_businessID, 'panatech')
|
||||||
|
|
||||||
// save new info to user
|
|
||||||
user.first_name = MongoData.first_name
|
user.first_name = MongoData.first_name
|
||||||
user.last_name = MongoData.last_name
|
user.last_name = MongoData.last_name
|
||||||
user.national_code = MongoData.national_code
|
user.national_code = MongoData.national_code
|
||||||
@@ -597,11 +594,10 @@ module.exports.update_user = [
|
|||||||
|
|
||||||
await user.save()
|
await user.save()
|
||||||
|
|
||||||
// send confirmation key after user saved
|
|
||||||
if (newEmail) await sendConfirmationEmail(user_id)
|
if (newEmail) await sendConfirmationEmail(user_id)
|
||||||
if (newMobile) await sendConfirmationSMS(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) {
|
} catch (e) {
|
||||||
console.log('Arpa Error during update user --', e)
|
console.log('Arpa Error during update user --', e)
|
||||||
return res500(res, _faSr.response.problem)
|
return res500(res, _faSr.response.problem)
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-unused-vars */
|
||||||
const mongoose = require('mongoose')
|
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.
|
// 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 outHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
|
||||||
const init = ()=>{
|
const init = ()=>{
|
||||||
try {
|
try {
|
||||||
@@ -9,7 +9,9 @@ const init = ()=>{
|
|||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
useFindAndModify: false,
|
useFindAndModify: false,
|
||||||
useCreateIndex: true
|
useCreateIndex: true,
|
||||||
|
connectTimeoutMS: 30000,
|
||||||
|
socketTimeoutMS: 45000,
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
init()
|
init()
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ const UserSchema = mongoose.Schema({
|
|||||||
first_name: String,
|
first_name: String,
|
||||||
last_name: String,
|
last_name: String,
|
||||||
national_code: String,
|
national_code: String,
|
||||||
province_name: String,
|
province_name: Object,
|
||||||
city_name: String,
|
city_name: Object,
|
||||||
address: String,
|
address: String,
|
||||||
mobile_number: String,
|
mobile_number: String,
|
||||||
cell_number:String,
|
cell_number:String,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ router.get('/notif', notif.setSeenAll)
|
|||||||
|
|
||||||
/// /////////////// User
|
/// /////////////// User
|
||||||
router.get('/user/me', userGPS.getCurrent)
|
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)
|
router.post('/user/reset-pass', userGPS.update_user_password)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user