This commit is contained in:
morteza-mortezai
2025-12-04 09:43:38 +03:30
parent 3def8f7157
commit 8c6aa4595c
+23 -9
View File
@@ -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 })
}