Skip to content

Commit 44012f8

Browse files
committed
Merge brt puanch 'develop' of https://github.com/swqat117/turftown-backend into develop
2 parents 17b4b0b + a0a18a7 commit 44012f8

File tree

2 files changed

+88
-38
lines changed

2 files changed

+88
-38
lines changed

routes/admin.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -907,18 +907,19 @@ router.post('/create_ad',
907907
verifyToken,
908908
AccessControl('ads', 'create'),
909909
(req, res, next) => {
910-
Ads.find({}).then(ads=>{
911-
let check_position = ads.filter(ad=>ad.position===req.body.position && ad.sport_type === req.body.sport_type && ad.page === req.body.page)
912-
console.log('position ',check_position.length);
913-
if(check_position.length){
914-
console.log('check ',check_position);
910+
Ads.find({status:true}).then(ads=>{
911+
let check_start_date = moment(req.body.start_date).format("YYYY-MM-DD")
912+
let check_end_date = moment(req.body.end_date).format("YYYY-MM-DD")
913+
let check_position = ads.filter(ad=>ad.position===req.body.position && ad.sport_type === req.body.sport_type && ad.page === req.body.page && (moment(check_start_date).isBetween(moment(ad.start_date).format("YYYY-MM-DD"),moment(ad.end_date).format("YYYY-MM-DD"),null,[]) || moment(check_end_date).isBetween(moment(ad.start_date).format("YYYY-MM-DD"),moment(ad.end_date).format("YYYY-MM-DD"),null,[]) ))
914+
if(check_position.length > 0){
915915
existing_positions = []
916916
check_position.map(ad=>{
917-
let x = 'position: '+ad.position.toString()+"already exists in page: "+ad.page + 'in sport: '+ad.sport_type
917+
let x = 'position: '+ad.position.toString()+" already exists in "+ad.page+' in sport '+ad.sport_type
918918
existing_positions.push(x)
919919
})
920920
res.send({status:"failed", message: existing_positions[0], existing_positions})
921-
}else{
921+
}
922+
else{
922923
Ads.create(req.body).then(ads=>{
923924
Ads.findById({_id:ads.id}).lean().populate('event','_id event type').populate('venue','_id name venue type').then(ads=>{
924925
res.send({status:"success", message:"ad created", data:ads})
@@ -936,13 +937,27 @@ router.post('/edit_ad/:id',
936937
(req, res, next) => {
937938
req.body.modified_at = new Date()
938939
req.body.modified_by = req.username
940+
Ads.find({status:true}).then(ads=>{
941+
let check_start_date = moment(req.body.start_date).format("YYYY-MM-DD")
942+
let check_end_date = moment(req.body.end_date).format("YYYY-MM-DD")
943+
let check_position = ads.filter(ad=>ad.position===req.body.position && ad.sport_type === req.body.sport_type && ad.page === req.body.page && ad._id === req.params.id && (moment(check_start_date).isBetween(moment(ad.start_date).format("YYYY-MM-DD"),moment(ad.end_date).format("YYYY-MM-DD"),null,[]) || moment(check_end_date).isBetween(moment(ad.start_date).format("YYYY-MM-DD"),moment(ad.end_date).format("YYYY-MM-DD"),null,[]) ))
944+
if(check_position.length > 0){
945+
existing_positions = []
946+
check_position.map(ad=>{
947+
let x = 'position: '+ad.position.toString()+" already exists in "+ad.page+' in sport '+ad.sport_type
948+
existing_positions.push(x)
949+
})
950+
res.send({status:"failed", message: existing_positions[0]})
951+
}
952+
else {
939953
Ads.findByIdAndUpdate({_id:req.params.id}, req.body).then(ads=>{
940954
Ads.findById({_id:req.params.id}).lean().populate('event','_id event type').populate('venue','_id name venue type').then(ads=>{
941-
console.log(' edit ads',ads);
942955
res.send({status:"success", message:"ad modified", data:ads})
943956
ActivityLog(req.userId, req.role, 'ad modified', req.name+" modified ad ")
944957
}).catch(next)
945958
}).catch(next)
959+
}
960+
}).catch(next)
946961
})
947962

948963
//// Delete ad

routes/user.js

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,12 +1670,15 @@ router.post('/booking_history_by_time/:id', verifyToken, (req, res, next) => {
16701670
let x = {}
16711671
let finalBookingList = []
16721672
Object.entries(grouped).map(([i,j])=>{
1673-
j.every((key)=>{
1674-
if(key.booking_status !== "cancelled" && key.booking_status !== "completed"){
1675-
x[i] = j
1676-
finalBookingList = [...j,...finalBookingList]
1677-
}
1678-
})
1673+
const filtered = j.filter((key)=>{
1674+
if(key.booking_status == "booked"){
1675+
return key
1676+
}
1677+
})
1678+
if(filtered.length > 0){
1679+
x[i] = j
1680+
finalBookingList = [...j,...finalBookingList]
1681+
}
16791682
})
16801683
res.send({status:"success", message:"booking history fetched", data:finalBookingList})
16811684
}).catch(next)
@@ -1688,11 +1691,21 @@ router.post('/booking_history_by_time/:id', verifyToken, (req, res, next) => {
16881691
let grouped = _.mapValues(_.groupBy(booking, 'group_id'),clist => clist.map(booking => _.omit(booking, 'multiple_id')));
16891692
let finalBookingList = []
16901693
Object.entries(grouped).map(([i,j])=>{
1691-
j.every((key)=>{
1692-
if(moment().isAfter(key.end_date_range) && key.booking_status === 'completed'){
1693-
finalBookingList = [...j,...finalBookingList]
1694-
}
1694+
const filtered = j.filter((key)=>{
1695+
if(key.booking_status == "completed" && moment().isAfter(key.end_date_range) ){
1696+
return key
1697+
}
16951698
})
1699+
if(filtered.length > 0){
1700+
x[i] = j
1701+
finalBookingList = [...j,...finalBookingList]
1702+
}
1703+
1704+
// j.every((key)=>{
1705+
// if(moment().isAfter(key.end_date_range) && key.booking_status === 'completed'){
1706+
// finalBookingList = [...j,...finalBookingList]
1707+
// }
1708+
// })
16961709
})
16971710
res.send({status:"success", message:"booking history fetched", data:finalBookingList})
16981711
}).catch(next)
@@ -1707,14 +1720,16 @@ router.post('/booking_history_by_time/:id', verifyToken, (req, res, next) => {
17071720
let x = {}
17081721
let finalBookingList = []
17091722
Object.entries(grouped).map(([i,j])=>{
1710-
1711-
j.every((key)=>{
1712-
if(key.booking_status !== "cancelled"){
1713-
x[i] = j
1714-
finalBookingList = [...j,...finalBookingList]
1715-
}
1716-
})
1717-
})
1723+
const filtered = j.filter((key)=>{
1724+
if(key.booking_status !== "cancelled"){
1725+
return key
1726+
}
1727+
})
1728+
if(filtered.length > 0){
1729+
x[i] = j
1730+
finalBookingList = [...j,...finalBookingList]
1731+
}
1732+
})
17181733
res.send({status:"success", message:"booking history fetched", data:finalBookingList, })
17191734
}).catch(next)
17201735
})
@@ -1729,12 +1744,22 @@ router.post('/booking_history_by_time/:id', verifyToken, (req, res, next) => {
17291744
let x = {}
17301745
let finalBookingList = []
17311746
Object.entries(grouped).map(([i,j])=>{
1732-
j.every((key)=>{
1733-
if(key.booking_status !== "cancelled"){
1734-
x[i] = j
1735-
finalBookingList = [...j,...finalBookingList]
1736-
}
1737-
})
1747+
const filtered = j.filter((key)=>{
1748+
if(key.booking_status !== "cancelled"){
1749+
return key
1750+
}
1751+
})
1752+
if(filtered.length > 0){
1753+
x[i] = j
1754+
finalBookingList = [...j,...finalBookingList]
1755+
}
1756+
1757+
// j.every((key)=>{
1758+
// if(key.booking_status !== "cancelled"){
1759+
// x[i] = j
1760+
// finalBookingList = [...j,...finalBookingList]
1761+
// }
1762+
// })
17381763
})
17391764
console.log(finalBookingList,sortedActivities[0].invoice_date);
17401765
res.send({status:"success", message:"booking history fetched", data:finalBookingList ,invoice_date:sortedActivities.length > 0 ? sortedActivities[0].invoice_date : '' })
@@ -1750,12 +1775,22 @@ router.post('/booking_history_by_time/:id', verifyToken, (req, res, next) => {
17501775
let x = {}
17511776
let finalBookingList = []
17521777
Object.entries(grouped).map(([i,j])=>{
1753-
j.every((key)=>{
1754-
if(key.booking_status !== "cancelled"){
1755-
x[i] = j
1756-
finalBookingList = [...j,...finalBookingList]
1757-
}
1758-
})
1778+
1779+
const filtered = j.filter((key)=>{
1780+
if(key.booking_status !== "cancelled"){
1781+
return key
1782+
}
1783+
})
1784+
if(filtered.length > 0){
1785+
x[i] = j
1786+
finalBookingList = [...j,...finalBookingList]
1787+
}
1788+
// j.every((key)=>{
1789+
// if(key.booking_status !== "cancelled"){
1790+
// x[i] = j
1791+
// finalBookingList = [...j,...finalBookingList]
1792+
// }
1793+
// })
17591794
})
17601795
res.send({status:"success", message:"booking history fetched", data:finalBookingList ,invoice_date:sortedActivities.length > 0 ? sortedActivities[0].invoice_date : '' })
17611796
}).catch(next)

0 commit comments

Comments
 (0)