fix bug
This commit is contained in:
@@ -353,6 +353,8 @@
|
|||||||
name="دستگاه های ثبت شده"
|
name="دستگاه های ثبت شده"
|
||||||
:to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }"
|
:to="{ name: 'admin-gps-installed-device', query: { filter: 'all' } }"
|
||||||
font-icon="fal fa-map"
|
font-icon="fal fa-map"
|
||||||
|
:badge="newInstallDeviceRequest ? { text: newInstallDeviceRequest, color: 'danger' } : null"
|
||||||
|
|
||||||
:exact="false"
|
:exact="false"
|
||||||
/>
|
/>
|
||||||
<CSidebarNavItem
|
<CSidebarNavItem
|
||||||
@@ -361,6 +363,8 @@
|
|||||||
:to="{ name: 'admin-gps-withdraw', query: { filter: 'all' }}"
|
:to="{ name: 'admin-gps-withdraw', query: { filter: 'all' }}"
|
||||||
font-icon="fal fa-credit-card"
|
font-icon="fal fa-credit-card"
|
||||||
:exact="false"
|
:exact="false"
|
||||||
|
:badge="newWithdrawRequest ? { text: newWithdrawRequest, color: 'danger' } : null"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
<CSidebarNavItem
|
<CSidebarNavItem
|
||||||
v-if="hasPermission('gps')"
|
v-if="hasPermission('gps')"
|
||||||
@@ -372,9 +376,11 @@
|
|||||||
<CSidebarNavItem
|
<CSidebarNavItem
|
||||||
v-if="hasPermission('gps')"
|
v-if="hasPermission('gps')"
|
||||||
name="درخواست های جوایز"
|
name="درخواست های جوایز"
|
||||||
:to="{ name: 'admin-admins-admin', params: { admin: 'new' } }"
|
:to="{ name: 'admin-gps-award-req', params: { admin: 'new' } }"
|
||||||
font-icon="fal fa-trophy"
|
font-icon="fal fa-trophy"
|
||||||
:exact="false"
|
:exact="false"
|
||||||
|
:badge="newAwardRequest ? { text: newAwardRequest, color: 'danger' } : null"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</CSidebarNavDropdown>
|
</CSidebarNavDropdown>
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,47 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
socket.on(`admin:notify`, data => {
|
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') {
|
if (data.type === 'updateUnreadCuMsgs') {
|
||||||
// update store
|
// update store
|
||||||
this.$store.commit('admin/set', ['unreadCuMsgs', data.unreadCuMsgs])
|
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 admin = io.of('/admin')
|
||||||
const data = { type }
|
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') {
|
if (type === 'updateNewCustomers') {
|
||||||
const newCustomers = await User.find({ scope: ['user'], seenByAdmin: false })
|
const newCustomers = await User.find({ scope: ['user'], seenByAdmin: false })
|
||||||
data.newCustomers = newCustomers.length
|
data.newCustomers = newCustomers.length
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
|||||||
const User = require('../models/GPS.User')
|
const User = require('../models/GPS.User')
|
||||||
const Award = require('../models/GPS.Award');
|
const Award = require('../models/GPS.Award');
|
||||||
const AwardRequest = require('../models/GPS.AwardRequest');
|
const AwardRequest = require('../models/GPS.AwardRequest');
|
||||||
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
|
|
||||||
|
|
||||||
module.exports.sendRequest = [
|
module.exports.sendRequest = [
|
||||||
@@ -27,6 +28,7 @@ module.exports.sendRequest = [
|
|||||||
userId:req.user_id
|
userId:req.user_id
|
||||||
})
|
})
|
||||||
// res.status(200).json({ msg:_sr.fa.response.success_save, data})
|
// res.status(200).json({ msg:_sr.fa.response.success_save, data})
|
||||||
|
notifyAdmin('newAwardRequest')
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
@@ -45,7 +47,7 @@ module.exports.findAllUser = async(req, res)=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.findAllAdmin = 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)
|
res.status(200).json(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@ module.exports.findOne = [
|
|||||||
],
|
],
|
||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
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) {
|
if (!data) {
|
||||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||||
} else {
|
} else {
|
||||||
@@ -79,14 +81,16 @@ module.exports.update = [
|
|||||||
if (!data) {
|
if (!data) {
|
||||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||||
} else {
|
} else {
|
||||||
await AwardRequest.updateOne(
|
await AwardRequest.findByIdAndUpdate(
|
||||||
{id:req.params.id},
|
req.params.id,
|
||||||
{
|
{
|
||||||
status,
|
status,
|
||||||
desc,
|
desc,
|
||||||
metaData
|
metaData
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
notifyAdmin('newAwardRequest')
|
||||||
|
|
||||||
res.status(200).json({ msg: _sr.fa.response.success_save })
|
res.status(200).json({ msg: _sr.fa.response.success_save })
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
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/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')
|
||||||
|
|
||||||
module.exports.deviceRegistration = [
|
module.exports.deviceRegistration = [
|
||||||
[
|
[
|
||||||
@@ -30,6 +31,8 @@ module.exports.deviceRegistration = [
|
|||||||
const newRequest = await InstalledDevice.create(data);
|
const newRequest = await InstalledDevice.create(data);
|
||||||
device.status = 1;
|
device.status = 1;
|
||||||
device.save()
|
device.save()
|
||||||
|
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)
|
||||||
|
|
||||||
@@ -122,8 +125,8 @@ module.exports.updateInstalled = [
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@@ -136,6 +139,8 @@ module.exports.updateInstalled = [
|
|||||||
user.save()
|
user.save()
|
||||||
device.save()
|
device.save()
|
||||||
installedDevice.save()
|
installedDevice.save()
|
||||||
|
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 })
|
||||||
|
|
||||||
|
|
||||||
@@ -146,6 +151,8 @@ module.exports.updateInstalled = [
|
|||||||
installedDevice.save()
|
installedDevice.save()
|
||||||
device.status = 0;
|
device.status = 0;
|
||||||
device.save()
|
device.save()
|
||||||
|
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 })
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const {
|
|||||||
generateRandomDigits
|
generateRandomDigits
|
||||||
} = require('../plugins/controllersHelperFunctions')
|
} = require('../plugins/controllersHelperFunctions')
|
||||||
const _faSr = _sr.fa
|
const _faSr = _sr.fa
|
||||||
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -158,6 +159,8 @@ module.exports.register_user = [
|
|||||||
|
|
||||||
const user = new User(data)
|
const user = new User(data)
|
||||||
await user.save()
|
await user.save()
|
||||||
|
notifyAdmin('pendingUsers')
|
||||||
|
|
||||||
return res.json({ message: _faSr.response.success_save })
|
return res.json({ message: _faSr.response.success_save })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const registerFailurMsg = 'مشکلی در ثبت نام پیش آمده، لطفا مجددا تلاش کنید'
|
const registerFailurMsg = 'مشکلی در ثبت نام پیش آمده، لطفا مجددا تلاش کنید'
|
||||||
@@ -295,7 +298,7 @@ module.exports.send_otp = [
|
|||||||
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)
|
||||||
await sendConfirmationSMS(user.id)
|
await sendConfirmationSMS(user.id)
|
||||||
res.status(200).json({msg:"ok"})
|
res.status(200).json({ msg: "ok" })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err) return res500(res, err)
|
if (err) return res500(res, err)
|
||||||
}
|
}
|
||||||
@@ -373,14 +376,14 @@ module.exports.getUsersForAdmin = async (req, res) => {
|
|||||||
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) => {
|
||||||
const user = await User.findById(req.params.id).select('-password -token -otp -seenByAdmin')
|
const user = await User.findById(req.params.id).select('-password -token -otp -seenByAdmin')
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
return res.status(404).json({ msg: _sr.fa.not_found.user_id })
|
||||||
}else {
|
} else {
|
||||||
user.seenByAdmin = true
|
user.seenByAdmin = true
|
||||||
user.save()
|
user.save()
|
||||||
res.status(200).json(user)
|
res.status(200).json(user)
|
||||||
@@ -401,6 +404,7 @@ module.exports.activeUser = [
|
|||||||
{ 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')
|
||||||
|
|
||||||
res.status(200).json(data)
|
res.status(200).json(data)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const { _sr } = require('../plugins/serverResponses');
|
|||||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
||||||
const User = require('../models/GPS.User');
|
const User = require('../models/GPS.User');
|
||||||
const Withdraw = require('../models/GPS.Withdraw');
|
const Withdraw = require('../models/GPS.Withdraw');
|
||||||
|
const { notifyAdmin } = require('../WebSocket/controllers/admin_EventsController')
|
||||||
|
|
||||||
|
|
||||||
module.exports.createRequest = [
|
module.exports.createRequest = [
|
||||||
@@ -12,32 +13,33 @@ module.exports.createRequest = [
|
|||||||
checkValidations(validationResult),
|
checkValidations(validationResult),
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const withdraw = await Withdraw.findOne({userId: req.user_id, status:0})
|
const withdraw = await Withdraw.findOne({ userId: req.user_id, status: 0 })
|
||||||
if(withdraw){
|
if (withdraw) {
|
||||||
res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' })
|
res.status(400).json({ msg: 'شما درخواست درحال بررسی دارید' })
|
||||||
}else{
|
} else {
|
||||||
const user = await User.findById(req.user_id)
|
const user = await User.findById(req.user_id)
|
||||||
if(user.walletBalance < 50000){
|
if (user.walletBalance < 50000) {
|
||||||
const data = {
|
const data = {
|
||||||
card: req.body.card,
|
card: req.body.card,
|
||||||
userId: req.user_id,
|
userId: req.user_id,
|
||||||
amount: user.walletBalance,
|
amount: user.walletBalance,
|
||||||
dollarAmount: user.dollarBalance,
|
dollarAmount: user.dollarBalance,
|
||||||
status: 0
|
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 هزار تومان باشد' })
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 هزار تومان باشد' })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ msg: error })
|
res.status(500).json({ msg: error })
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ module.exports.getAllForUser = async (req, res) => {
|
|||||||
// { dollarAmount: { $regex: search } },
|
// { dollarAmount: { $regex: search } },
|
||||||
// { trackingNumber: { $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 })))
|
const total = Math.ceil((await Withdraw.countDocuments({ userId: req.user_id })))
|
||||||
res.status(200).json({ data, total })
|
res.status(200).json({ data, total })
|
||||||
}
|
}
|
||||||
@@ -119,6 +121,8 @@ module.exports.updateReq = [
|
|||||||
case "accept": {
|
case "accept": {
|
||||||
request.status = 1;
|
request.status = 1;
|
||||||
request.save()
|
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;
|
break;
|
||||||
@@ -128,6 +132,8 @@ module.exports.updateReq = [
|
|||||||
request.depositDate = new Date();
|
request.depositDate = new Date();
|
||||||
request.trackingNumber = req.body.trackingNumber || 0;
|
request.trackingNumber = req.body.trackingNumber || 0;
|
||||||
request.save()
|
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;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user