Add award
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const bcrypt = require('bcryptjs')
|
||||
const jwt = require('jsonwebtoken')
|
||||
const { body, param, validationResult } = require('express-validator')
|
||||
const { body, validationResult } = require('express-validator')
|
||||
const { secretKey } = require('../authentication')
|
||||
const { _sr } = require('../plugins/serverResponses')
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
@@ -23,14 +23,12 @@ module.exports.login = [
|
||||
else return true
|
||||
})
|
||||
}),
|
||||
|
||||
body('password')
|
||||
.notEmpty()
|
||||
.withMessage(_sr.fa.required.password)
|
||||
.bail()
|
||||
.isLength({ min: 4 })
|
||||
.withMessage(_sr.fa.min_char.min4),
|
||||
|
||||
body('remember_me')
|
||||
.exists()
|
||||
.withMessage(_sr.fa.required.remember_me)
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
const { body, validationResult, param } = require('express-validator');
|
||||
const { _sr } = require('../plugins/serverResponses');
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
||||
const Award = require('../models/GPS.Award');
|
||||
|
||||
|
||||
module.exports.createAward = [
|
||||
[
|
||||
body('score').notEmpty().isInt().withMessage(_sr.fa.required.field),
|
||||
body('title').notEmpty().isString().withMessage(_sr.fa.required.field),
|
||||
body('desc').notEmpty().isString().withMessage(_sr.fa.required.field),
|
||||
body('expireDate').notEmpty().isDate().withMessage(_sr.fa.required.field),
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const { score, title, desc, expireData } = req.body;
|
||||
const award = await Award.create({ score, title, desc, expireData })
|
||||
res.status(201).json({
|
||||
msg: _sr.fa.response.success_save,
|
||||
data: award
|
||||
})
|
||||
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.findAllUser = async (req, res) => {
|
||||
const toDay = new Date()
|
||||
const data = await Award.find({$lt: {expireDate: toDay}})
|
||||
res.status(200).json(data)
|
||||
}
|
||||
|
||||
module.exports.findAllAdmin = async (req, res) => {
|
||||
const data = await Award.find({})
|
||||
res.status(200).json(data)
|
||||
}
|
||||
|
||||
module.exports.findOne = [
|
||||
[
|
||||
param('id').notEmpty().isMongoId().withMessage('ایدی را وارد یا تصحیح کنید')
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const data = await Award.findById(req.params.id)
|
||||
if (!data) {
|
||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||
} else {
|
||||
res.status(200).json(data)
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
|
||||
module.exports.update =[
|
||||
[
|
||||
param('id').notEmpty().isMongoId().withMessage('ایدی را وارد یا تصحیح کنید'),
|
||||
body('score').notEmpty().isInt().withMessage(_sr.fa.required.field),
|
||||
body('title').notEmpty().isString().withMessage(_sr.fa.required.field),
|
||||
body('desc').notEmpty().isString().withMessage(_sr.fa.required.field),
|
||||
body('expireDate').notEmpty().isDate().withMessage(_sr.fa.required.field),
|
||||
],
|
||||
checkValidations(validationResult),
|
||||
async (req, res) => {
|
||||
const { score, title, desc, expireData } = req.body;
|
||||
const data = await Award.findById(req.params.id)
|
||||
if (!data) {
|
||||
res.status(404).json({ msg: _sr.fa.not_found.item_id })
|
||||
} else {
|
||||
data.score = score;
|
||||
data.title = title;
|
||||
data.desc = desc;
|
||||
data.expireData = expireData;
|
||||
data.save()
|
||||
res.status(200).json({
|
||||
msg: _sr.fa.response.success_save,
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
const { body, param, validationResult } = require('express-validator')
|
||||
const { _sr } = require('../plugins/serverResponses')
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions')
|
||||
const User = require('../models/User')
|
||||
@@ -0,0 +1,12 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const AwairdSchema = mongoose.Schema({
|
||||
|
||||
score:Number,
|
||||
title:String,
|
||||
desc:String,
|
||||
expireDate:Date
|
||||
|
||||
})
|
||||
|
||||
module.exports = mongoose.model('AwairdGPS', AwairdSchema)
|
||||
@@ -0,0 +1,24 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
const AwardRequestSchema = mongoose.Schema({
|
||||
awardId:{
|
||||
type:String,
|
||||
ref:'Award'
|
||||
},
|
||||
userId:{
|
||||
type:String,
|
||||
ref:'User'
|
||||
},
|
||||
desc:String,
|
||||
metaData:Object,
|
||||
status:{
|
||||
type:Number,
|
||||
enum:[
|
||||
0, // Pending
|
||||
1 // Done
|
||||
],
|
||||
default:0
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = mongoose.model('AwardRequestGPS', AwardRequestSchema)
|
||||
Reference in New Issue
Block a user