Update awards endpoint data and fix reset pass bug
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
const EnvirementVariables = {
|
const EnvirementVariables = {
|
||||||
// node envirements
|
// node envirements
|
||||||
isDev: process.env.NODE_ENV === 'development',
|
// isDev: process.env.NODE_ENV === 'development',
|
||||||
// isDev: true,
|
isDev: true,
|
||||||
isProduction: process.env.NODE_ENV === 'production',
|
isProduction: process.env.NODE_ENV === 'production',
|
||||||
|
|
||||||
// server ports
|
// server ports
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const { body, validationResult, param } = require('express-validator');
|
|||||||
const { _sr } = require('../plugins/serverResponses');
|
const { _sr } = require('../plugins/serverResponses');
|
||||||
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
const { checkValidations } = require('../plugins/controllersHelperFunctions');
|
||||||
const Award = require('../models/GPS.Award');
|
const Award = require('../models/GPS.Award');
|
||||||
|
const AwardRequest = require('../models/GPS.AwardRequest');
|
||||||
|
|
||||||
|
|
||||||
module.exports.createAward = [
|
module.exports.createAward = [
|
||||||
@@ -28,8 +29,41 @@ module.exports.createAward = [
|
|||||||
|
|
||||||
module.exports.findAllUser = async (req, res) => {
|
module.exports.findAllUser = async (req, res) => {
|
||||||
const toDay = new Date()
|
const toDay = new Date()
|
||||||
const data = await Award.find({expireDate: {$gt: toDay}, isDeleted:false})
|
const awards = await Award.find({expireDate: {$gt: toDay}, isDeleted:false})
|
||||||
res.status(200).json(data)
|
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) => {
|
module.exports.findAllAdmin = async (req, res) => {
|
||||||
|
|||||||
@@ -279,9 +279,15 @@ module.exports.update_user_password = [
|
|||||||
const salt = await bcrypt.genSalt(10)
|
const salt = await bcrypt.genSalt(10)
|
||||||
const hash = await bcrypt.hash(newPassword, salt)
|
const hash = await bcrypt.hash(newPassword, salt)
|
||||||
const user = await User.findById(user_id)
|
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)
|
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
|
user.password = hash
|
||||||
await user.save()
|
await user.save()
|
||||||
return res.json({ message: _faSr.response.success_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 outHostUrl = 'mongodb://root:KPTt76tImNBBMm4Kor8QA9gB@hotaka.liara.cloud:33794/asanserv_database?authSource=admin'
|
||||||
const init = ()=>{
|
const init = ()=>{
|
||||||
try {
|
try {
|
||||||
mongoose.connect(inHostUrl, {
|
mongoose.connect(outHostUrl, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
useFindAndModify: false,
|
useFindAndModify: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user