Update awards endpoint data and fix reset pass bug
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
const EnvirementVariables = {
|
||||
// node envirements
|
||||
isDev: process.env.NODE_ENV === 'development',
|
||||
// isDev: true,
|
||||
// isDev: process.env.NODE_ENV === 'development',
|
||||
isDev: true,
|
||||
isProduction: process.env.NODE_ENV === 'production',
|
||||
|
||||
// server ports
|
||||
|
||||
@@ -2,6 +2,7 @@ const { body, validationResult, param } = require('express-validator');
|
||||
const { _sr } = require('../plugins/serverResponses');
|
||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
||||
const Award = require('../models/GPS.Award');
|
||||
const AwardRequest = require('../models/GPS.AwardRequest');
|
||||
|
||||
|
||||
module.exports.createAward = [
|
||||
@@ -28,8 +29,41 @@ module.exports.createAward = [
|
||||
|
||||
module.exports.findAllUser = async (req, res) => {
|
||||
const toDay = new Date()
|
||||
const data = await Award.find({expireDate: {$gt: toDay}, isDeleted:false})
|
||||
res.status(200).json(data)
|
||||
const awards = await Award.find({expireDate: {$gt: toDay}, isDeleted:false})
|
||||
const awardsReq = await AwardRequest.find({userId:req.user_id}).populate('awardId','-created_at -updated_at')
|
||||
// eslint-disable-next-line array-callback-return
|
||||
const d = awards.map((award) => {
|
||||
|
||||
// eslint-disable-next-line eqeqeq
|
||||
const h = awardsReq.filter(awardReq => awardReq.awardId.id == award.id);
|
||||
|
||||
console.log(award);
|
||||
|
||||
if (h.length) {
|
||||
return {
|
||||
score:award.score,
|
||||
title:award.title,
|
||||
desc:award.desc,
|
||||
expireDate:award.expireDate,
|
||||
req: {
|
||||
desc: h[0].desc,
|
||||
metaData: h[0].metaData,
|
||||
status: h[0].status,
|
||||
},
|
||||
status: 1
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
score:award.score,
|
||||
title:award.title,
|
||||
desc:award.desc,
|
||||
expireDate:award.expireDate,
|
||||
status: 0
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
res.status(200).json(d)
|
||||
}
|
||||
|
||||
module.exports.findAllAdmin = async (req, res) => {
|
||||
|
||||
@@ -279,9 +279,15 @@ module.exports.update_user_password = [
|
||||
const salt = await bcrypt.genSalt(10)
|
||||
const hash = await bcrypt.hash(newPassword, salt)
|
||||
const user = await User.findById(user_id)
|
||||
if (!user) throw new Error(_faSr.not_found.user_id)
|
||||
if (!user) {
|
||||
res.status(404)
|
||||
throw new Error(_faSr.not_found.user_id)
|
||||
}
|
||||
const passwordMatch = await bcrypt.compare(password, user.password)
|
||||
if (!passwordMatch) throw new Error('err')
|
||||
if (!passwordMatch) {
|
||||
res.status(401)
|
||||
throw new Error('err')
|
||||
}
|
||||
user.password = hash
|
||||
await user.save()
|
||||
return res.json({ message: _faSr.response.success_save })
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ const inHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@asan-service:27017/as
|
||||
const outHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
|
||||
const init = ()=>{
|
||||
try {
|
||||
mongoose.connect(inHostUrl, {
|
||||
mongoose.connect(outHostUrl, {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
useFindAndModify: false,
|
||||
|
||||
Reference in New Issue
Block a user