diff --git a/rair-node/bin/api/nft/nft.Service.js b/rair-node/bin/api/nft/nft.Service.js index 22b721938..d2488340d 100644 --- a/rair-node/bin/api/nft/nft.Service.js +++ b/rair-node/bin/api/nft/nft.Service.js @@ -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: { diff --git a/rair-node/bin/api/notifications/notifications.Service.js b/rair-node/bin/api/notifications/notifications.Service.js index 2ae799d44..948f2602a 100644 --- a/rair-node/bin/api/notifications/notifications.Service.js +++ b/rair-node/bin/api/notifications/notifications.Service.js @@ -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); diff --git a/rair-node/readme/current/notifications/get_list.md b/rair-node/readme/current/notifications/get_list.md index ac716bd81..9687f466a 100644 --- a/rair-node/readme/current/notifications/get_list.md +++ b/rair-node/readme/current/notifications/get_list.md @@ -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" } }, } ``` @@ -22,6 +23,7 @@ Uses pagination and filtering, user search is only available to admins ```json { "success": true, + "totalCount": 90, "notifications": [ { "_id": "6657edb4d1f06c7b91e39089",