Skip to content

Commit

Permalink
Merge pull request rairprotocol#110 from rairprotocol/109-start-and-e…
Browse files Browse the repository at this point in the history
…nd-limits-to-token-numbers-endpoint

109 - start and end limits to token numbers endpoint
  • Loading branch information
sarora180673 authored Jul 12, 2024
2 parents 8568f7d + bb4856a commit 84716ad
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
3 changes: 2 additions & 1 deletion rair-node/bin/api/nft/nft.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ router.get(
'/network/:networkId/:contract/:product',
validation(['nftContract', 'nftProduct'], 'params'),
findContractAndProductMiddleware,
validation(['getTokensByContractProduct', 'resaleFlag', 'metadataSearch'], 'query'),
validation(['getTokensByContractProduct', 'resaleFlag', 'metadataSearch', 'tokenLimits'], 'query'),
getTokensForProduct,
);
router.get(
'/network/:networkId/:contract/:product/numbers',
validation(['nftContract', 'nftProduct'], 'params'),
validation(['tokenLimits'], 'query'),
findContractAndProductMiddleware,
getTokenNumbers,
);
Expand Down
25 changes: 24 additions & 1 deletion rair-node/bin/api/nft/nft.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,22 @@ module.exports = {
getTokenNumbers: async (req, res, next) => {
try {
const { contract, product } = req;
const { fromToken, toToken } = req.query;
const tokenLimitFilter = [];
if (fromToken) {
tokenLimitFilter.push(
{
$gte: ['$token', fromToken],
},
);
}
if (toToken) {
tokenLimitFilter.push(
{
$lte: ['$token', toToken],
},
);
}
const offerData = await Offer.aggregate([
{
$match: {
Expand All @@ -392,7 +408,14 @@ module.exports = {
as: 'tokens',
pipeline: [{
$match: {
$expr: { $eq: ['$offer', '$$offerIndex'] },
$expr: {
$and: [
{
$eq: ['$offer', '$$offerIndex'],
},
...tokenLimitFilter,
],
},
contract: contract._id,
},
},
Expand Down
4 changes: 4 additions & 0 deletions rair-node/bin/schemas/commonApiSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ module.exports = {
metadataSearch: () => ({
metadataFilters: Joi.string(),
}),
tokenLimits: () => ({
fromToken: Joi.string(),
toToken: Joi.string(),
}),
};
2 changes: 0 additions & 2 deletions rair-node/bin/schemas/getTokensByContractProduct.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const Joi = require('joi');

module.exports = () => ({
fromToken: Joi.string(),
toToken: Joi.string(),
limit: Joi.number(),
forSale: Joi.any()
.valid('true', 'false'),
Expand Down
2 changes: 2 additions & 0 deletions rair-node/bin/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const {
userAddress,
resaleFlag,
metadataSearch,
tokenLimits,
} = require('./commonApiSchemas');
const {
fullContracts,
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
userAddress,
resaleFlag,
metadataSearch,
tokenLimits,

// Contract schemas
fullContracts,
Expand Down

0 comments on commit 84716ad

Please sign in to comment.