From 8c6aa4595c100ee0a76c6c831d2a891664613344 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 4 Dec 2025 09:43:38 +0330 Subject: [PATCH] up --- server/controllers/GPS.Award.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/server/controllers/GPS.Award.js b/server/controllers/GPS.Award.js index 1d8e43e..7a6009d 100644 --- a/server/controllers/GPS.Award.js +++ b/server/controllers/GPS.Award.js @@ -30,14 +30,15 @@ module.exports.findAllUser = async (req, res) => { 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') + const awardsReq = await AwardRequest.find({ userId: req.user_id }) + .populate('awardId', '-created_at -updated_at') const score = await GPSUser.findById(req.user_id, { score: 1 }) // 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) + const h = awardsReq.find(awardReq => awardReq.awardId.id == award.id) - if (h.length) { + if (h) { return { id: award.id, score: award.score, @@ -45,23 +46,36 @@ module.exports.findAllUser = async (req, res) => { desc: award.desc, expireDate: award.expireDate, req: { - desc: h[0].desc, - metaData: h[0].metaData, - status: h[0].status + desc: h.desc, + metaData: h.metaData, + status: h.status }, status: 1 } - } else if(award.expireDate < toDay){ + } else if (new Date(award.expireDate) < toDay) { return { id: award.id, score: award.score, title: award.title, desc: award.desc, expireDate: award.expireDate, + req: null, status: 0 } - } - }) + } + // else { + // // Award is not expired and has no request + // return { + // id: award.id, + // score: award.score, + // title: award.title, + // desc: award.desc, + // expireDate: award.expireDate, + // req: null, + // status: 2 + // } + // } + }).filter(Boolean) // Remove any undefined values res.status(200).json({ awards: d, score }) }