feat: add route to update and add cardbank and fix
This commit is contained in:
@@ -7,12 +7,12 @@ module.exports.addCard = [
|
|||||||
[
|
[
|
||||||
body('holderName').notEmpty().isString().withMessage(_sr.fa.required.name),
|
body('holderName').notEmpty().isString().withMessage(_sr.fa.required.name),
|
||||||
body('PAN').notEmpty().isInt().withMessage(_sr.fa.required.store_number),
|
body('PAN').notEmpty().isInt().withMessage(_sr.fa.required.store_number),
|
||||||
body('IBAN').notEmpty().isIBAN().withMessage(_sr.fa.required.address)
|
body('IBAN').notEmpty().isLength({ min: 24, max: 24 }).withMessage(_sr.fa.required.iban)
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
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)) {
|
if (userData?.cardBank && Array.isArray(userData?.cardBank)) {
|
||||||
userData.cardBank.push({
|
userData.cardBank.push({
|
||||||
@@ -23,40 +23,73 @@ module.exports.addCard = [
|
|||||||
userData.save()
|
userData.save()
|
||||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||||
} else {
|
} else {
|
||||||
userData.cardBank = [{
|
userData.cardBank = [
|
||||||
|
{
|
||||||
holderName,
|
holderName,
|
||||||
PAN,
|
PAN,
|
||||||
IBAN
|
IBAN
|
||||||
}];
|
}
|
||||||
|
]
|
||||||
userData.save()
|
userData.save()
|
||||||
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
res.status(201).json({ msg: 'با موفقیت ثبت شد ' })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ msg: error })
|
res.status(500).json({ msg: error })
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
module.exports.getAll = [
|
module.exports.getAll = [
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const userData = await User.findById(req.user_id).select('id cardBank')
|
const userData = await User.findById(req.user_id).select('id cardBank')
|
||||||
res.status(200).json(userData)
|
res.status(200).json(userData)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
module.exports.getOne = [
|
||||||
|
async (req, res) => {
|
||||||
|
const userCart = await User.findOne({ _id: req.user_id, 'cardBank._id': req.params.id }).select('id cardBank')
|
||||||
|
console.log(userCart)
|
||||||
|
res.status(200).json({ userCart: userCart.cardBank[0] })
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
module.exports.updateCard = [
|
||||||
|
[
|
||||||
|
param('id').notEmpty().isMongoId().withMessage('این ایدی اشتباه می باشد'),
|
||||||
|
body('holderName').notEmpty().isString().withMessage(_sr.fa.required.name),
|
||||||
|
body('PAN').notEmpty().isInt().withMessage(_sr.fa.required.store_number),
|
||||||
|
body('IBAN').notEmpty().isLength({ min: 24, max: 24 }).withMessage(_sr.fa.required.iban)
|
||||||
|
],
|
||||||
|
checkValidations(validationResult),
|
||||||
|
async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { holderName, PAN, IBAN } = req.body
|
||||||
|
const userData = await User.findOneAndUpdate(
|
||||||
|
{ _id: req.user_id, 'cardBank._id': req.params.id },
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
'cardBank.$.holderName': holderName,
|
||||||
|
'cardBank.$.PAN': PAN,
|
||||||
|
'cardBank.$.IBAN': IBAN
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ new: true }
|
||||||
|
).select('id cardBank')
|
||||||
|
res.status(200).json(userData)
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ msg: error.message })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
module.exports.deleteCard = [
|
module.exports.deleteCard = [
|
||||||
[
|
[param('id').notEmpty().isMongoId().withMessage('این ایدی اشتباه می باشد')],
|
||||||
param('id').notEmpty().isMongoId().withMessage('این ایدی اشتباه می باشد')
|
|
||||||
],
|
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const userData = await User.findOneAndUpdate(
|
const userData = await User.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
_id: req.user_id,
|
_id: req.user_id,
|
||||||
"cardBank._id": req.params.id
|
'cardBank._id': req.params.id
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$pull: {
|
$pull: {
|
||||||
@@ -67,6 +100,5 @@ module.exports.deleteCard = [
|
|||||||
).select('id cardBank')
|
).select('id cardBank')
|
||||||
// res.status(200).json({ msg: "با موفقیت حذف شد ", data: userData })
|
// res.status(200).json({ msg: "با موفقیت حذف شد ", data: userData })
|
||||||
res.status(200).json(userData)
|
res.status(200).json(userData)
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
const readXlsxFile = require('read-excel-file/node')
|
const readXlsxFile = require('read-excel-file/node')
|
||||||
const { body, param, validationResult } = require('express-validator');
|
const { body, param, validationResult } = require('express-validator')
|
||||||
const xlsx = require("json-as-xlsx")
|
const xlsx = require('json-as-xlsx')
|
||||||
const { _sr } = require('../plugins/serverResponses');
|
const { _sr } = require('../plugins/serverResponses')
|
||||||
const { checkValidations, res500 } = require('../plugins/controllersHelperFunctions');
|
const { checkValidations, res500 } = require('../plugins/controllersHelperFunctions')
|
||||||
const Device = require('../models/GPS.Device');
|
const Device = require('../models/GPS.Device')
|
||||||
module.exports.addCode = [
|
module.exports.addCode = [
|
||||||
[
|
[
|
||||||
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
|
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
|
||||||
body('IMEI').notEmpty().isIMEI().trim().withMessage('لطفا IMEI را وارد یا تصحیح کنید').custom(async (v) => {
|
body('IMEI')
|
||||||
|
.notEmpty()
|
||||||
|
.isIMEI()
|
||||||
|
.trim()
|
||||||
|
.withMessage('لطفا IMEI را وارد یا تصحیح کنید')
|
||||||
|
.custom(async v => {
|
||||||
const device = await Device.findOne({ IMEI: v })
|
const device = await Device.findOne({ IMEI: v })
|
||||||
if (device) {
|
if (device) {
|
||||||
return Promise.reject(_sr.fa.duplicated.IMEI)
|
return Promise.reject(_sr.fa.duplicated.IMEI)
|
||||||
@@ -15,46 +20,39 @@ module.exports.addCode = [
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage("قیمت دستگاه را به تومتن وارد کنید"),
|
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'),
|
||||||
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage("سود نصاب را به دلار وارد کنید"),
|
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'),
|
||||||
body('profit').notEmpty().isInt({ min: 0 }).withMessage("سود نصاب را به تومان وارد کنید"),
|
body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'),
|
||||||
body('score').notEmpty().isInt({ min: 0 }).withMessage("امتیاز دریافتی نصاب را وارد کنید"),
|
body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
|
||||||
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage("سود دریافتی نصاب را از تمدید اشتراک وارد کنید"),
|
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const data = await Device.create(req.body)
|
const data = await Device.create(req.body)
|
||||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data })
|
// res.status(201).json({ msg: _sr.fa.response.success_save, data })
|
||||||
res.status(201).json(data)
|
res.status(201).json(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports.importExel = async (req, res) => {
|
module.exports.importExel = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
if (!req.files?.file) return res.status(422).json({ validation: { file: { msg: 'فایل را اضافه کنید' } } })
|
if (!req.files?.file) return res.status(422).json({ validation: { file: { msg: 'فایل را اضافه کنید' } } })
|
||||||
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item))) return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
|
if (!req.files?.file.name.split('.').some(item => ['xlsx', 'xltx', 'xlsm', 'xlsb'].includes(item)))
|
||||||
|
return res.status(422).json({ validation: { file: { msg: 'فرمت فایل درست نمیباشد' } } })
|
||||||
const file = req.files.file
|
const file = req.files.file
|
||||||
|
|
||||||
const exelFile = await readXlsxFile(Buffer.from(file.data));
|
const exelFile = await readXlsxFile(Buffer.from(file.data))
|
||||||
const data = await creator(exelFile)
|
const data = await creator(exelFile)
|
||||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data })
|
// res.status(201).json({ msg: _sr.fa.response.success_save, data })
|
||||||
res.status(201).json(data)
|
res.status(201).json(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error)
|
||||||
res500(res, error)
|
res500(res, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getAll = [
|
module.exports.getAll = [
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
|
||||||
const data = await Device.find().sort({ created_at: -1 })
|
const data = await Device.find().sort({ created_at: -1 })
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
}
|
}
|
||||||
@@ -62,47 +60,44 @@ module.exports.getAll = [
|
|||||||
|
|
||||||
module.exports.downloadAll = [
|
module.exports.downloadAll = [
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
|
|
||||||
const device = await Device.find().sort({ created_at: -1 })
|
const device = await Device.find().sort({ created_at: -1 })
|
||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
sheet: "device",
|
sheet: 'device',
|
||||||
columns: [
|
columns: [
|
||||||
{ label: "IMEI", value: "IMEI" },
|
{ label: 'IMEI', value: 'IMEI' },
|
||||||
{ label: "مدل", value: "model" },
|
{ label: 'مدل', value: 'model' },
|
||||||
{ label: "قیمت به تومان", value: "tomanPrice" },
|
{ label: 'قیمت به تومان', value: 'tomanPrice' },
|
||||||
{ label: "سود به دلار", value: "dollarProfit" },
|
{ label: 'سود به دلار', value: 'dollarProfit' },
|
||||||
{ label: "سود به تومان", value: "profit" },
|
{ label: 'سود به تومان', value: 'profit' },
|
||||||
{ label: "امتیاز", value: "score" },
|
{ label: 'امتیاز', value: 'score' },
|
||||||
{ label: "سود از تمدید", value: "renewalProfit" },
|
{ label: 'سود از تمدید', value: 'renewalProfit' },
|
||||||
{ label: "وضعیت نصب", value: "status" },
|
{ label: 'وضعیت نصب', value: 'status' }
|
||||||
],
|
],
|
||||||
content: device,
|
content: device
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const settings = {
|
const settings = {
|
||||||
writeOptions: {
|
writeOptions: {
|
||||||
type: "buffer",
|
type: 'buffer',
|
||||||
bookType: "csv",
|
bookType: 'csv'
|
||||||
},
|
},
|
||||||
RTL: true
|
RTL: true
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const buffer = xlsx(data, settings)
|
const buffer = xlsx(data, settings)
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
"Content-Type": "application/octet-stream",
|
'Content-Type': 'application/octet-stream',
|
||||||
"Content-disposition": "attachment; filename=device.csv",
|
'Content-disposition': 'attachment; filename=device.csv'
|
||||||
})
|
})
|
||||||
res.end(buffer)
|
res.end(buffer)
|
||||||
}, 2000);
|
}, 2000)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
module.exports.getOne = [
|
module.exports.getOne = [
|
||||||
[
|
[param('id').notEmpty().isMongoId().withMessage('ایدی اشتباه است')],
|
||||||
param('id').notEmpty().isMongoId().withMessage('ایدی اشتباه است')
|
|
||||||
],
|
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const data = await Device.findById(req.params.id).sort({ created_at: -1 })
|
const data = await Device.findById(req.params.id).sort({ created_at: -1 })
|
||||||
@@ -111,14 +106,11 @@ module.exports.getOne = [
|
|||||||
} else {
|
} else {
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
module.exports.getOneByIMEI = [
|
module.exports.getOneByIMEI = [
|
||||||
[
|
[param('imei').notEmpty().isString().withMessage('ایدی اشتباه است')],
|
||||||
param('imei').notEmpty().isString().withMessage('ایدی اشتباه است')
|
|
||||||
],
|
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const data = await Device.findOne({ IMEI: req.params.imei }).sort({ created_at: -1 })
|
const data = await Device.findOne({ IMEI: req.params.imei }).sort({ created_at: -1 })
|
||||||
@@ -127,57 +119,60 @@ module.exports.getOneByIMEI = [
|
|||||||
} else {
|
} else {
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports.updateDevice = [
|
module.exports.updateDevice = [
|
||||||
[
|
[
|
||||||
param('id').notEmpty().isMongoId().withMessage('ایدی اشتباه است').custom(async (v) => {
|
param('id')
|
||||||
|
.notEmpty()
|
||||||
|
.isMongoId()
|
||||||
|
.withMessage('ایدی اشتباه است')
|
||||||
|
.custom(async v => {
|
||||||
const device = await Device.findById(v)
|
const device = await Device.findById(v)
|
||||||
if (device) {
|
if (device) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(_sr.fa.not_found.item_id)
|
return Promise.reject(_sr.fa.not_found.item_id)
|
||||||
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
|
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
|
||||||
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage("قیمت دستگاه را به تومتن وارد کنید"),
|
body('tomanPrice').notEmpty().isInt({ min: 0 }).withMessage('قیمت دستگاه را به تومتن وارد کنید'),
|
||||||
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage("سود نصاب را به دلار وارد کنید"),
|
body('dollarProfit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به دلار وارد کنید'),
|
||||||
body('profit').notEmpty().isInt({ min: 0 }).withMessage("سود نصاب را به تومان وارد کنید"),
|
body('profit').notEmpty().isInt({ min: 0 }).withMessage('سود نصاب را به تومان وارد کنید'),
|
||||||
body('score').notEmpty().isInt({ min: 0 }).withMessage("امتیاز دریافتی نصاب را وارد کنید"),
|
body('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
|
||||||
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage("سود دریافتی نصاب را از تمدید اشتراک وارد کنید"),
|
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
|
||||||
|
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const { model, tomanPrice, dollarProfit, profit, score, renewalProfit } = req.body;
|
const { model, tomanPrice, dollarProfit, profit, score, renewalProfit } = req.body
|
||||||
const data = await Device.findByIdAndUpdate(
|
const data = await Device.findByIdAndUpdate(
|
||||||
req.params.id,
|
req.params.id,
|
||||||
{
|
{
|
||||||
model, tomanPrice, dollarProfit, profit, score, renewalProfit
|
model,
|
||||||
|
tomanPrice,
|
||||||
|
dollarProfit,
|
||||||
|
profit,
|
||||||
|
score,
|
||||||
|
renewalProfit
|
||||||
},
|
},
|
||||||
{ new: true }
|
{ new: true }
|
||||||
)
|
)
|
||||||
// res.status(200).json({ msg: _sr.fa.response.success_save, data })
|
// res.status(200).json({ msg: _sr.fa.response.success_save, data })
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const creator = exel => {
|
||||||
const creator = (exel) => {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
for (const row of exel) {
|
for (const row of exel) {
|
||||||
|
console.log(row)
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
if (/^[0-9]{15}$/gm.test(row[0].toString().trim())) {
|
if (/^[0-9]{15}$/gm.test(row?.[0]?.toString()?.trim())) {
|
||||||
const device = await Device.findOne({ IMEI: row[0].trim() })
|
const device = await Device.findOne({ IMEI: row?.[0]?.toString()?.trim() })
|
||||||
if (device) {
|
if (device) {
|
||||||
console.info("Repeated IMEI ", row[0])
|
console.info('Repeated IMEI ', row[0])
|
||||||
|
|
||||||
device.model = row[1]
|
device.model = row[1]
|
||||||
device.tomanPrice = row[2]
|
device.tomanPrice = row[2]
|
||||||
@@ -187,26 +182,23 @@ const creator = (exel) => {
|
|||||||
device.renewalProfit = row[6] || 1
|
device.renewalProfit = row[6] || 1
|
||||||
device.save()
|
device.save()
|
||||||
} else {
|
} else {
|
||||||
await Device.create(
|
await Device.create({
|
||||||
{
|
IMEI: row[0].toString().trim(),
|
||||||
IMEI: row[0].trim(),
|
|
||||||
model: row[1],
|
model: row[1],
|
||||||
tomanPrice: row[2],
|
tomanPrice: row[2],
|
||||||
dollarProfit: row[3] || 1,
|
dollarProfit: row[3] || 1,
|
||||||
profit: row[4] || 1,
|
profit: row[4] || 1,
|
||||||
score: row[5] || 1,
|
score: row[5] || 1,
|
||||||
renewalProfit: row[6] || 1
|
renewalProfit: row[6] || 1
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.warn("Wrong IMEI ", row[0])
|
console.warn('Wrong IMEI ', row[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve("end")
|
resolve('end')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error.message)
|
reject(error.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
const { body, param, validationResult } = require('express-validator');
|
const { body, param, validationResult } = require('express-validator')
|
||||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||||
const User = require('../models/GPS.User');
|
const User = require('../models/GPS.User')
|
||||||
const InstalledDevice = require('../models/GPS.InstalledDevice');
|
const InstalledDevice = require('../models/GPS.InstalledDevice')
|
||||||
const Device = require('../models/GPS.Device');
|
const Device = require('../models/GPS.Device')
|
||||||
const Score = require('../models/GPS.Score');
|
const Score = require('../models/GPS.Score')
|
||||||
const { _sr } = require('../plugins/serverResponses');
|
const { _sr } = require('../plugins/serverResponses')
|
||||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
|
|
||||||
module.exports.deviceRegistration = [
|
module.exports.deviceRegistration = [
|
||||||
[
|
[body('IMEI').notEmpty().isString().withMessage('لطفا IMEI را وارد یا تصحیح کنید')],
|
||||||
body('IMEI').notEmpty().isString().withMessage('لطفا IMEI را وارد یا تصحیح کنید')
|
|
||||||
],
|
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const device = await Device.findOne({ IMEI: req.body.IMEI });
|
const device = await Device.findOne({ IMEI: req.body.IMEI })
|
||||||
if (!device) {
|
if (!device) {
|
||||||
throw res.status(404).json({ msg: 'این IMEI وجود ندارد' })
|
throw res.status(404).json({ msg: 'این IMEI وجود ندارد' })
|
||||||
// eslint-disable-next-line eqeqeq
|
// eslint-disable-next-line eqeqeq
|
||||||
} else if (device.status == 1 || device.status == 0) {
|
} else if (device.status == 1) {
|
||||||
throw res.status(404).json({ msg: 'این IMEI قبلا ثبت شده' })
|
throw res.status(404).json({ msg: 'این IMEI قبلا ثبت شده' })
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const data = {
|
const data = {
|
||||||
deviceId: device.id,
|
deviceId: device.id,
|
||||||
@@ -28,77 +25,69 @@ module.exports.deviceRegistration = [
|
|||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
IMEI: req.body.IMEI
|
IMEI: req.body.IMEI
|
||||||
}
|
}
|
||||||
const newRequest = await InstalledDevice.create(data);
|
const newRequest = await InstalledDevice.create(data)
|
||||||
device.status = 1;
|
device.status = 1
|
||||||
device.save()
|
device.save()
|
||||||
notifyAdmin('newInstallDeviceRequest')
|
notifyAdmin('newInstallDeviceRequest')
|
||||||
|
|
||||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data: newRequest })
|
// res.status(201).json({ msg: _sr.fa.response.success_save, data: newRequest })
|
||||||
res.status(201).json(newRequest)
|
res.status(201).json(newRequest)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
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 || req.query.page <= 1) {
|
if (!req.query?.page || req.query.page <= 1) {
|
||||||
page = 0;
|
page = 0
|
||||||
} else {
|
} else {
|
||||||
page = (req.query.page - 1) * rows;
|
page = (req.query.page - 1) * rows
|
||||||
}
|
}
|
||||||
|
|
||||||
const search = req.query?.search || null;
|
const search = req.query?.search || null
|
||||||
|
|
||||||
let sort = {};
|
let sort = {}
|
||||||
|
|
||||||
if (req.query?.deviceId_dollarProfit) {
|
if (req.query?.deviceId_dollarProfit) {
|
||||||
sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit);
|
sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit)
|
||||||
}
|
}
|
||||||
if (req.query?.status) {
|
if (req.query?.status) {
|
||||||
sort.status = parseInt(req.query.status);
|
sort.status = parseInt(req.query.status)
|
||||||
}
|
}
|
||||||
if (req.query?.registerDate) {
|
if (req.query?.registerDate) {
|
||||||
sort.registerDate = parseInt(req.query.registerDate);
|
sort.registerDate = parseInt(req.query.registerDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(sort).length === 0) {
|
if (Object.keys(sort).length === 0) {
|
||||||
sort = { 'created_at': -1 };
|
sort = { created_at: -1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
userId: req.user_id,
|
userId: req.user_id
|
||||||
};
|
}
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
filter.$or = [
|
filter.$or = [{ IMEI: { $regex: search, $options: 'i' } }]
|
||||||
{ IMEI: { $regex: search, $options: 'i' } },
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await InstalledDevice.find(filter)
|
const data = await InstalledDevice.find(filter).skip(page).limit(rows).sort(sort).populate('deviceId')
|
||||||
.skip(page)
|
|
||||||
.limit(rows)
|
|
||||||
.sort(sort)
|
|
||||||
.populate('deviceId');
|
|
||||||
|
|
||||||
const total = await InstalledDevice.countDocuments(filter);
|
const total = await InstalledDevice.countDocuments(filter)
|
||||||
|
|
||||||
res.status(200).json({ data, total });
|
res.status(200).json({ data, total })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ message: 'An error occurred', error });
|
res.status(500).json({ message: 'An error occurred', error })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.getAllForAdmin = async (req, res) => {
|
module.exports.getAllForAdmin = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -129,19 +118,17 @@ module.exports.getAllForAdmin = async (req, res) => {
|
|||||||
// const totalDocuments = await InstalledDevice.countDocuments(filter);
|
// const totalDocuments = await InstalledDevice.countDocuments(filter);
|
||||||
// const totalPages = Math.ceil(totalDocuments / rows);
|
// const totalPages = Math.ceil(totalDocuments / rows);
|
||||||
|
|
||||||
res.status(200).json({ data });
|
res.status(200).json({ data })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error.message);
|
console.error('Error:', error.message)
|
||||||
res.status(500).json({ message: "Server Error", error: error.message });
|
res.status(500).json({ message: 'Server Error', error: error.message })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports.updateInstalled = [
|
module.exports.updateInstalled = [
|
||||||
[
|
[
|
||||||
param('id').notEmpty().isMongoId().withMessage('لطفا ایدی را وارد یا تصحیح کنید'),
|
param('id').notEmpty().isMongoId().withMessage('لطفا ایدی را وارد یا تصحیح کنید'),
|
||||||
param('type').notEmpty().isString().withMessage('لطفا وضعیت را وارد یا تصحیح کنید'),
|
param('type').notEmpty().isString().withMessage('لطفا وضعیت را وارد یا تصحیح کنید')
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
@@ -152,18 +139,17 @@ module.exports.updateInstalled = [
|
|||||||
const user = await User.findById(installedDevice.userId).select('walletBalance dollarBalance score')
|
const user = await User.findById(installedDevice.userId).select('walletBalance dollarBalance score')
|
||||||
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
|
||||||
user.dollarBalance += device.dollarProfit
|
user.dollarBalance += device.dollarProfit
|
||||||
user.score += device.score
|
user.score += device.score
|
||||||
|
|
||||||
|
|
||||||
await Score.create({
|
await Score.create({
|
||||||
title: "ثبت دستگاه",
|
title: 'ثبت دستگاه',
|
||||||
deviceId: device.id,
|
deviceId: device.id,
|
||||||
score: device.score,
|
score: device.score,
|
||||||
userId: installedDevice.userId
|
userId: installedDevice.userId
|
||||||
@@ -175,27 +161,24 @@ module.exports.updateInstalled = [
|
|||||||
|
|
||||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||||
|
|
||||||
|
break
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "reject": {
|
case 'reject': {
|
||||||
installedDevice.status = 2;
|
installedDevice.status = 2
|
||||||
installedDevice.save()
|
installedDevice.save()
|
||||||
device.status = 0;
|
device.status = 0
|
||||||
device.save()
|
device.save()
|
||||||
notifyAdmin('newInstallDeviceRequest')
|
notifyAdmin('newInstallDeviceRequest')
|
||||||
|
|
||||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||||
|
|
||||||
|
break
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
res.status(404).json({ msg: "وضعیت اشتباه است" })
|
res.status(404).json({ msg: 'وضعیت اشتباه است' })
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ const {
|
|||||||
const _faSr = _sr.fa
|
const _faSr = _sr.fa
|
||||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sendConfirmationSMS(userId) {
|
function sendConfirmationSMS(userId) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
@@ -31,11 +29,7 @@ function sendConfirmationSMS(userId) {
|
|||||||
user.otp = mobileKey
|
user.otp = mobileKey
|
||||||
await user.save()
|
await user.save()
|
||||||
|
|
||||||
const smsMsg = [
|
const smsMsg = ['این شماره در وبسایت آسان سرویس ثبت گردیده.', ' کد تایید شماره همراه: ', mobileKey]
|
||||||
'این شماره در وبسایت آسان سرویس ثبت گردیده.',
|
|
||||||
' کد تایید شماره همراه: ',
|
|
||||||
mobileKey
|
|
||||||
]
|
|
||||||
|
|
||||||
await SMS([user.mobile_number], smsMsg.join(''))
|
await SMS([user.mobile_number], smsMsg.join(''))
|
||||||
|
|
||||||
@@ -96,10 +90,7 @@ module.exports.register_user = [
|
|||||||
|
|
||||||
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
||||||
|
|
||||||
body('shopName')
|
body('shopName').notEmpty().withMessage(_faSr.required.address),
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.address),
|
|
||||||
|
|
||||||
|
|
||||||
body('mobile_number')
|
body('mobile_number')
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
@@ -134,16 +125,8 @@ module.exports.register_user = [
|
|||||||
const provinceId = uid.v4()
|
const provinceId = uid.v4()
|
||||||
const cityId = uid.v4()
|
const cityId = uid.v4()
|
||||||
|
|
||||||
const {
|
const { first_name, last_name, national_code, province_name, city_name, mobile_number, password, shopName } =
|
||||||
first_name,
|
req.body
|
||||||
last_name,
|
|
||||||
national_code,
|
|
||||||
province_name,
|
|
||||||
city_name,
|
|
||||||
mobile_number,
|
|
||||||
password,
|
|
||||||
shopName
|
|
||||||
} = req.body
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
last_name,
|
last_name,
|
||||||
@@ -155,7 +138,6 @@ module.exports.register_user = [
|
|||||||
data.national_code = national_code.trim()
|
data.national_code = national_code.trim()
|
||||||
data.mobile_number = normalizeMobileNumber(mobile_number)
|
data.mobile_number = normalizeMobileNumber(mobile_number)
|
||||||
|
|
||||||
|
|
||||||
// hash user password and done
|
// hash user password and done
|
||||||
const salt = await bcrypt.genSalt(10)
|
const salt = await bcrypt.genSalt(10)
|
||||||
const hash = await bcrypt.hash(password, salt)
|
const hash = await bcrypt.hash(password, salt)
|
||||||
@@ -173,7 +155,6 @@ module.exports.register_user = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
module.exports.update_user = [
|
module.exports.update_user = [
|
||||||
[
|
[
|
||||||
body('first_name')
|
body('first_name')
|
||||||
@@ -205,34 +186,17 @@ module.exports.update_user = [
|
|||||||
|
|
||||||
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
||||||
|
|
||||||
body('shopName')
|
body('shopName').notEmpty().withMessage(_faSr.required.field),
|
||||||
.notEmpty()
|
body('address').notEmpty().withMessage(_faSr.required.address),
|
||||||
.withMessage(_faSr.required.field),
|
|
||||||
body('address')
|
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.address),
|
|
||||||
|
|
||||||
body('cell_number')
|
body('cell_number').notEmpty().withMessage(_faSr.required.address),
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.address),
|
|
||||||
|
|
||||||
body('birthDate')
|
body('birthDate').notEmpty().withMessage(_faSr.required.address)
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.address),
|
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {
|
const { first_name, last_name, province_name, city_name, shopName, birthDate, address, cell_number } = req.body
|
||||||
first_name,
|
|
||||||
last_name,
|
|
||||||
province_name,
|
|
||||||
city_name,
|
|
||||||
shopName,
|
|
||||||
birthDate,
|
|
||||||
address,
|
|
||||||
cell_number
|
|
||||||
} = req.body
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
last_name,
|
last_name,
|
||||||
@@ -250,10 +214,7 @@ module.exports.update_user = [
|
|||||||
data.profilePic = `/uploads/images/${fileName}`
|
data.profilePic = `/uploads/images/${fileName}`
|
||||||
}
|
}
|
||||||
data.first_name = nameOptimizer(first_name)
|
data.first_name = nameOptimizer(first_name)
|
||||||
await User.findByIdAndUpdate(
|
await User.findByIdAndUpdate(req.params.id, data)
|
||||||
req.params.id,
|
|
||||||
data
|
|
||||||
)
|
|
||||||
const user = await User.findById(req.params.id)
|
const user = await User.findById(req.params.id)
|
||||||
return res.json({ message: _faSr.response.success_save, user })
|
return res.json({ message: _faSr.response.success_save, user })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -272,9 +233,7 @@ module.exports.update_user_password = [
|
|||||||
if (value === req.body.password_confirmation) return true
|
if (value === req.body.password_confirmation) return true
|
||||||
else return Promise.reject(_faSr.response.passwords_not_match)
|
else return Promise.reject(_faSr.response.passwords_not_match)
|
||||||
}),
|
}),
|
||||||
body('password')
|
body('password').isLength({ min: 4 }).withMessage(_faSr.min_char.min4)
|
||||||
.isLength({ min: 4 })
|
|
||||||
.withMessage(_faSr.min_char.min4)
|
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
@@ -303,11 +262,7 @@ module.exports.update_user_password = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
module.exports.send_otp = [
|
module.exports.send_otp = [
|
||||||
[
|
[body('mobile_number').notEmpty().withMessage(_faSr.required.phone_number)],
|
||||||
body('mobile_number')
|
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.phone_number)
|
|
||||||
],
|
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
try {
|
try {
|
||||||
@@ -318,7 +273,7 @@ module.exports.send_otp = [
|
|||||||
throw new Error(_sr.fa.not_found.user_id)
|
throw new Error(_sr.fa.not_found.user_id)
|
||||||
}
|
}
|
||||||
await sendConfirmationSMS(user.id)
|
await sendConfirmationSMS(user.id)
|
||||||
res.status(200).json({ msg: "ok" })
|
res.status(200).json({ msg: 'ok' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err.message)
|
throw new Error(err.message)
|
||||||
}
|
}
|
||||||
@@ -327,12 +282,8 @@ module.exports.send_otp = [
|
|||||||
|
|
||||||
module.exports.check_otp = [
|
module.exports.check_otp = [
|
||||||
[
|
[
|
||||||
body('mobile_number')
|
body('mobile_number').notEmpty().withMessage(_faSr.required.phone_number),
|
||||||
.notEmpty()
|
body('otp').notEmpty().withMessage(_faSr.required.phone_number)
|
||||||
.withMessage(_faSr.required.phone_number),
|
|
||||||
body('otp')
|
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.phone_number)
|
|
||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
@@ -340,8 +291,8 @@ module.exports.check_otp = [
|
|||||||
const { mobile_number, otp } = req.body
|
const { mobile_number, otp } = req.body
|
||||||
const user = await User.findOne({ mobile_number })
|
const user = await User.findOne({ mobile_number })
|
||||||
if (!user) throw new Error(_sr.fa.not_found.user_id)
|
if (!user) throw new Error(_sr.fa.not_found.user_id)
|
||||||
if (user.otp !== otp) throw new Error("کد اشتباه است")
|
if (user.otp !== otp) throw new Error('کد اشتباه است')
|
||||||
if (user.otp === otp) res.status(200).json({ msg: "ok" })
|
if (user.otp === otp) res.status(200).json({ msg: 'ok' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err.message)
|
throw new Error(err.message)
|
||||||
}
|
}
|
||||||
@@ -350,12 +301,8 @@ module.exports.check_otp = [
|
|||||||
|
|
||||||
module.exports.resetpass_otp = [
|
module.exports.resetpass_otp = [
|
||||||
[
|
[
|
||||||
body('mobile_number')
|
body('mobile_number').notEmpty().withMessage(_faSr.required.phone_number),
|
||||||
.notEmpty()
|
body('otp').notEmpty().withMessage(_faSr.required.phone_number),
|
||||||
.withMessage(_faSr.required.phone_number),
|
|
||||||
body('otp')
|
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.phone_number),
|
|
||||||
body('password')
|
body('password')
|
||||||
.isLength({ min: 4 })
|
.isLength({ min: 4 })
|
||||||
.withMessage(_faSr.min_char.min4)
|
.withMessage(_faSr.min_char.min4)
|
||||||
@@ -372,7 +319,7 @@ module.exports.resetpass_otp = [
|
|||||||
const hash = await bcrypt.hash(password, salt)
|
const hash = await bcrypt.hash(password, salt)
|
||||||
const user = await User.findOne({ mobile_number })
|
const user = await User.findOne({ mobile_number })
|
||||||
if (!user) throw new Error(_sr.fa.not_found.user_id)
|
if (!user) throw new Error(_sr.fa.not_found.user_id)
|
||||||
if (user.otp !== otp) throw new Error("کد اشتباه است")
|
if (user.otp !== otp) throw new Error('کد اشتباه است')
|
||||||
if (user.otp === otp) {
|
if (user.otp === otp) {
|
||||||
user.password = hash
|
user.password = hash
|
||||||
user.otp = generateRandomDigits(6)
|
user.otp = generateRandomDigits(6)
|
||||||
@@ -392,11 +339,15 @@ module.exports.getCurrent = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getUsersForAdmin = async (req, res) => {
|
module.exports.getUsersForAdmin = async (req, res) => {
|
||||||
const user = await User.find({}).sort({ active: 1, created_at: -1 }).select('-password -token -otp -seenByAdmin -cardBank')
|
const user = await User.find({})
|
||||||
|
.sort({ active: 1, created_at: -1 })
|
||||||
|
.select('-password -token -otp -seenByAdmin -cardBank')
|
||||||
res.status(200).json(user)
|
res.status(200).json(user)
|
||||||
}
|
}
|
||||||
module.exports.getPendingUsersForAdmin = async (req, res) => {
|
module.exports.getPendingUsersForAdmin = async (req, res) => {
|
||||||
const user = await User.find({ active: false }).sort({ active: 1, created_at: -1 }).select('-password -token -otp -seenByAdmin -cardBank')
|
const user = await User.find({ active: false })
|
||||||
|
.sort({ active: 1, created_at: -1 })
|
||||||
|
.select('-password -token -otp -seenByAdmin -cardBank')
|
||||||
res.status(200).json(user)
|
res.status(200).json(user)
|
||||||
}
|
}
|
||||||
module.exports.getUserForAdmin = async (req, res) => {
|
module.exports.getUserForAdmin = async (req, res) => {
|
||||||
@@ -417,17 +368,18 @@ module.exports.activeUser = [
|
|||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
const data = await User.findByIdAndUpdate(req.params.id,
|
const data = await User.findByIdAndUpdate(
|
||||||
|
req.params.id,
|
||||||
{
|
{
|
||||||
active: req.params.status
|
active: req.params.status
|
||||||
},
|
},
|
||||||
{ new: true }).select('-password -token -otp -seenByAdmin')
|
{ new: true }
|
||||||
|
).select('-password -token -otp -seenByAdmin')
|
||||||
if (!data) return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
if (!data) return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
||||||
|
|
||||||
notifyAdmin('pendingUsers')
|
notifyAdmin('pendingUsers')
|
||||||
|
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -481,10 +433,7 @@ module.exports.addUserByAdmin = [
|
|||||||
|
|
||||||
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
body('city_name').notEmpty().withMessage(_faSr.required.city),
|
||||||
|
|
||||||
body('shopName')
|
body('shopName').notEmpty().withMessage(_faSr.required.address),
|
||||||
.notEmpty()
|
|
||||||
.withMessage(_faSr.required.address),
|
|
||||||
|
|
||||||
|
|
||||||
body('mobile_number')
|
body('mobile_number')
|
||||||
.notEmpty()
|
.notEmpty()
|
||||||
@@ -519,16 +468,8 @@ module.exports.addUserByAdmin = [
|
|||||||
const provinceId = uid.v4()
|
const provinceId = uid.v4()
|
||||||
const cityId = uid.v4()
|
const cityId = uid.v4()
|
||||||
|
|
||||||
const {
|
const { first_name, last_name, national_code, province_name, city_name, mobile_number, password, shopName } =
|
||||||
first_name,
|
req.body
|
||||||
last_name,
|
|
||||||
national_code,
|
|
||||||
province_name,
|
|
||||||
city_name,
|
|
||||||
mobile_number,
|
|
||||||
password,
|
|
||||||
shopName
|
|
||||||
} = req.body
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
last_name,
|
last_name,
|
||||||
@@ -541,7 +482,6 @@ module.exports.addUserByAdmin = [
|
|||||||
data.national_code = national_code.trim()
|
data.national_code = national_code.trim()
|
||||||
data.mobile_number = normalizeMobileNumber(mobile_number)
|
data.mobile_number = normalizeMobileNumber(mobile_number)
|
||||||
|
|
||||||
|
|
||||||
// hash user password and done
|
// hash user password and done
|
||||||
const salt = await bcrypt.genSalt(10)
|
const salt = await bcrypt.genSalt(10)
|
||||||
const hash = await bcrypt.hash(password, salt)
|
const hash = await bcrypt.hash(password, salt)
|
||||||
@@ -550,7 +490,6 @@ module.exports.addUserByAdmin = [
|
|||||||
const user = new User(data)
|
const user = new User(data)
|
||||||
await user.save()
|
await user.save()
|
||||||
|
|
||||||
|
|
||||||
return res.status(200).json({ message: _faSr.response.success_save })
|
return res.status(200).json({ message: _faSr.response.success_save })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const registerFailurMsg = 'مشکلی در ثبت نام پیش آمده، لطفا مجددا تلاش کنید'
|
const registerFailurMsg = 'مشکلی در ثبت نام پیش آمده، لطفا مجددا تلاش کنید'
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ module.exports._sr = {
|
|||||||
province: 'استان را وارد کنید',
|
province: 'استان را وارد کنید',
|
||||||
city: 'شهر را وارد کنید',
|
city: 'شهر را وارد کنید',
|
||||||
address: 'آدرس را وارد کنید',
|
address: 'آدرس را وارد کنید',
|
||||||
|
iban: 'شماره شبا را وارد کنید',
|
||||||
postal_code: 'کد پستی را وارد کنید',
|
postal_code: 'کد پستی را وارد کنید',
|
||||||
plaque: 'پلاک را وارد کنید',
|
plaque: 'پلاک را وارد کنید',
|
||||||
receiver_first_name: 'نام گیرنده را وارد کنید',
|
receiver_first_name: 'نام گیرنده را وارد کنید',
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ router.get('/renew', renewal.findAllUser)
|
|||||||
router.get('/notif/:id', notif.setSeen)
|
router.get('/notif/:id', notif.setSeen)
|
||||||
router.get('/notif', notif.setSeenAll)
|
router.get('/notif', notif.setSeenAll)
|
||||||
|
|
||||||
|
|
||||||
/// /////////////// User
|
/// /////////////// User
|
||||||
router.get('/user/me', userGPS.getCurrent)
|
router.get('/user/me', userGPS.getCurrent)
|
||||||
router.put('/user/me/:id', userGPS.update_user)
|
router.put('/user/me/:id', userGPS.update_user)
|
||||||
@@ -28,7 +27,6 @@ router.post('/user/reset-pass', userGPS.update_user_password)
|
|||||||
router.get('/overview/main', overview.mainPage)
|
router.get('/overview/main', overview.mainPage)
|
||||||
router.get('/overview/wallet', overview.walletPage)
|
router.get('/overview/wallet', overview.walletPage)
|
||||||
|
|
||||||
|
|
||||||
/// ////////////// Award request
|
/// ////////////// Award request
|
||||||
router.post('/award-request', awardRequest.sendRequest)
|
router.post('/award-request', awardRequest.sendRequest)
|
||||||
router.get('/award-request', awardRequest.findAllUser)
|
router.get('/award-request', awardRequest.findAllUser)
|
||||||
@@ -39,6 +37,8 @@ router.get('/award', award.findAllUser)
|
|||||||
/// ///////////////// Bank card
|
/// ///////////////// Bank card
|
||||||
router.post('/bank-card', bankAccount.addCard)
|
router.post('/bank-card', bankAccount.addCard)
|
||||||
router.get('/bank-card', bankAccount.getAll)
|
router.get('/bank-card', bankAccount.getAll)
|
||||||
|
router.get('/bank-card/:id', bankAccount.getOne)
|
||||||
|
router.put('/bank-card/:id', bankAccount.updateCard)
|
||||||
router.delete('/bank-card/:id', bankAccount.deleteCard)
|
router.delete('/bank-card/:id', bankAccount.deleteCard)
|
||||||
/// ///////////////// Withdraw request
|
/// ///////////////// Withdraw request
|
||||||
router.post('/withdraw', withdraw.createRequest)
|
router.post('/withdraw', withdraw.createRequest)
|
||||||
|
|||||||
Reference in New Issue
Block a user