This commit is contained in:
morteza-mortezai
2025-12-04 10:34:12 +03:30
parent 8c6aa4595c
commit f488b7aa8e
+18 -26
View File
@@ -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 })
}