diff --git a/src/api/controllers/nfts/controller.ts b/src/api/controllers/nfts/controller.ts index a0d6e07..436ae59 100644 --- a/src/api/controllers/nfts/controller.ts +++ b/src/api/controllers/nfts/controller.ts @@ -165,6 +165,58 @@ export class Controller { next(err) } } + + async getMostViewed( + req: Request, + res: Response, + next: NextFunction + ): Promise { + try { + const queryValues = validationGetFilters(req.query) + res.json(await NFTService.getMostViewed(queryValues)); + } catch (err) { + next(err) + } + } + + async getMostSold( + req: Request, + res: Response, + next: NextFunction + ): Promise { + try { + const queryValues = validationGetFilters(req.query) + res.json(await NFTService.getMostSold(queryValues)); + } catch (err) { + next(err) + } + } + + async getMostSoldSeries( + req: Request, + res: Response, + next: NextFunction + ): Promise { + try { + const queryValues = validationGetFilters(req.query) + res.json(await NFTService.getMostSoldSeries(queryValues)); + } catch (err) { + next(err) + } + } + + async getTopSellers( + req: Request, + res: Response, + next: NextFunction + ): Promise { + try { + const queryValues = validationGetFilters(req.query) + res.json(await NFTService.getTopSellers(queryValues)); + } catch (err) { + next(err) + } + } } export default new Controller(); diff --git a/src/api/controllers/nfts/router.ts b/src/api/controllers/nfts/router.ts index 047f105..5379d43 100644 --- a/src/api/controllers/nfts/router.ts +++ b/src/api/controllers/nfts/router.ts @@ -4,9 +4,10 @@ export default express .Router() .get("/", controller.getNFTs) .get("/most-liked", controller.getMostLiked) - // .get("/most-viewed", controller.getMostViewed) - // .get("/most-sold", controller.getMostSold) - // .get("/most-soldSeries", controller.getMostSoldSeries) + .get("/most-viewed", controller.getMostViewed) + .get("/most-sold", controller.getMostSold) + .get("/most-sold-series", controller.getMostSoldSeries) + .get("/top-sellers", controller.getTopSellers) .get("/history", controller.getHistory) .get("/total-on-sale", controller.getTotalOnSale) .get("/:id", controller.getNFT) diff --git a/src/api/services/gqlQueriesBuilder.ts b/src/api/services/gqlQueriesBuilder.ts index 75540e3..218ac13 100644 --- a/src/api/services/gqlQueriesBuilder.ts +++ b/src/api/services/gqlQueriesBuilder.ts @@ -1,6 +1,6 @@ import { gql } from "graphql-request"; -import { convertSortString, LIMIT_MAX_PAGINATION } from "../../utils"; -import { getHistoryQuery, getSeriesStatusQuery, NFTBySeriesQuery, NFTQuery, NFTsQuery, statNFTsUserQuery } from "../validators/nftValidators"; +import { convertSortString, convertSortStringDistinct, LIMIT_MAX_PAGINATION } from "../../utils"; +import { getFiltersQuery, getHistoryQuery, getSeriesStatusQuery, NFTBySeriesQuery, NFTQuery, NFTsQuery, statNFTsUserQuery } from "../validators/nftValidators"; // import L from '../../common/logger'; const nodes = ` @@ -22,7 +22,7 @@ const nodes = ` export class GQLQueriesBuilder { - NFTs = (query: NFTsQuery) => gql` + distinctNFTs = (query: NFTsQuery) => gql` { distinctSerieNfts( first: ${query.pagination?.limit ? query.pagination.limit : LIMIT_MAX_PAGINATION} @@ -35,25 +35,17 @@ export class GQLQueriesBuilder { ${query.filter?.idsToExcludeCategories ? `{id: { notIn: ${JSON.stringify(query.filter.idsToExcludeCategories.map(x => String(x)))} }}` : ""} ${query.filter?.series ? `{serieId: { in: ${JSON.stringify(query.filter.series)} }}` : ""} ${query.filter?.creator ? `{creator: {equalTo: "${query.filter.creator}"}}` : ""} - ${query.filter?.priceStartRange !== undefined ? - `{priceRounded: {greaterThanOrEqualTo: "${query.filter.priceStartRange}"}}` - : ""} - ${query.filter?.priceEndRange !== undefined ? - `{priceRounded: {lessThanOrEqualTo: "${query.filter.priceEndRange}"}}` - : ""} - ${query.filter?.timestampCreateStartRange !== undefined ? - `{timestampCreate: {greaterThanOrEqualTo: "${query.filter.timestampCreateStartRange}"}}` - : ""} - ${query.filter?.timestampCreateEndRange !== undefined ? - `{timestampCreate: {lessThanOrEqualTo: "${query.filter.timestampCreateEndRange}"}}` - : ""} ] } ${query.filter?.owner ? `owner: "${query.filter.owner}"` : ""} ${query.filter?.marketplaceId!==undefined ? `marketplaceId: "${query.filter.marketplaceId}"` : ""} ${query.filter?.listed!==undefined ? `listed: ${!query.filter.listed ? 0 : 1}` : ""} ${query.filter?.isCapsule!==undefined ? `isCapsule: ${!query.filter.isCapsule ? false : true}` : ""} - ${query.sort ? `orderBy: [${convertSortString(query.sort)}]` : ""} + ${query.filter?.priceStartRange!==undefined ? `priceStartRange: ${query.filter.priceStartRange}` : ""} + ${query.filter?.priceEndRange!==undefined ? `priceEndRange: ${query.filter.priceEndRange}` : ""} + ${query.filter?.timestampCreateStartRange!==undefined ? `timestampCreateStartRange: ${query.filter.timestampCreateStartRange}` : ""} + ${query.filter?.timestampCreateEndRange!==undefined ? `timestampCreateEndRange: ${query.filter.timestampCreateEndRange}` : ""} + ${query.sort ? convertSortStringDistinct(query.sort) : ""} ) { totalCount pageInfo { @@ -65,6 +57,41 @@ export class GQLQueriesBuilder { } `; + NFTs = (query: NFTsQuery) => gql` + { + nftEntities( + first: ${query.pagination?.limit ? query.pagination.limit : LIMIT_MAX_PAGINATION} + offset: ${query.pagination?.page && query.pagination?.limit ? (query.pagination.page - 1) * query.pagination.limit : 0} + filter:{ + and:[ + ${query.filter?.ids ? `{id: { in: ${JSON.stringify(query.filter.ids.map(x => String(x)))} }}` : ""} + ${query.filter?.idsToExclude ? `{id: { notIn: ${JSON.stringify(query.filter.idsToExclude.map(x => String(x)))} }}` : ""} + ${query.filter?.idsCategories ? `{id: { in: ${JSON.stringify(query.filter.idsCategories.map(x => String(x)))} }}` : ""} + ${query.filter?.idsToExcludeCategories ? `{id: { notIn: ${JSON.stringify(query.filter.idsToExcludeCategories.map(x => String(x)))} }}` : ""} + ${query.filter?.series ? `{serieId: { in: ${JSON.stringify(query.filter.series)} }}` : ""} + ${query.filter?.creator ? `{creator: {equalTo: "${query.filter.creator}"}}` : ""} + ${query.filter?.owner ? `{owner: {equalTo: "${query.filter.owner}"}}` : ""} + ${query.filter?.marketplaceId ? `{marketplaceId: {equalTo: "${query.filter.marketplaceId}"}}` : ""} + ${query.filter?.listed ? `{listed: {equalTo: ${!query.filter.listed ? 0 : 1}}}` : ""} + ${query.filter?.isCapsule ? `{isCapsule: {equalTo: ${!query.filter.isCapsule ? 0 : 1}}}` : ""} + ${query.filter?.priceStartRange ? `{priceRounded: {greaterThanOrEqualTo: ${query.filter.priceStartRange}}}` : ""} + ${query.filter?.priceEndRange ? `{priceRounded: {lessThanOrEqualTo: ${query.filter.priceEndRange}}}` : ""} + ${query.filter?.timestampCreateStartRange ? `{timestampCreate: {greaterThanOrEqualTo: "${query.filter.priceStartRange}"}}` : ""} + ${query.filter?.timestampCreateEndRange ? `{timestampCreate: {lessThanOrEqualTo: "${query.filter.timestampCreateEndRange}"}}` : ""} + ] + } + ${query.sort ? convertSortString(query.sort) : ""} + ) { + totalCount + pageInfo { + hasNextPage + hasPreviousPage + } + ${nodes} + } + } +`; + NFTfromId = (query: NFTQuery) => gql` { nftEntities( @@ -219,7 +246,7 @@ export class GQLQueriesBuilder { first: ${query.pagination.limit} offset: ${(query.pagination.page - 1) * query.pagination.limit} ` : ""} - orderBy: ${query.sort ? `[${convertSortString(query.sort)}]` : "TIMESTAMP_DESC"} + orderBy: ${query.sort ? `[${convertSortStringDistinct(query.sort)}]` : "TIMESTAMP_DESC"} filter: {and:[ ${query.filter?.onlyNftId ? `{nftId: {equalTo: "${query.filter.nftId}"}}` @@ -399,6 +426,67 @@ countAllListedInMarketplace = (marketplaceId: number) => gql` } `; +getMostSold = (query: getFiltersQuery) => gql` + { + mostSold( + first: ${query.pagination?.limit ? query.pagination.limit : LIMIT_MAX_PAGINATION} + offset: ${query.pagination?.page && query.pagination?.limit ? (query.pagination.page - 1) * query.pagination.limit : 0} + typeOfTransaction: "sale" + orderBy: OCCURENCES_DESC + ) { + totalCount + pageInfo { + hasNextPage + hasPreviousPage + } + nodes { + id + occurences + } + } + } +`; + +getMostSoldSeries = (query: getFiltersQuery) => gql` + { + mostSoldSeries( + first: ${query.pagination?.limit ? query.pagination.limit : LIMIT_MAX_PAGINATION} + offset: ${query.pagination?.page && query.pagination?.limit ? (query.pagination.page - 1) * query.pagination.limit : 0} + typeOfTransaction: "sale" + orderBy: OCCURENCES_DESC + ) { + totalCount + pageInfo { + hasNextPage + hasPreviousPage + } + nodes { + id + occurences + } + } + } +`; + +getTopSellers = (query: getFiltersQuery) => gql` + { + topSeller( + first: ${query.pagination?.limit ? query.pagination.limit : LIMIT_MAX_PAGINATION} + offset: ${query.pagination?.page && query.pagination?.limit ? (query.pagination.page - 1) * query.pagination.limit : 0} + orderBy: OCCURENCES_DESC + ) { + totalCount + pageInfo { + hasNextPage + hasPreviousPage + } + nodes { + id + occurences + } + } + } +`; } export default new GQLQueriesBuilder(); diff --git a/src/api/services/nft.ts b/src/api/services/nft.ts index e06c2e9..0873c3f 100644 --- a/src/api/services/nft.ts +++ b/src/api/services/nft.ts @@ -1,4 +1,5 @@ import { request } from "graphql-request"; +import fetch from "node-fetch"; import { DistinctNFTListResponse, INFT, NFTListResponse, CustomResponse, ISeries, INFTTransfer } from "../../interfaces/graphQL"; import FollowModel from "../../models/follow"; import NftModel from "../../models/nft"; @@ -7,11 +8,12 @@ import NftLikeModel from "../../models/nftLike"; import CategoryService from "./category" import { populateNFT } from "../helpers/nftHelpers"; import QueriesBuilder from "./gqlQueriesBuilder"; -import { decryptCookie, TIME_BETWEEN_SAME_USER_VIEWS } from "../../utils"; +import { decryptCookie, TERNOA_API_URL, TIME_BETWEEN_SAME_USER_VIEWS } from "../../utils"; import { canAddToSeriesQuery, addCategoriesNFTsQuery, getHistoryQuery, getSeriesStatusQuery, NFTBySeriesQuery, NFTQuery, NFTsQuery, statNFTsUserQuery, getTotalOnSaleQuery, likeUnlikeQuery, getFiltersQuery } from "../validators/nftValidators"; import CategoryModel from "../../models/category"; import { ICategory } from "../../interfaces/ICategory"; import { INftLike } from "src/interfaces/INftLike"; +import { IUser } from "src/interfaces/IUser"; const indexerUrl = process.env.INDEXER_URL || "https://indexer.chaos.ternoa.com"; @@ -29,7 +31,7 @@ export class NFTService { // Liked only if (query.filter?.liked) await this.handleFilterLikedOnly(query) /// Indexer data - const gqlQuery = QueriesBuilder.NFTs(query); + const gqlQuery = QueriesBuilder.distinctNFTs(query); const res: DistinctNFTListResponse = await request(indexerUrl, gqlQuery); const NFTs = res.distinctSerieNfts.nodes; // Populate @@ -38,12 +40,11 @@ export class NFTService { const result: CustomResponse = { totalCount: res.distinctSerieNfts.totalCount, data: res.distinctSerieNfts.nodes, - hasNextPage: res.distinctSerieNfts.pageInfo?.hasNextPage || undefined, - hasPreviousPage: res.distinctSerieNfts.pageInfo?.hasPreviousPage || undefined + hasNextPage: res.distinctSerieNfts.pageInfo?.hasNextPage, + hasPreviousPage: res.distinctSerieNfts.pageInfo?.hasPreviousPage } return result } catch (err) { - console.log(err) throw new Error("Couldn't get NFTs"); } } @@ -231,8 +232,8 @@ export class NFTService { const result: CustomResponse = { totalCount: res.nftEntities.totalCount, data: seriesData, - hasNextPage: res.nftEntities.pageInfo?.hasNextPage || undefined, - hasPreviousPage: res.nftEntities.pageInfo?.hasPreviousPage || undefined + hasNextPage: res.nftEntities.pageInfo?.hasNextPage, + hasPreviousPage: res.nftEntities.pageInfo?.hasPreviousPage } return result } catch (err) { @@ -330,8 +331,8 @@ export class NFTService { const result: CustomResponse = { totalCount: res.nftTransferEntities.totalCount, data: query.filter?.grouped ? data : res.nftTransferEntities.nodes, - hasNextPage: res.nftTransferEntities.pageInfo?.hasNextPage || undefined, - hasPreviousPage: res.nftTransferEntities.pageInfo?.hasPreviousPage || undefined + hasNextPage: res.nftTransferEntities.pageInfo?.hasNextPage, + hasPreviousPage: res.nftTransferEntities.pageInfo?.hasPreviousPage } return result } catch (err) { @@ -395,32 +396,155 @@ export class NFTService { * @param query - see getFiltersQuery * @throws Will throw an error if mongo can't be reached */ - async getMostLiked(query: getFiltersQuery): Promise> { - try { - const aggregateQuery = [{ $group: { _id: "$serieId", totalLikes: { $sum: 1 } } }] - const aggregate = NftLikeModel.aggregate(aggregateQuery); - const data = await NftLikeModel.aggregatePaginate(aggregate, {page: query.pagination.page, limit: query.pagination.limit, sort:{totalLikes: -1}}) - const seriesSorted = data.docs.map(x => x._id) - const queryNfts = {filter:{series: seriesSorted}} - const gqlQuery = QueriesBuilder.NFTs(queryNfts); - const res: DistinctNFTListResponse = await request(indexerUrl, gqlQuery); - const NFTs = res.distinctSerieNfts.nodes; - res.distinctSerieNfts.nodes = await Promise.all(NFTs.map(async (NFT) => populateNFT(NFT, query))) - const result: CustomResponse = { - totalCount: data.totalDocs, - data: NFTs.sort((a,b) => { - const aId = seriesSorted.findIndex(x => x === a.serieId) - const bId = seriesSorted.findIndex(x => x === b.serieId) - return aId - bId - }), - hasNextPage: data.hasNextPage || undefined, - hasPreviousPage: data.hasPrevPage || undefined - } - return result - } catch (err) { - throw new Error("Couldn't get most liked NFTs"); + async getMostLiked(query: getFiltersQuery): Promise> { + try { + const aggregateQuery = [{ $group: { _id: "$serieId", totalLikes: { $sum: 1 } } }] + const aggregate = NftLikeModel.aggregate(aggregateQuery); + const data = await NftLikeModel.aggregatePaginate(aggregate, {page: query.pagination.page, limit: query.pagination.limit, sort:{totalLikes: -1}}) + const seriesSorted = data.docs.map(x => x._id) + const queryNfts = {filter:{series: seriesSorted}} + const gqlQuery = QueriesBuilder.distinctNFTs(queryNfts); + const res: DistinctNFTListResponse = await request(indexerUrl, gqlQuery); + const NFTs = await Promise.all(res.distinctSerieNfts.nodes.map(async (NFT) => populateNFT(NFT, query))); + const result: CustomResponse = { + totalCount: data.totalDocs, + data: NFTs.sort((a,b) => { + const aId = seriesSorted.findIndex(x => x === a.serieId) + const bId = seriesSorted.findIndex(x => x === b.serieId) + return aId - bId + }), + hasNextPage: data.hasNextPage, + hasPreviousPage: data.hasPrevPage } + return result + } catch (err) { + throw new Error("Couldn't get most liked NFTs"); } + } + + /** + * Get NFTs sorted by views + * @param query - see getFiltersQuery + * @throws Will throw an error if mongo can't be reached + */ + async getMostViewed(query: getFiltersQuery): Promise> { + try { + const aggregateQuery = [{ $group: { _id: "$viewedSerie", totalViews: { $sum: 1 } } }] + const aggregate = NftViewModel.aggregate(aggregateQuery); + const data = await NftViewModel.aggregatePaginate(aggregate, {page: query.pagination.page, limit: query.pagination.limit, sort:{totalViews: -1}}) + const seriesSorted = data.docs.map(x => x._id) + const queryNfts = {filter:{series: seriesSorted}} + const gqlQuery = QueriesBuilder.distinctNFTs(queryNfts); + const res: DistinctNFTListResponse = await request(indexerUrl, gqlQuery); + const NFTs = await Promise.all(res.distinctSerieNfts.nodes.map(async (NFT) => populateNFT(NFT, query))); + const result: CustomResponse = { + totalCount: data.totalDocs, + data: NFTs.sort((a,b) => { + const aId = seriesSorted.findIndex(x => x === a.serieId) + const bId = seriesSorted.findIndex(x => x === b.serieId) + return aId - bId + }), + hasNextPage: data.hasNextPage, + hasPreviousPage: data.hasPrevPage + } + return result + } catch (err) { + throw new Error("Couldn't get most viewed NFTs"); + } + } + + /** + * Get NFTs sorted by most sold + * @param query - see getFiltersQuery + * @throws Will throw an error if indexer can't be reached + */ + async getMostSold(query: getFiltersQuery): Promise> { + try { + const gqlQuery = QueriesBuilder.getMostSold(query); + const res = await request(indexerUrl, gqlQuery); + const mostSold: {id: string, occurences: number}[] = res.mostSold.nodes; + const mostSoldIdsSorted = mostSold.map(x => x.id) + const queryNfts = {filter:{ids: mostSoldIdsSorted}} + const gqlQueryFinal = QueriesBuilder.NFTs(queryNfts); + const resFinal: NFTListResponse = await request(indexerUrl, gqlQueryFinal); + const NFTs = await Promise.all(resFinal.nftEntities.nodes.map(async (NFT) => populateNFT(NFT, query))); + const result: CustomResponse = { + totalCount: res.mostSold.totalCount, + data: NFTs.sort((a,b) => { + const aId = mostSoldIdsSorted.findIndex(x => x === a.id) + const bId = mostSoldIdsSorted.findIndex(x => x === b.id) + return aId - bId + }), + hasNextPage: res.mostSold.pageInfo.hasNextPage, + hasPreviousPage: res.mostSold.pageInfo.hasPreviousPage + } + return result + } catch (err) { + throw new Error("Couldn't get most sold NFTs"); + } + } + + /** + * Get NFTs sorted by most sold series + * @param query - see getFiltersQuery + * @throws Will throw an error if indexer can't be reached + */ + async getMostSoldSeries(query: getFiltersQuery): Promise> { + try { + const gqlQuery = QueriesBuilder.getMostSoldSeries(query); + const res = await request(indexerUrl, gqlQuery); + const mostSoldSeries: {id: string, occurences: number}[] = res.mostSoldSeries.nodes; + const mostSoldSeriesSorted = mostSoldSeries.map(x => x.id) + const queryNfts = {filter:{series: mostSoldSeriesSorted}} + const gqlQueryFinal = QueriesBuilder.distinctNFTs(queryNfts); + const resFinal: DistinctNFTListResponse = await request(indexerUrl, gqlQueryFinal); + const NFTs = await Promise.all(resFinal.distinctSerieNfts.nodes.map(async (NFT) => populateNFT(NFT, query))); + const result: CustomResponse = { + totalCount: res.mostSoldSeries.totalCount, + data: NFTs.sort((a,b) => { + const aId = mostSoldSeriesSorted.findIndex(x => x === a.serieId) + const bId = mostSoldSeriesSorted.findIndex(x => x === b.serieId) + return aId - bId + }), + hasNextPage: res.mostSoldSeries.pageInfo.hasNextPage, + hasPreviousPage: res.mostSoldSeries.pageInfo.hasPreviousPage + } + return result + } catch (err) { + throw new Error("Couldn't get most sold series"); + } + } + + /** + * Get top sellers account address sorted by best sellers + * @param query - see getFiltersQuery + * @throws Will throw an error if indexer or db can't be reached + */ + async getTopSellers(query: getFiltersQuery): Promise> { + try { + const gqlQuery = QueriesBuilder.getTopSellers(query); + const res = await request(indexerUrl, gqlQuery); + const topSellers: {id: string, occurences: number}[] = res.topSeller.nodes; + const topSellersSorted = topSellers.map(x => x.id) + const filterDbUser = {walletIds: topSellersSorted} + const resDbUsers = await fetch(`${TERNOA_API_URL}/api/users/?filter=${JSON.stringify(filterDbUser)}`) + const dbUsers: CustomResponse = await resDbUsers.json() + const data = topSellersSorted.map(x => { + let user = dbUsers.data.find(y => y.walletId === x) + if (user === undefined) user = {_id: x, walletId: x} + return user + }) + const result: CustomResponse = { + totalCount: res.topSeller.totalCount, + data, + hasNextPage: res.topSeller.pageInfo.hasNextPage, + hasPreviousPage: res.topSeller.pageInfo.hasPreviousPage + } + return result + } catch (err) { + throw new Error("Couldn't get top sellers"); + } + } } export default new NFTService(); diff --git a/src/api/validators/nftValidators.ts b/src/api/validators/nftValidators.ts index ea595bc..ecfdf67 100644 --- a/src/api/validators/nftValidators.ts +++ b/src/api/validators/nftValidators.ts @@ -21,10 +21,10 @@ export type NFTsQuery = { categories?: string[] owner?: string creator?: string - priceStartRange?: string - priceEndRange?: string - timestampCreateStartRange?: string, - timestampCreateEndRange?: string, + priceStartRange?: number + priceEndRange?: number + timestampCreateStartRange?: Date, + timestampCreateEndRange?: Date, seriesLocked?: boolean isCapsule?: boolean } @@ -51,10 +51,10 @@ export const validationGetNFTs = (query: any) => { categories: Joi.array().items(Joi.string()), owner: Joi.string(), creator: Joi.string(), - priceStartRange: Joi.string(), - priceEndRange: Joi.string(), - timestampCreateStartRange: Joi.string(), - timestampCreateEndRange: Joi.string(), + priceStartRange: Joi.number(), + priceEndRange: Joi.number(), + timestampCreateStartRange: Joi.date(), + timestampCreateEndRange: Joi.date(), seriesLocked: Joi.boolean(), isCapsule: Joi.boolean(), }), diff --git a/src/utils/index.ts b/src/utils/index.ts index 2e5dc83..f35b7a1 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -60,8 +60,8 @@ export const decryptCookie = (cookie: string) => { export const convertSortString = (sortString: string) => { if (sortString) { - const sortArray = sortString.split(","); - let finalString = ""; + const sortArray = sortString.split(",") + let finalString = "" sortArray.forEach((x) => { const fieldArray = x.split(":"); if (fieldArray[0]) { @@ -70,7 +70,49 @@ export const convertSortString = (sortString: string) => { },`; } }); - return finalString; + return finalString + } else { + return ""; + } +}; + +export const convertSortStringDistinct = (sortString: string) => { + if (sortString) { + const pluginFilters = ["TIMESTAMP_CREATE", "PRICE", "PRICE_ROUNDED", "LISTED", "IS_CAPSULE"] + const sortArray = sortString.split(",") + let regularFilterString = "" + let customFilterString = "" + sortArray.forEach((x) => { + const fieldArray = x.split(":"); + if (fieldArray[0]) { + if (!pluginFilters.includes(fieldArray[0])){ + regularFilterString += `${fieldArray[0].toUpperCase()}_${ + fieldArray[1] ? fieldArray[1].toUpperCase() : "ASC" + },`; + }else{ + switch(fieldArray[0]){ + case "LISTED": + customFilterString += `listedSortOrder: ${fieldArray[1] ? fieldArray[1].toLowerCase() : "desc"} `; + break; + case "IS_CAPSULE": + customFilterString += `isCapsuleSortOrder: ${fieldArray[1] ? fieldArray[1].toLowerCase() : "asc"} `; + break; + case "TIMESTAMP_CREATE": + customFilterString += `timestampCreateSortOrder: ${fieldArray[1] ? fieldArray[1].toLowerCase() : "desc"} `; + break; + case "PRICE" || "PRICE_ROUNDED": + customFilterString += `priceSortOrder: ${fieldArray[1] ? fieldArray[1].toLowerCase() : "asc"} `; + break; + default: + break; + } + } + } + }); + return ` + ${customFilterString.length > 0 ? customFilterString : ""} + ${regularFilterString.length > 0 ? `orderBy: [${regularFilterString}]` : ""} + `; } else { return ""; }