Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Notifications GET #95

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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