fix bug
This commit is contained in:
@@ -353,6 +353,8 @@
|
||||
name="دستگاه های ثبت شده"
|
||||
:to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }"
|
||||
font-icon="fal fa-map"
|
||||
:badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null"
|
||||
|
||||
:exact="false"
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
@@ -361,6 +363,8 @@
|
||||
:to="{ name: 'admin-gps-withdraw', query: { filter: 'all' }}"
|
||||
font-icon="fal fa-credit-card"
|
||||
:exact="false"
|
||||
:badge="newWithdrawRequest ? { text: newWithdrawRequest, color: 'danger' } : null"
|
||||
|
||||
/>
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('gps')"
|
||||
@@ -372,9 +376,11 @@
|
||||
<CSidebarNavItem
|
||||
v-if="hasPermission('gps')"
|
||||
name="درخواست های جوایز"
|
||||
:to="{ name: 'admin-admins-admin', params: { admin: 'new' } }"
|
||||
:to="{ name: 'admin-gps-award-req', params: { admin: 'new' } }"
|
||||
font-icon="fal fa-trophy"
|
||||
:exact="false"
|
||||
:badge="newAwardRequest ? { text: newAwardRequest, color: 'danger' } : null"
|
||||
|
||||
/>
|
||||
</CSidebarNavDropdown>
|
||||
|
||||
|
||||
@@ -67,6 +67,47 @@ export default {
|
||||
})
|
||||
|
||||
socket.on(`admin:notify`, data => {
|
||||
if (data.type === 'newAwardRequest') {
|
||||
// update store
|
||||
this.$store.commit('admin/set', ['newAwardRequest', data.newAwardRequest])
|
||||
|
||||
// update DOM
|
||||
if (this.$route.name === 'admin-gps-award-req') {
|
||||
this.$nuxt.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === 'newInstallDeviceRequest') {
|
||||
// update store
|
||||
this.$store.commit('admin/set', ['newInstallDeviceRequest', data.newInstallDeviceRequest])
|
||||
|
||||
// update DOM
|
||||
if (this.$route.name === 'admin-gps-installed-device') {
|
||||
this.$nuxt.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === 'newWithdrawRequest') {
|
||||
// update store
|
||||
this.$store.commit('admin/set', ['newWithdrawRequest', data.newWithdrawRequest])
|
||||
|
||||
// update DOM
|
||||
if (this.$route.name === 'admin-gps-withdraw') {
|
||||
this.$nuxt.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === 'updateNewCustomers') {
|
||||
// update store
|
||||
this.$store.commit('admin/set', ['updateNewCustomers', data.updateNewCustomers])
|
||||
|
||||
// update DOM
|
||||
if (this.$route.name === 'admin-gps-users') {
|
||||
this.$nuxt.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (data.type === 'updateUnreadCuMsgs') {
|
||||
// update store
|
||||
this.$store.commit('admin/set', ['unreadCuMsgs', data.unreadCuMsgs])
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog
|
||||
:title="dialogState === 1 ? 'به روزرسانی اطلاعات' : 'ساخت جایزه '"
|
||||
:visible.sync="centerDialogVisible"
|
||||
width="40%"
|
||||
center
|
||||
>
|
||||
<CRow>
|
||||
|
||||
<CCol xl="12" class="my-3">
|
||||
<el-input v-model="award.desc" type="textarea" :rows="3" placeholder="توضیحات"> </el-input>
|
||||
<p v-if="validation.desc" class="errMsg">{{ validation.desc.msg }}</p>
|
||||
|
||||
</CCol>
|
||||
|
||||
</CRow>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="centerDialogVisible = false">بستن</el-button>
|
||||
<el-button type="primary" @click="post( award)">تایید</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
<CustomSubHeader>
|
||||
<CBreadcrumb class="border-0 mb-0"> درخواست جوایز</CBreadcrumb>
|
||||
</CustomSubHeader>
|
||||
|
||||
<CRow>
|
||||
<CCol xl="6">
|
||||
<CCard>
|
||||
<CCardHeader>
|
||||
<slot name="header">
|
||||
<i class="fas fa-filter"></i>
|
||||
<b>فیلتر ها</b>
|
||||
</slot>
|
||||
</CCardHeader>
|
||||
|
||||
<CCardBody>
|
||||
<CRow>
|
||||
<CCol sm="12">
|
||||
<h4>جستجو در لیست:</h4>
|
||||
<el-input
|
||||
v-model="filterText"
|
||||
clearable
|
||||
placeholder=""
|
||||
style="display: inline-block; max-width: 500px; margin-top: 8px"
|
||||
></el-input>
|
||||
</CCol>
|
||||
</CRow>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</CCol>
|
||||
</CRow>
|
||||
|
||||
<CCard>
|
||||
<CCardHeader>
|
||||
<slot name="header">
|
||||
<CIcon name="cil-grid" />
|
||||
درخواست جوایز
|
||||
</slot>
|
||||
</CCardHeader>
|
||||
|
||||
<CCardBody>
|
||||
<el-table :data="filteredItems" style="width: 100%">
|
||||
<el-table-column type="index" label="#"> </el-table-column>
|
||||
<el-table-column label="نوع" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.awardId.title) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="توضیحات" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.awardId.desc) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="امتیاز مورد نیاز" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.awardId.score) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="مهلت استفاده" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ $jDate(scope.row.awardId.expireDate) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="نام و نام خانودگی متقاضی" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.userId.first_name)+" "+(scope.row.userId.last_name) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="توضیحات" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.userId.national_code) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="توضیحات" width="">
|
||||
<template slot-scope="scope">
|
||||
{{ (scope.row.userId.mobile_number) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column label="تغییرات" width="110" align="center">
|
||||
<template slot-scope="scope">
|
||||
<CButton :key="scope.row._id" color="info" variant="outline" @click="showDialog(scope.row._id, scope.row.desc)">
|
||||
<i class="fa fa-pencil"></i>
|
||||
</CButton>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</CCardBody>
|
||||
</CCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AdminGpsAwardList',
|
||||
layout: 'admin',
|
||||
async asyncData({ $axios, error, query }) {
|
||||
try {
|
||||
const { data } = await $axios.get('/api/admin/gps/award-request')
|
||||
|
||||
return {
|
||||
awards: data
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
awards: [],
|
||||
centerDialogVisible: false,
|
||||
award: {
|
||||
desc:'ی',
|
||||
status:1
|
||||
},
|
||||
filterText: '',
|
||||
dialogState: 0,
|
||||
validation: {}
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
config() {
|
||||
return this.$config
|
||||
},
|
||||
filteredItems() {
|
||||
const filterText = this.filterText
|
||||
if (!this.filterText.length) return this.awards
|
||||
else {
|
||||
return this.awards.filter(item => {
|
||||
return item.score.includes(filterText) || item.title.includes(filterText) || item.desc.includes(filterText)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showDialog( id,desc) {
|
||||
|
||||
this.dialogState = 1
|
||||
this.award = {
|
||||
_id:id,
|
||||
desc,
|
||||
status:1
|
||||
}
|
||||
this.centerDialogVisible = true
|
||||
|
||||
},
|
||||
|
||||
post( data) {
|
||||
|
||||
this.$axios.put(`/api/admin/gps/award-request/${data._id}`,data).then(res => {
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
})
|
||||
|
||||
this.centerDialogVisible = false
|
||||
this.$nuxt.refresh()
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.response.data.status === 401) {
|
||||
return this.$message({
|
||||
type: 'warning',
|
||||
message: 'لطفا دوباره وارد حساب خود شوید'
|
||||
})
|
||||
}
|
||||
if (err.response.status === 422) this.validation = err.response.data.validation
|
||||
else {
|
||||
console.log(err)
|
||||
return this.$message({
|
||||
type: 'warning',
|
||||
message: err.response.data.msg
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -96,6 +96,27 @@ module.exports.notifyAdmin = async type => {
|
||||
const admin = io.of('/admin')
|
||||
const data = { type }
|
||||
|
||||
if (type === 'newAwardRequest') {
|
||||
const newCustomers = await AwardRequest.countDocuments({ status: 0 })
|
||||
|
||||
data.newCustomers = newCustomers.length
|
||||
}
|
||||
if (type === 'newInstallDeviceRequest') {
|
||||
const newCustomers = await InstalledDevice.countDocuments({ status: 0 })
|
||||
|
||||
data.newCustomers = newCustomers.length
|
||||
}
|
||||
|
||||
if (type === 'newWithdrawRequest') {
|
||||
const newCustomers = await Withdraw.countDocuments({ status: 0 })
|
||||
|
||||
data.newCustomers = newCustomers.length
|
||||
}
|
||||
if (type === 'pendingUsers') {
|
||||
const newCustomers = await UserGPS.countDocuments({ active: false })
|
||||
|
||||
data.newCustomers = newCustomers.length
|
||||
}
|
||||
if (type === 'updateNewCustomers') {
|
||||
const newCustomers = await User.find({ scope: ['user'], seenByAdmin: false })
|
||||
data.newCustomers = newCustomers.length
|
||||
|
||||
@@ -4,6 +4,7 @@ const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
const User = require('../models/GPS.User')
|
||||
const Award = require('../models/GPS.Award');
|
||||
const AwardRequest = require('../models/GPS.AwardRequest');
|
||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||
|
||||
|
||||
module.exports.sendRequest = [
|
||||
@@ -27,6 +28,7 @@ module.exports.sendRequest = [
|
||||
userId:req.user_id
|
||||
})
|
||||
// res.status(200).json({ msg:_sr.fa.response.success_save, data})
|
||||
notifyAdmin('newAwardRequest')
|
||||
res.status(200).json(data)
|
||||
|
||||
}else{
|
||||
@@ -45,7 +47,7 @@ module.exports.findAllUser = async(req, res)=>{
|
||||
}
|
||||
|
||||
module.exports.findAllAdmin = async(req, res)=>{
|
||||
const data = await AwardRequest.find().populate('awardId','-created_at -updated_at').populate('userId', 'first_name last_name shopName shopNumber shopAddress national_code mobile_number')
|
||||
const data = await AwardRequest.find().populate('awardId','-created_at -updated_at').populate('userId', 'first_name last_name shopName national_code mobile_number')
|
||||
res.status(200).json(data)
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ module.exports.findOne = [
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const data = await AwardRequest.findById(req.params.id).populate('awardId','-created_at -updated_at').populate('userId', 'first_name last_name shopName shopNumber shopAddress national_code mobile_number')
|
||||
const data = await AwardRequest.findById(req.params.id).populate('awardId','-created_at -updated_at').populate('userId', 'first_name last_name shopName national_code mobile_number')
|
||||
if (!data) {
|
||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||
} else {
|
||||
@@ -79,14 +81,16 @@ module.exports.update = [
|
||||
if (!data) {
|
||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||
} else {
|
||||
await AwardRequest.updateOne(
|
||||
{id:req.params.id},
|
||||
await AwardRequest.findByIdAndUpdate(
|
||||
req.params.id,
|
||||
{
|
||||
status,
|
||||
desc,
|
||||
metaData
|
||||
}
|
||||
)
|
||||
notifyAdmin('newAwardRequest')
|
||||
|
||||
res.status(200).json({ msg: _sr.fa.response.success_save })
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
const { body, param, validationResult } = require('express-validator');
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
||||
const User = require('../models/User');
|
||||
const User = require('../models/GPS.User');
|
||||
const InstalledDevice = require('../models/GPS.InstalledDevice');
|
||||
const Device = require('../models/GPS.Device');
|
||||
const Score = require('../models/GPS.Score');
|
||||
const { _sr } = require('../plugins/serverResponses');
|
||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||
|
||||
module.exports.deviceRegistration = [
|
||||
[
|
||||
@@ -30,6 +31,8 @@ module.exports.deviceRegistration = [
|
||||
const newRequest = await InstalledDevice.create(data);
|
||||
device.status = 1;
|
||||
device.save()
|
||||
notifyAdmin('newInstallDeviceRequest')
|
||||
|
||||
// res.status(201).json({ msg: _sr.fa.response.success_save, data: newRequest })
|
||||
res.status(201).json(newRequest)
|
||||
|
||||
@@ -121,9 +124,9 @@ module.exports.updateInstalled = [
|
||||
installedDevice.installationDate = new Date();
|
||||
|
||||
device.status = 1;
|
||||
|
||||
user.walletBalance = device.profit
|
||||
user.dollarBalance = device.dollarProfit
|
||||
|
||||
user.walletBalance += device.profit
|
||||
user.dollarBalance += device.dollarProfit
|
||||
user.score = device.score
|
||||
|
||||
|
||||
@@ -136,8 +139,10 @@ module.exports.updateInstalled = [
|
||||
user.save()
|
||||
device.save()
|
||||
installedDevice.save()
|
||||
notifyAdmin('newInstallDeviceRequest')
|
||||
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -146,6 +151,8 @@ module.exports.updateInstalled = [
|
||||
installedDevice.save()
|
||||
device.status = 0;
|
||||
device.save()
|
||||
notifyAdmin('newInstallDeviceRequest')
|
||||
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: installedDevice })
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ const {
|
||||
generateRandomDigits
|
||||
} = require('../plugins/controllersHelperFunctions')
|
||||
const _faSr = _sr.fa
|
||||
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||
|
||||
|
||||
|
||||
@@ -158,6 +159,8 @@ module.exports.register_user = [
|
||||
|
||||
const user = new User(data)
|
||||
await user.save()
|
||||
notifyAdmin('pendingUsers')
|
||||
|
||||
return res.json({ message: _faSr.response.success_save })
|
||||
} catch (err) {
|
||||
const registerFailurMsg = 'مشکلی در ثبت نام پیش آمده، لطفا مجددا تلاش کنید'
|
||||
@@ -295,7 +298,7 @@ module.exports.send_otp = [
|
||||
const user = await User.findOne({ mobile_number })
|
||||
if (!user) throw new Error(_sr.fa.not_found.user_id)
|
||||
await sendConfirmationSMS(user.id)
|
||||
res.status(200).json({msg:"ok"})
|
||||
res.status(200).json({ msg: "ok" })
|
||||
} catch (err) {
|
||||
if (err) return res500(res, err)
|
||||
}
|
||||
@@ -373,14 +376,14 @@ module.exports.getUsersForAdmin = async (req, res) => {
|
||||
res.status(200).json(user)
|
||||
}
|
||||
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)
|
||||
}
|
||||
module.exports.getUserForAdmin = async (req, res) => {
|
||||
const user = await User.findById(req.params.id).select('-password -token -otp -seenByAdmin')
|
||||
if (!user) {
|
||||
return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
||||
}else {
|
||||
} else {
|
||||
user.seenByAdmin = true
|
||||
user.save()
|
||||
res.status(200).json(user)
|
||||
@@ -401,6 +404,7 @@ module.exports.activeUser = [
|
||||
{ new: true }).select('-password -token -otp -seenByAdmin')
|
||||
if (!data) return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
||||
|
||||
notifyAdmin('pendingUsers')
|
||||
|
||||
res.status(200).json(data)
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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 = [
|
||||
@@ -12,35 +13,36 @@ module.exports.createRequest = [
|
||||
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 })
|
||||
res.status(201).json(request)
|
||||
}else{
|
||||
res.status(400).json({ msg: 'حداقل موجودی باید 50 هزار تومان باشد' })
|
||||
}
|
||||
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 })
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -67,14 +69,14 @@ module.exports.getAllForUser = async (req, res) => {
|
||||
// const search = req.query?.search ? req.query.search : 0
|
||||
|
||||
|
||||
const data = await Withdraw.find({
|
||||
const data = await Withdraw.find({
|
||||
userId: req.user_id,
|
||||
// $or: [
|
||||
// { amount: { $regex: search } },
|
||||
// { dollarAmount: { $regex: search } },
|
||||
// { trackingNumber: { $regex: search } },
|
||||
// ],
|
||||
}).skip(page).limit(rows).sort({ created_at: -1 });
|
||||
}).skip(page).limit(rows).sort({ created_at: -1 });
|
||||
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
@@ -119,8 +121,10 @@ module.exports.updateReq = [
|
||||
case "accept": {
|
||||
request.status = 1;
|
||||
request.save()
|
||||
notifyAdmin('newWithdrawRequest')
|
||||
|
||||
res.status(201).json({ msg: _sr.fa.response.success_save, data: request })
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case "deposit": {
|
||||
@@ -128,8 +132,10 @@ module.exports.updateReq = [
|
||||
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: {
|
||||
|
||||
Reference in New Issue
Block a user