From f488b7aa8e0ecd65970a6f3d4b5cbddcffc8f795 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 4 Dec 2025 10:34:12 +0330 Subject: [PATCH] up --- server/controllers/GPS.Award.js | 44 ++++++++++++++------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/server/controllers/GPS.Award.js b/server/controllers/GPS.Award.js index 7a6009d..bbb416e 100644 --- a/server/controllers/GPS.Award.js +++ b/server/controllers/GPS.Award.js @@ -27,19 +27,22 @@ module.exports.createAward = [ module.exports.findAllUser = async (req, res) => { const toDay = new Date() - const awards = await Award.find({ + 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') + isDeleted: false + }) + 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 => { + const d = [] + + awards.forEach(award => { // eslint-disable-next-line eqeqeq - const h = awardsReq.find(awardReq => awardReq.awardId.id == award.id) + const h = awardsReq.find(awardReq => awardReq.awardId && awardReq.awardId.id == award.id) + const isExpired = new Date(award.expireDate) < toDay if (h) { - return { + // Award has a request + d.push({ id: award.id, score: award.score, title: award.title, @@ -51,9 +54,10 @@ module.exports.findAllUser = async (req, res) => { status: h.status }, status: 1 - } - } else if (new Date(award.expireDate) < toDay) { - return { + }) + } else if (!isExpired) { + // Award is expired and has no request + d.push({ id: award.id, score: award.score, title: award.title, @@ -61,21 +65,9 @@ module.exports.findAllUser = async (req, res) => { 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 }) }