Skip to content

Commit

Permalink
Merge pull request #95 from rairprotocol/93-notifications-query-update
Browse files Browse the repository at this point in the history
Update Notifications GET
  • Loading branch information
sarora180673 authored Jul 8, 2024
2 parents bb73780 + f151784 commit 0d0ecfa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
30 changes: 15 additions & 15 deletions rair-node/bin/api/nft/nft.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ module.exports = {
if (onResale.toString() === 'true') {
pipeline.push({
$lookup: {
from: 'ResaleTokenOffer',
localField: 'uniqueIndexInContract',
foreignField: 'tokenIndex',
as: 'resaleData',
let: {
tokenContract: '$tokenContract',
},
pipeline: [{
$match: {
$expr: {
$eq: ['$$tokenContract', '$contract'],
},
buyer: { $exists: false },
},
}],
from: 'ResaleTokenOffer',
localField: 'uniqueIndexInContract',
foreignField: 'tokenIndex',
as: 'resaleData',
let: {
tokenContract: '$tokenContract',
},
pipeline: [{
$match: {
$expr: {
$eq: ['$$tokenContract', '$contract'],
},
buyer: { $exists: false },
},
}],
},
}, {
$addFields: {
Expand Down
42 changes: 38 additions & 4 deletions rair-node/bin/api/notifications/notifications.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,47 @@ module.exports = {
if (user && adminRights) {
filter.user = user.toLowerCase();
}
const list = await Notification.find(filter)
.sort({ createdAt: 'descending' })
.skip(itemsPerPage * pageNum)
.limit(itemsPerPage);
const list = await Notification.aggregate([
{
$match: filter,
},
{
$lookup: {
from: 'MintedToken',
let: {
tokenId: '$data',
},
pipeline: [
{
$match: {
$expr: {
$in: [
{
$toString: '$_id',
},
'$$tokenId',
],
},
},
},
],
as: 'tokenData',
},
},
{
$addFields: {
tokenData: '$tokenData.metadata.image',
},
},
{ $sort: { createdAt: 1 } },
{ $skip: itemsPerPage * pageNum },
{ $limit: itemsPerPage },
]);
const count = await Notification.count(filter);
return res.json({
success: true,
notifications: list,
totalCount: count,
});
} catch (err) {
logger.error(err);
Expand Down
4 changes: 3 additions & 1 deletion rair-node/readme/current/notifications/get_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Uses pagination and filtering, user search is only available to admins
"itemsPerPage": { "required": false, "content": { "type": "number" } },
"user": { "required": false, "content": { "type": "string" } },
"type": { "required": false, "content": { "type": "string" } },
"read": { "required": false, "content": { "type": "boolean" } },
"onlyRead": { "required": false, "content": { "type": "boolean" } },
"onlyUnread": { "required": false, "content": { "type": "boolean" } },
}
```

Expand All @@ -22,6 +23,7 @@ Uses pagination and filtering, user search is only available to admins
```json
{
"success": true,
"totalCount": 90,
"notifications": [
{
"_id": "6657edb4d1f06c7b91e39089",
Expand Down

0 comments on commit 0d0ecfa

Please sign in to comment.