diff --git a/components/admin/TheFooter.vue b/components/admin/TheFooter.vue
index 43167a2..f73948a 100644
--- a/components/admin/TheFooter.vue
+++ b/components/admin/TheFooter.vue
@@ -2,7 +2,7 @@
@@ -12,3 +12,9 @@ export default {
name: 'TheFooter'
}
+
+
diff --git a/pages/admin/gps/device/index.vue b/pages/admin/gps/device/index.vue
index 5deca4f..19ccc05 100644
--- a/pages/admin/gps/device/index.vue
+++ b/pages/admin/gps/device/index.vue
@@ -2,9 +2,7 @@
دستگاه ها
- خروجی اکسل
+ خروجی اکسل
@@ -19,13 +17,14 @@
افزودن
- دستور عمل
+ دستور عمل
- برای اضافه کردن دستگاه جدید فقط کافی است فایل نمونه رو دانلود کنید و به ترتیب مقادیر رو وارد کنید .
-
- برای به روزرسانی یک دستگاه به صورت تکی یا عمده داخل فایل نمونه IMEI را قرار داده و مقادیر جدید آن را ثبت کنید و آپلود کنید
-
+ برای اضافه کردن دستگاه جدید فقط کافی است فایل نمونه رو دانلود کنید و به ترتیب مقادیر رو وارد کنید .
+
+ برای به روزرسانی یک دستگاه به صورت تکی یا عمده داخل فایل نمونه IMEI را قرار داده و مقادیر جدید آن را
+ ثبت کنید و آپلود کنید
+
دستگاه ها
-
@@ -83,7 +81,7 @@
-
+
@@ -166,11 +164,9 @@ export default {
else console.log(err)
})
},
- async download(){
- const x = await this.$axios
- .get('/api/admin/gps/device/exel')
- FileDownload(x.data, 'device.csv');
-
+ async download() {
+ const x = await this.$axios.get('/api/admin/gps/device/exel')
+ FileDownload(x.data, 'device.csv')
}
}
}
diff --git a/pages/admin/gps/installed-device/index.vue b/pages/admin/gps/installed-device/index.vue
index 94e0a0e..edb1882 100644
--- a/pages/admin/gps/installed-device/index.vue
+++ b/pages/admin/gps/installed-device/index.vue
@@ -24,10 +24,7 @@
رد شده
- تایید شده
- {{ scope.row.deviceId.model }}
+ {{ scope?.row?.deviceId?.model }}
- {{ scope.row.userId.shopName }}
+ {{ scope?.row?.userId?.shopName }}
- {{ scope.row.userId.national_code }}
+ {{ scope?.row?.userId?.national_code }}
- {{ scope.row.userId.first_name + " " + scope.row.userId.last_name }}
+ {{ scope?.row?.userId?.first_name + ' ' + scope?.row?.userId?.last_name }}
- {{ scope.row.userId.mobile_number }}
+ {{ scope?.row?.userId?.mobile_number }}
- {{ scope.row.userId.province_name + ", "+ scope.row.userId.city_name }}
+ {{ scope?.row?.userId?.province_name + ', ' + scope?.row?.userId?.city_name }}
- رد شده
- تایید شده
+ رد شده
+ تایید شده
- درانتظار تایید
+ درانتظار تایید
@@ -155,8 +152,7 @@ export default {
devices: [],
device: {},
- filterText: '',
-
+ filterText: ''
}
},
diff --git a/pages/admin/gps/withdraw/index.vue b/pages/admin/gps/withdraw/index.vue
index 49e98c6..d1683c2 100644
--- a/pages/admin/gps/withdraw/index.vue
+++ b/pages/admin/gps/withdraw/index.vue
@@ -10,7 +10,9 @@
{{ requestData.userId?.city_name }}
{{ requestData.userId?.national_code }}
{{ requestData.userId?.shopName }}
- {{ requestData.trackingNumber }}
+ {{
+ requestData.trackingNumber
+ }}
@@ -29,9 +31,12 @@
>
@@ -102,7 +107,7 @@
{{ scope.row.amount }}
-
+
@@ -195,10 +200,12 @@ export default {
if (!this.filterText.length) return filterUsersByType
else {
return this.requestsData.filter(item => {
- return item.userId.mobile_number.includes(filterText) ||
- item.userId.national_code.includes(filterText) ||
- item.userId.last_name.includes(filterText) ||
- item.userId.first_name.includes(filterText)
+ return (
+ item.userId.mobile_number.includes(filterText) ||
+ item.userId.national_code.includes(filterText) ||
+ item.userId.last_name.includes(filterText) ||
+ item.userId.first_name.includes(filterText)
+ )
})
}
},
diff --git a/server/controllers/GPS.Device.js b/server/controllers/GPS.Device.js
index b0feb29..72cb078 100644
--- a/server/controllers/GPS.Device.js
+++ b/server/controllers/GPS.Device.js
@@ -21,7 +21,7 @@ module.exports.addCode = [
}
}),
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('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
@@ -68,7 +68,7 @@ module.exports.downloadAll = [
{ label: 'IMEI', value: 'IMEI' },
{ label: 'مدل', value: 'model' },
{ label: 'قیمت به تومان', value: 'tomanPrice' },
- { label: 'سود به دلار', value: 'dollarProfit' },
+ // { label: 'سود به دلار', value: 'dollarProfit' },
{ label: 'سود به تومان', value: 'profit' },
{ label: 'امتیاز', value: 'score' },
{ label: 'سود از تمدید', value: 'renewalProfit' },
@@ -138,20 +138,20 @@ module.exports.updateDevice = [
}),
body('model').notEmpty().isString().withMessage(_sr.fa.required.name),
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('score').notEmpty().isInt({ min: 0 }).withMessage('امتیاز دریافتی نصاب را وارد کنید'),
body('renewalProfit').notEmpty().isInt({ min: 0 }).withMessage('سود دریافتی نصاب را از تمدید اشتراک وارد کنید')
],
checkValidations(validationResult),
async (req, res) => {
- const { model, tomanPrice, dollarProfit, profit, score, renewalProfit } = req.body
+ const { model, tomanPrice, profit, score, renewalProfit } = req.body
const data = await Device.findByIdAndUpdate(
req.params.id,
{
model,
tomanPrice,
- dollarProfit,
+ // dollarProfit,
profit,
score,
renewalProfit
@@ -176,20 +176,20 @@ const creator = exel => {
device.model = row[1]
device.tomanPrice = row[2]
- device.dollarProfit = row[3] || 1
- device.profit = row[4] || 1
- device.score = row[5] || 1
- device.renewalProfit = row[6] || 1
+ // device.dollarProfit = row[3] || 1
+ device.profit = row[3] || 1
+ device.score = row[4] || 1
+ device.renewalProfit = row[5] || 1
device.save()
} else {
await Device.create({
IMEI: row[0].toString().trim(),
model: row[1],
tomanPrice: row[2],
- dollarProfit: row[3] || 1,
- profit: row[4] || 1,
- score: row[5] || 1,
- renewalProfit: row[6] || 1
+ // dollarProfit: row[3] || 1,
+ profit: row[3] || 1,
+ score: row[4] || 1,
+ renewalProfit: row[5] || 1
})
}
} else {
diff --git a/server/controllers/GPS.InstalledDevice.js b/server/controllers/GPS.InstalledDevice.js
index 85e0876..7be2c13 100644
--- a/server/controllers/GPS.InstalledDevice.js
+++ b/server/controllers/GPS.InstalledDevice.js
@@ -56,9 +56,9 @@ module.exports.getAllForUser = async (req, res) => {
let sort = {}
- if (req.query?.deviceId_dollarProfit) {
- sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit)
- }
+ // if (req.query?.deviceId_dollarProfit) {
+ // sort.dollarProfit = parseInt(req.query.deviceId_dollarProfit)
+ // }
if (req.query?.status) {
sort.status = parseInt(req.query.status)
}
@@ -136,7 +136,7 @@ module.exports.updateInstalled = [
if (!installedDevice) {
throw res.status(404).json({ msg: 'این ایدی وجود ندارد' })
} else {
- const user = await User.findById(installedDevice.userId).select('walletBalance dollarBalance score')
+ const user = await User.findById(installedDevice.userId).select('walletBalance score')
const device = await Device.findById(installedDevice.deviceId)
switch (req.params.type) {
case 'accept': {
@@ -145,7 +145,7 @@ module.exports.updateInstalled = [
device.status = 1
user.walletBalance += device.profit
- user.dollarBalance += device.dollarProfit
+ // user.dollarBalance += device.dollarProfit
user.score += device.score
await Score.create({
diff --git a/server/controllers/GPS.Overview.js b/server/controllers/GPS.Overview.js
index 5155355..b4760da 100644
--- a/server/controllers/GPS.Overview.js
+++ b/server/controllers/GPS.Overview.js
@@ -1,23 +1,22 @@
-const User = require('../models/GPS.User');
-const InstalledDevice = require('../models/GPS.InstalledDevice');
-const Withdraw = require('../models/GPS.Withdraw');
+const User = require('../models/GPS.User')
+const InstalledDevice = require('../models/GPS.InstalledDevice')
+const Withdraw = require('../models/GPS.Withdraw')
-
-module.exports.mainPage = async(req, res)=>{
- const device = await InstalledDevice.countDocuments({userId:req.user_id})
- const user = await User.findById(req.user_id).select('walletBalance dollarBalance score')
- res.status(200).json({installedDevice:device, user})
+module.exports.mainPage = async (req, res) => {
+ const device = await InstalledDevice.countDocuments({ userId: req.user_id })
+ const user = await User.findById(req.user_id).select('walletBalance score')
+ res.status(200).json({ installedDevice: device, user })
}
-module.exports.walletPage = async(req, res)=>{
- const withdraw = await Withdraw.findOne({userId: req.user_id, status:0})
- const user = await User.findById(req.user_id).select('walletBalance dollarBalance score')
- let pending;
-
- if(withdraw){
- pending = true
- }else{
- pending = false
- }
- res.status(200).json({user, pending })
-}
\ No newline at end of file
+module.exports.walletPage = async (req, res) => {
+ const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 })
+ const user = await User.findById(req.user_id).select('walletBalance score')
+ let pending
+
+ if (withdraw) {
+ pending = true
+ } else {
+ pending = false
+ }
+ res.status(200).json({ user, pending })
+}
diff --git a/server/controllers/GPS.Renewal.js b/server/controllers/GPS.Renewal.js
index 5886732..f41064d 100644
--- a/server/controllers/GPS.Renewal.js
+++ b/server/controllers/GPS.Renewal.js
@@ -2,160 +2,146 @@ const { body, validationResult } = require('express-validator')
const { _sr } = require('../plugins/serverResponses')
const { checkValidations } = require('../plugins/controllersHelperFunctions')
const Renewal = require('../models/GPS.Renewal')
-const User = require('../models/GPS.User');
-const Score = require('../models/GPS.Score');
-const InstalledDevice = require('../models/GPS.InstalledDevice');
-
+const User = require('../models/GPS.User')
+const Score = require('../models/GPS.Score')
+const InstalledDevice = require('../models/GPS.InstalledDevice')
module.exports.create = [
- [
- body('IMEI').notEmpty().isString().withMessage(_sr.fa.required.field),
- body('renewDate').notEmpty().withMessage(_sr.fa.required.field),
- body('renewType').notEmpty().withMessage(_sr.fa.required.field),
- body('price').notEmpty().isInt().withMessage(_sr.fa.required.field),
-
- ],
- checkValidations(validationResult),
- async (req, res) => {
- try {
- // eslint-disable-next-line eqeqeq
- const { IMEI, renewDate, renewType, price } = req.body
- const device = await InstalledDevice.findOne({IMEI}).populate('deviceId')
- if(!device){
- res.status(200)
- throw new Error(_sr.fa.response.success_save+1)
- }
- // eslint-disable-next-line eqeqeq
- if(device.status == 1 ){
- const user = await User.findById(device.userId)
- const profit = price *0.05
- const data = {
- renewDate,
- renewType,
- price,
- deviceId:device.deviceId.id,
- IMEI,
- profit,
- userId:device.userId,
- }
- await Renewal.create(data)
- await Score.create({
- title: " تمدید اشتراک",
- deviceId: device.deviceId.id,
- score: device.deviceId.score,
- userId: device.userId
- })
- user.walletBalance += data.profit
- user.score += device.deviceId.score
- user.save()
- res.status(201).json({msg:_sr.fa.response.success_save})
- }else{
- res.status(200)
- throw new Error(_sr.fa.response.success_save+2)
- }
-
-
- } catch (error) {
- res.json({msg:error.message})
+ [
+ body('IMEI').notEmpty().isString().withMessage(_sr.fa.required.field),
+ body('renewDate').notEmpty().withMessage(_sr.fa.required.field),
+ body('renewType').notEmpty().withMessage(_sr.fa.required.field),
+ body('price').notEmpty().isInt().withMessage(_sr.fa.required.field)
+ ],
+ checkValidations(validationResult),
+ async (req, res) => {
+ try {
+ // eslint-disable-next-line eqeqeq
+ const { IMEI, renewDate, renewType, price } = req.body
+ const device = await InstalledDevice.findOne({ IMEI }).populate('deviceId')
+ if (!device) {
+ res.status(200)
+ throw new Error(_sr.fa.response.success_save + 1)
+ }
+ // eslint-disable-next-line eqeqeq
+ if (device.status == 1) {
+ const user = await User.findById(device.userId)
+ const profit = price * 0.05
+ const data = {
+ renewDate,
+ renewType,
+ price,
+ deviceId: device.deviceId.id,
+ IMEI,
+ profit,
+ userId: device.userId
}
-
+ await Renewal.create(data)
+ await Score.create({
+ title: ' تمدید اشتراک',
+ deviceId: device.deviceId.id,
+ score: device.deviceId.score,
+ userId: device.userId
+ })
+ user.walletBalance += data.profit
+ user.score += device.deviceId.score
+ user.save()
+ res.status(201).json({ msg: _sr.fa.response.success_save })
+ } else {
+ res.status(200)
+ throw new Error(_sr.fa.response.success_save + 2)
+ }
+ } catch (error) {
+ res.json({ msg: error.message })
}
+ }
]
-
module.exports.findAllUser = async (req, res) => {
- let page;
- let rows;
+ let page
+ let rows
- if (!req.query?.rows || req.query?.rows <= 5) {
- rows = 10;
- } else {
- rows = parseInt(req.query.rows);
- }
+ if (!req.query?.rows || req.query?.rows <= 5) {
+ rows = 10
+ } else {
+ rows = parseInt(req.query.rows)
+ }
- if (!req.query?.page || req.query.page <= 1) {
- page = 0;
- } else {
- page = (req.query.page - 1) * rows;
- }
+ if (!req.query?.page || req.query.page <= 1) {
+ page = 0
+ } else {
+ 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) {
- 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 (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 };
- }
+ if (Object.keys(sort).length === 0) {
+ sort = { created_at: -1 }
+ }
- const filter = {
- userId: req.user_id,
- };
+ const filter = {
+ userId: req.user_id
+ }
- if (search) {
- filter.$or = [
- { IMEI: { $regex: search, $options: 'i' } },
- ];
- }
+ if (search) {
+ filter.$or = [{ IMEI: { $regex: search, $options: 'i' } }]
+ }
- try {
- const data = await Renewal.find(filter)
- .skip(page)
- .limit(rows)
- .sort(sort)
- .populate('deviceId');
+ try {
+ const data = await Renewal.find(filter).skip(page).limit(rows).sort(sort).populate('deviceId')
- const total = await Renewal.countDocuments(filter);
-
- res.status(200).json({ data, total });
- } catch (error) {
- res.status(500).json({ message: 'An error occurred', error });
- }
+ const total = await Renewal.countDocuments(filter)
+ res.status(200).json({ data, total })
+ } catch (error) {
+ res.status(500).json({ message: 'An error occurred', error })
+ }
}
module.exports.findAllAdmin = async (req, res) => {
- 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;
+ 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;
+ // const skip = (page - 1) * rows;
- // 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 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 Renewal.find()
- // .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 data = await Renewal.find()
+ // .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);
+ // const totalDocuments = await InstalledDevice.countDocuments(filter);
+ // const totalPages = Math.ceil(totalDocuments / rows);
- res.status(200).json({ data });
- } catch (error) {
- console.error('Error:', error.message);
- res.status(500).json({ message: "Server Error", error: error.message });
- }
+ res.status(200).json({ data })
+ } catch (error) {
+ console.error('Error:', error.message)
+ res.status(500).json({ message: 'Server Error', error: error.message })
+ }
}
-
diff --git a/server/controllers/GPS.Withdraw.js b/server/controllers/GPS.Withdraw.js
index e15c73b..89e050f 100644
--- a/server/controllers/GPS.Withdraw.js
+++ b/server/controllers/GPS.Withdraw.js
@@ -1,192 +1,177 @@
-const { body, param, validationResult } = require('express-validator');
-const { _sr } = require('../plugins/serverResponses');
-const { checkValidations } = require('../plugins/controllersHelperFunctions');
-const User = require('../models/GPS.User');
-const Withdraw = require('../models/GPS.Withdraw');
+const { body, param, validationResult } = require('express-validator')
+const { _sr } = require('../plugins/serverResponses')
+const { checkValidations } = require('../plugins/controllersHelperFunctions')
+const User = require('../models/GPS.User')
+const Withdraw = require('../models/GPS.Withdraw')
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
-
module.exports.createRequest = [
- [
- body('card').notEmpty().isObject().withMessage('گارت ورودی خود را انتخاب کنید'),
- ],
- checkValidations(validationResult),
- async (req, res) => {
- try {
- const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 })
- if (withdraw) {
- res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' })
- } else {
- const user = await User.findById(req.user_id)
- if (user.walletBalance < 50000) {
- const data = {
- card: req.body.card,
- userId: req.user_id,
- amount: user.walletBalance,
- dollarAmount: user.dollarBalance,
- status: 0
- }
-
- const request = await Withdraw.create(data)
- user.dollarBalance = 0;
- user.walletBalance = 0;
- user.save()
- // res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
- notifyAdmin('newWithdrawRequest')
- res.status(201).json(request)
- } else {
- res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' })
- }
-
- }
-
- } catch (error) {
- res.status(500).json({ msg: error })
+ [body('card').notEmpty().isObject().withMessage('گارت ورودی خود را انتخاب کنید')],
+ checkValidations(validationResult),
+ async (req, res) => {
+ try {
+ const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 })
+ if (withdraw) {
+ res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' })
+ } else {
+ const user = await User.findById(req.user_id)
+ if (user.walletBalance < 50000) {
+ const data = {
+ card: req.body.card,
+ userId: req.user_id,
+ amount: user.walletBalance,
+ // dollarAmount: user.dollarBalance,
+ status: 0
+ }
+ const request = await Withdraw.create(data)
+ // user.dollarBalance = 0
+ user.walletBalance = 0
+ user.save()
+ // res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
+ notifyAdmin('newWithdrawRequest')
+ res.status(201).json(request)
+ } else {
+ res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' })
}
+ }
+ } catch (error) {
+ res.status(500).json({ msg: error })
}
+ }
]
-
module.exports.getAllForUser = async (req, res) => {
- const rows = (!req.query?.rows || req.query?.rows <= 5) ? 10 : 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;
- }
+ let page = 0
+ if (req.query?.page && req.query.page > 1) {
+ 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?.created_at) {
- sort.created_at = parseInt(req.query.created_at);
- }
+ if (req.query?.created_at) {
+ sort.created_at = parseInt(req.query.created_at)
+ }
- if (req.query?.updated_at) {
- sort.updated_at = parseInt(req.query.updated_at);
- }
+ 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?.amount) {
+ sort.amount = parseInt(req.query.amount)
+ }
- if (req.query?.status) {
- sort.status = parseInt(req.query.status);
- }
+ if (req.query?.status) {
+ sort.status = parseInt(req.query.status)
+ }
- if (Object.keys(sort).length === 0) {
- sort = { created_at: 1 };
- }
+ if (Object.keys(sort).length === 0) {
+ sort = { created_at: 1 }
+ }
- const filter = {
- userId: req.user_id,
- };
+ const filter = {
+ userId: req.user_id
+ }
- if (search) {
- filter.$or = [
- { amount: search },
- { dollarAmount: search },
- { trackingNumber: { $regex: search, $options: 'i' } },
- ];
- }
+ if (search) {
+ filter.$or = [{ amount: 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);
+ try {
+ const data = await Withdraw.find(filter).skip(page).limit(rows).sort(sort)
+ const total = await Withdraw.countDocuments(filter)
- res.status(200).json({ data, total });
- } catch (error) {
- res.status(500).json({ message: 'خطای سرور', error });
- }
-};
-
-module.exports.getAllForAdmin = async (req, res) => {
- 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;
-
- 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 });
- }
+ res.status(200).json({ data, total })
+ } catch (error) {
+ res.status(500).json({ message: 'خطای سرور', error })
+ }
}
+module.exports.getAllForAdmin = async (req, res) => {
+ 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
+
+ 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 })
+ }
+}
module.exports.updateReq = [
- [
- param('id').notEmpty().isMongoId().withMessage('ایدی را باید وارد کنید'),
- param('type').notEmpty().isString().withMessage('وضعیت را باید وارد کنید'),
- ],
- checkValidations(validationResult),
- async (req, res) => {
- const request = await Withdraw.findById(req.params.id)
- if (!request) {
- res.status(404).json({ msg: _sr.fa.not_found.item_id })
- } else {
- switch (req.params.type) {
- case "accept": {
- request.status = 1;
- request.save()
- notifyAdmin('newWithdrawRequest')
+ [
+ param('id').notEmpty().isMongoId().withMessage('ایدی را باید وارد کنید'),
+ param('type').notEmpty().isString().withMessage('وضعیت را باید وارد کنید')
+ ],
+ checkValidations(validationResult),
+ async (req, res) => {
+ const request = await Withdraw.findById(req.params.id)
+ if (!request) {
+ res.status(404).json({ msg: _sr.fa.not_found.item_id })
+ } else {
+ switch (req.params.type) {
+ case 'accept': {
+ request.status = 1
+ request.save()
+ notifyAdmin('newWithdrawRequest')
- res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
+ res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
- break;
- }
- case "deposit": {
- request.status = 2;
- request.depositDate = new Date();
- request.trackingNumber = req.body.trackingNumber || 0;
- request.save()
- notifyAdmin('newWithdrawRequest')
-
- res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
-
- break;
- }
- default: {
- res.status(404).json({ msg: "استاتوس اشتباه است" })
- break;
- }
- }
+ break
}
+ case 'deposit': {
+ request.status = 2
+ request.depositDate = new Date()
+ request.trackingNumber = req.body.trackingNumber || 0
+ request.save()
+ notifyAdmin('newWithdrawRequest')
+
+ res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
+
+ break
+ }
+ default: {
+ res.status(404).json({ msg: 'استاتوس اشتباه است' })
+ break
+ }
+ }
}
+ }
]
-
-
diff --git a/server/models/GPS.Device.js b/server/models/GPS.Device.js
index cb7dbad..920d91e 100644
--- a/server/models/GPS.Device.js
+++ b/server/models/GPS.Device.js
@@ -1,42 +1,42 @@
const mongoose = require('mongoose')
const deviceSchema = mongoose.Schema({
- model: String,
- IMEI: {
- type: String,
- unique: [true, "این ایدی در سامانه موجود است"]
- },
- tomanPrice: {
- type: Number,
- min: 0,
- default: 0
- },
- dollarProfit: {
- type: Number,
- min: 0,
- default: 0
- },
- profit: {
- type: Number,
- min: 0,
- default: 0
- },
- score: {
- type: Number,
- min: 0
- },
- renewalProfit: {
- type: Number,
- min: 0
- },
- status: {
- type: Number,
- enum: [
- 0, // not installed
- 1 // installed
- ],
- default: 0
- }
+ model: String,
+ IMEI: {
+ type: String,
+ unique: [true, 'این ایدی در سامانه موجود است']
+ },
+ tomanPrice: {
+ type: Number,
+ min: 0,
+ default: 0
+ },
+ // dollarProfit: {
+ // type: Number,
+ // min: 0,
+ // default: 0
+ // },
+ profit: {
+ type: Number,
+ min: 0,
+ default: 0
+ },
+ score: {
+ type: Number,
+ min: 0
+ },
+ renewalProfit: {
+ type: Number,
+ min: 0
+ },
+ status: {
+ type: Number,
+ enum: [
+ 0, // not installed
+ 1 // installed
+ ],
+ default: 0
+ }
})
module.exports = mongoose.model('Device', deviceSchema)
diff --git a/server/models/GPS.User.js b/server/models/GPS.User.js
index 082a2de..d6fe946 100644
--- a/server/models/GPS.User.js
+++ b/server/models/GPS.User.js
@@ -1,58 +1,56 @@
const mongoose = require('mongoose')
const BankSchema = mongoose.Schema({
- holderName: String,
- PAN: {
- type: Number,
- },
- IBAN: {
- type: String,
- }
+ holderName: String,
+ PAN: {
+ type: Number
+ },
+ IBAN: {
+ type: String
+ }
})
-
const UserSchema = mongoose.Schema({
- first_name: String,
- last_name: String,
- national_code: String,
- province_name: Object,
- city_name: Object,
- address: String,
- mobile_number: String,
- cell_number:String,
- password: String,
- profilePic: {
- type: String,
- default: "noPic"
- },
- shopName: String,
- birthDate: String,
- lastIP:String,
- walletBalance: {
- type: Number,
- min: 0,
- default: 0
- },
- dollarBalance: {
- type: Number,
- min: 0,
- default: 0
- },
- score: {
- type: Number,
- min: 0,
- default: 0
- },
- cardBank: [BankSchema],
- active:{ type: Boolean, default: false },
+ first_name: String,
+ last_name: String,
+ national_code: String,
+ province_name: Object,
+ city_name: Object,
+ address: String,
+ mobile_number: String,
+ cell_number: String,
+ password: String,
+ profilePic: {
+ type: String,
+ default: 'noPic'
+ },
+ shopName: String,
+ birthDate: String,
+ lastIP: String,
+ walletBalance: {
+ type: Number,
+ min: 0,
+ default: 0
+ },
+ // dollarBalance: {
+ // type: Number,
+ // min: 0,
+ // default: 0
+ // },
+ score: {
+ type: Number,
+ min: 0,
+ default: 0
+ },
+ cardBank: [BankSchema],
+ active: { type: Boolean, default: false },
+ /// //////////////////////////////// user confirmations
+ seenByAdmin: { type: Boolean, default: false },
- /// //////////////////////////////// user confirmations
- seenByAdmin: { type: Boolean, default: false },
-
- /// /////////////
- token: String,
- otp:String
+ /// /////////////
+ token: String,
+ otp: String
})
module.exports = mongoose.model('UserGPS', UserSchema)
diff --git a/server/models/GPS.Withdraw.js b/server/models/GPS.Withdraw.js
index 3b02048..33a7d98 100644
--- a/server/models/GPS.Withdraw.js
+++ b/server/models/GPS.Withdraw.js
@@ -1,41 +1,40 @@
const mongoose = require('mongoose')
-
const BankSchema = mongoose.Schema({
- holderName: String,
- PAN: {
- type: Number,
- },
- IBAN: {
- type: String,
- }
+ holderName: String,
+ PAN: {
+ type: Number
+ },
+ IBAN: {
+ type: String
+ }
})
/// /////////////////////////////////////////////////////
const WithdrawSchema = mongoose.Schema({
- card: BankSchema,
- amount: {
- type: Number,
- min: 0
- },
- dollarAmount: {
- type: Number,
- min: 0
- },
- userId: {
- type: String,
- ref: 'UserGPS'
- },
- status: {
- type: Number,
- enum: [
- 0, // Pending
- 1, // Accepted
- 2, // deposited
- ]
- },
- depositDate: Date,
- trackingNumber: String
+ card: BankSchema,
+ amount: {
+ type: Number,
+ min: 0
+ },
+ // dollarAmount: {
+ // type: Number,
+ // min: 0
+ // },
+ userId: {
+ type: String,
+ ref: 'UserGPS'
+ },
+ status: {
+ type: Number,
+ enum: [
+ 0, // Pending
+ 1, // Accepted
+ 2 // deposited
+ ]
+ },
+ depositDate: Date,
+ trackingNumber: String
})
module.exports = mongoose.model('Withdraw', WithdrawSchema)
diff --git a/static/example.xlsx b/static/example.xlsx
index e135af3..e5a6ba0 100644
Binary files a/static/example.xlsx and b/static/example.xlsx differ