diff --git a/server/_env.js b/server/_env.js index 010cb05..1d75de1 100644 --- a/server/_env.js +++ b/server/_env.js @@ -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 diff --git a/server/controllers/GPS.Award.js b/server/controllers/GPS.Award.js index 6f2fc5c..27ce0bf 100644 --- a/server/controllers/GPS.Award.js +++ b/server/controllers/GPS.Award.js @@ -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) => { diff --git a/server/controllers/GPS.User.js b/server/controllers/GPS.User.js index affdb76..7b47dc3 100644 --- a/server/controllers/GPS.User.js +++ b/server/controllers/GPS.User.js @@ -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 }) diff --git a/server/database.js b/server/database.js index 0f6c099..d59a6d9 100644 --- a/server/database.js +++ b/server/database.js @@ -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,