Update: User.ad
This commit is contained in:
parent
a369177e19
commit
b9512ef3b0
1 changed files with 12 additions and 1 deletions
|
|
@ -418,12 +418,23 @@ exports.ad = (req, res) => {
|
||||||
match = {$match: {isVisible: true, isActive: true}};
|
match = {$match: {isVisible: true, isActive: true}};
|
||||||
pick = {$sample: {size: parseInt(quantity, 10)}};
|
pick = {$sample: {size: parseInt(quantity, 10)}};
|
||||||
}
|
}
|
||||||
|
console.log(match, pick, interests);
|
||||||
Ad.aggregate([
|
Ad.aggregate([
|
||||||
match,
|
match,
|
||||||
pick
|
pick
|
||||||
])
|
])
|
||||||
.then(data => {
|
.then(data => {
|
||||||
return sendMessage(res, 11, data, token);
|
if(data.length > 0){
|
||||||
|
return sendMessage(res, 11, data, token);
|
||||||
|
} else {
|
||||||
|
Ad.aggregate([{$match: {isVisible: true, isActive: true}}, {$sample: {size: parseInt(quantity, 10)}}])
|
||||||
|
.then(data => {
|
||||||
|
return sendMessage(res, 11, data, token);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
return sendError(res,500,101,err.message || `Some error occurred while getting ${quantity} ad(s) for the User.`, token);
|
||||||
|
});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return sendError(res,500,101,err.message || `Some error occurred while getting ${quantity} ad(s) for the User.`, token);
|
return sendError(res,500,101,err.message || `Some error occurred while getting ${quantity} ad(s) for the User.`, token);
|
||||||
|
|
|
||||||
Reference in a new issue