Skip to content

Commit

Permalink
Merge branch 'dev' into clear-all-notifications-pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanM322 committed Jul 10, 2024
2 parents 40eef87 + e5beb92 commit e2234d9
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 189 deletions.
4 changes: 2 additions & 2 deletions rair-front/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# build environment

FROM node:21.2.0 as build
FROM node:22.4.0 as build

WORKDIR /usr/src/minting

Expand All @@ -22,4 +22,4 @@ COPY --from=build /usr/src/minting/nginx/nginx.conf /etc/nginx/conf.d/default.co
EXPOSE 80

# The default parameters to ENTRYPOINT (unless overruled on the command line)
CMD ["nginx", "-g", "daemon off;"]
CMD ["nginx", "-g", "daemon off;"]
6 changes: 3 additions & 3 deletions rair-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ The benefits of using the Dockerfile are that it uses the latest OFAC list.
* [x] /network/:networkId/:contract/:product
* [x] / - GET - Get the tokens in product ([details](readme/current/nft/nft_manual_product.md))
* [x] /attributes - GET - Get all attributes from the NFTs in a product ([details](readme/current/nft/nft_manual_attributes.md))
* [x] /numbers - GET - Get all tokens numbers in the product ([details](readme/current/nft/nft_manual_numbers.md))
* [x] /files - GET - Get all files associated with the product ([details](readme/current/nft/nft_manual_files.md))
* [x] /files/:token - GET - Get all files associated with a token in the product ([details](readme/current/nft/nft_manual_files_token.md))
* [x] /offers - GET - Get the product data and the offers associated ([details](readme/current/nft/nft_manual_offers.md))
Expand Down Expand Up @@ -180,7 +181,6 @@ The benefits of using the Dockerfile are that it uses the latest OFAC list.
* [x] /tokens
* [x] / - GET - Search tokens ([details](readme/current/tokens/tokens_list.md))
* [x] /id/:id - GET - Get data for a specific token ([details](readme/current/tokens/tokens_single.md))
* [x] /tokenNumbers - GET - Get all tokens on a specific contract and offer ([details](readme/current/tokens/tokens_numbers.md))
* [x] /:token - GET - Get information for a single token ([details](readme/current/tokens/tokens_single_number.md))
* [x] /transaction/:network/:hash - POST - Process a blockchain transaction ([details](readme/current/transactions/transaction_hash.md))
* [x] /users
Expand All @@ -196,8 +196,8 @@ The benefits of using the Dockerfile are that it uses the latest OFAC list.
* [x] /notifications
* [x] / - GET - List of notifications ([details](readme/current/notifications/get_list.md))
* [x] /:id - GET - Get a single notification ([details](readme/current/notifications/get_single.md))
* [x] /:id - PUT - Mark a notification as read ([details](readme/current/notifications/mark_read.md))
* [x] /:id - DELETE - Delete a notification ([details](readme/current/notifications/delete.md))
* [x] / - PUT - Mark a notification as read ([details](readme/current/notifications/mark_read.md))
* [x] / - DELETE - Delete a notification ([details](readme/current/notifications/delete.md))

# Contributors
Valerii Kovalov \
Expand Down
37 changes: 17 additions & 20 deletions rair-node/bin/api/nft/nft.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const {
getUserTokensProfile,
metadataCSVSample,
pinMetadataToIPFS,
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
getProductAttributes,
getTokensForProduct,
getTokenNumbers,
filesForTokenInProduct,
getFilesForProduct,
findOffersForProductMiddleware,
Expand Down Expand Up @@ -55,60 +55,58 @@ router.post(
router.get(
'/network/:networkId/:contract/:product',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
validation(['getTokensByContractProduct', 'resaleFlag', 'metadataSearch'], 'query'),
getTokensForProduct,
);
router.get(
'/network/:networkId/:contract/:product/numbers',
validation(['nftContract', 'nftProduct'], 'params'),
findContractAndProductMiddleware,
getTokenNumbers,
);
router.get(
'/network/:networkId/:contract/:product/attributes',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
getProductAttributes,
);
router.get(
'/network/:networkId/:contract/:product/files/',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
loadUserSession,
getFilesForProduct,
);
router.get(
'/network/:networkId/:contract/:product/files/:token',
validation(['nftContract', 'nftProduct', 'tokenNumber'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
filesForTokenInProduct,
);
router.get(
'/network/:networkId/:contract/:product/offers',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
getOffersForProduct,
);
router.get(
'/network/:networkId/:contract/:product/locks',
validation(['nftContract', 'nftProduct'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
getLockedOffersForProduct,
);
router.get(
'/network/:networkId/:contract/:product/token/:token',
validation(['nftContract', 'nftProduct', 'tokenNumber'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
findOffersForProductMiddleware,
getSingleToken,
);
router.post(
'/network/:networkId/:contract/:product/token/:token',
validation(['nftContract', 'nftProduct', 'tokenNumber'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
findOffersForProductMiddleware,
requireUserSession,
upload.array('files', 2),
Expand All @@ -119,8 +117,7 @@ router.post(
router.post(
'/network/:networkId/:contract/:product/token/:token/pinning',
validation(['nftContract', 'nftProduct', 'tokenNumber'], 'params'),
findContractMiddleware,
findProductMiddleware,
findContractAndProductMiddleware,
findOffersForProductMiddleware,
requireUserSession,
pinSingleTokenMetadata,
Expand Down
117 changes: 93 additions & 24 deletions rair-node/bin/api/nft/nft.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const path = require('path');
const _ = require('lodash');

const fsPromises = fs.promises;
const { ZeroAddress } = require('ethers');
const { addPin, addFolder, addMetadata, removePin, addFile } = require('../../integrations/ipfsService')();
const config = require('../../config');
const log = require('../../utils/logger')(module);
Expand Down Expand Up @@ -313,18 +314,43 @@ module.exports = {
return next(err);
}
},
findContractMiddleware: async (req, res, next) => {
findContractAndProductMiddleware: async (req, res, next) => {
try {
const contract = await Contract.findOne({
contractAddress: req.params.contract.toLowerCase(),
blockchain: req.params.networkId,
});
const { contract, networkId, product } = req.params;
const data = await Contract.aggregate([
{
$match: {
blockchain: networkId,
contractAddress: contract.toLowerCase(),
},
},
{
$lookup: {
from: 'Product',
as: 'productData',
let: { contractId: '$_id' },
pipeline: [
{
$match: {
$expr: {
$eq: ['$$contractId', '$contract'],
},
collectionIndexInContract: product,
},
},
],
},
},
]);

if (!contract) {
return next(new AppError('Contract not found.', 404));
return next(new AppError('Data not found.', 404));
}

req.contract = contract;
const { productData, ...contractData } = data[0];

req.contract = contractData;
[req.product] = productData;

return next();
} catch (e) {
Expand All @@ -347,23 +373,66 @@ module.exports = {
next(err);
}
},
findProductMiddleware: async (req, res, next) => {
try {
const product = await Product.findOne({
contract: req.contract._id,
collectionIndexInContract: req.params.product,
});

if (!product) {
return next(new AppError('Product not found.', 404));
}

req.product = product;

return next();
} catch (e) {
return next(e);
}
getTokenNumbers: async (req, res, next) => {
try {
const { contract, product } = req;
const offerData = await Offer.aggregate([
{
$match: {
$expr: {
$eq: [contract._id, '$contract'],
},
product: product.collectionIndexInContract,
},
},
{
$lookup: {
from: 'MintedToken',
let: { offerIndex: '$diamondRangeIndex' },
as: 'tokens',
pipeline: [{
$match: {
$expr: { $eq: ['$offer', '$$offerIndex'] },
contract: contract._id,
},
},
{
$sort: { uniqueIndexInContract: 1 },
},
{
$addFields: {
sold: {
$cond: {
if: { $eq: ['$ownerAddress', ZeroAddress] },
then: false,
else: true,
},
},
},
},
{
$project: {
_id: 0,
token: 1,
sold: 1,
},
},
],
},
},
{
$project: {
tokens: 1,
},
},
]).collation({ locale: 'en_US', numericOrdering: true });
return res.json({
success: true,
tokens: offerData.reduce((total, offer) => total.concat(offer.tokens), []),
});
} catch (err) {
return next(err);
}
},
getProductAttributes: async (req, res, next) => {
try {
Expand Down
4 changes: 2 additions & 2 deletions rair-node/bin/api/notifications/notifications.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ router.put(
markNotificationAsRead,
);
router.delete(
'/:id',
'/',
requireUserSession,
validation(['dbId'], 'params'),
validation(['dbIdArray'], 'params'),
deleteNotification,
);

Expand Down
9 changes: 3 additions & 6 deletions rair-node/bin/api/notifications/notifications.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ module.exports = {
},
deleteNotification: async (req, res, next) => {
try {
const { id } = req.params;
const notification = await Notification.findByIdAndDelete(id);
if (!notification) {
return next(new AppError('Notification not found', 404));
}
const { ids } = req.body;
const result = await Notification.deleteMany({ _id: { $in: ids } });
return res.json({
success: true,
notification,
deleted: result.deletedCount,
});
} catch (err) {
logger.error(err);
Expand Down
9 changes: 0 additions & 9 deletions rair-node/bin/api/tokens/tokens.Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ const { Router } = require('express');
const {
getSingleToken,
getAllTokens,
getTokenNumbers,
getFullTokenInfo,
} = require('./tokens.Service');
const { getSpecificContracts } = require('../contracts/contracts.Service');
const {
validation,
requireUserSession,
} = require('../../middleware');

const router = Router();
Expand All @@ -20,13 +18,6 @@ router.get(
getAllTokens,
);

router.get(
'/tokenNumbers',
requireUserSession,
validation(['getTokenNumbers'], 'query'),
getTokenNumbers,
);

router.get(
'/:token',
validation(['tokenNumber'], 'params'),
Expand Down
28 changes: 1 addition & 27 deletions rair-node/bin/api/tokens/tokens.Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,6 @@ exports.getOfferPoolByContractAndProduct = async (req, res, next) => {
}
};

exports.getTokenNumbers = async (req, res, next) => {
try {
const { contract, offerPool, offers } = req.query;
const options = {
contract,
};
if (offerPool) {
options.offerPool = offerPool.marketplaceCatalogIndex;
}
if (offers) {
options.offer = { $in: offers };
}
const tokens = await MintedToken.find(options)
.sort([['token', 1]])
.collation({ locale: 'en_US', numericOrdering: true })
.distinct('token');
// handle respond \|/
if (!tokens || tokens.length === 0) {
return next(new AppError('No Tokens found', 404));
}
return res.json({ success: true, tokens });
} catch (err) {
return next(err);
}
};

exports.getAllTokens = async (req, res, next) => {
try {
const { skip, limit, query } = processPaginationQuery(req.query);
Expand All @@ -134,7 +108,7 @@ exports.getAllTokens = async (req, res, next) => {
} catch (err) {
return next(new AppError(err));
}
}
};

exports.updateTokenCommonMetadata = async (req, res, next) => {
try {
Expand Down
3 changes: 1 addition & 2 deletions rair-node/bin/schemas/v2TokenSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ module.exports = {
forceOverwrite: Joi.boolean(),
}),
getTokenNumbers: () => ({
contract: mongoId,
product: Joi.string(),
contract: mongoId.required(),
offerPool: Joi.string(),
offers: Joi.string(),
}),
Expand Down
Loading

0 comments on commit e2234d9

Please sign in to comment.