From af4a287f322263cc6997822cb23f7b86a4b01e88 Mon Sep 17 00:00:00 2001 From: soyombo Date: Fri, 5 Apr 2024 10:53:20 +0800 Subject: [PATCH] fix(payment): updated invoice query contentType to handle 'cards' contentType --- .../src/graphql/resolvers/queries/invoices.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/plugin-payment-api/src/graphql/resolvers/queries/invoices.ts b/packages/plugin-payment-api/src/graphql/resolvers/queries/invoices.ts index e03a8d09680..e65fcacca7e 100644 --- a/packages/plugin-payment-api/src/graphql/resolvers/queries/invoices.ts +++ b/packages/plugin-payment-api/src/graphql/resolvers/queries/invoices.ts @@ -36,15 +36,7 @@ const generateFilterQuery = (params: IParam) => { query.contentType = contentType; if (contentType.includes('cards')) { - const cardType = contentType.split(':')[1]; - - const lastCharacter = cardType.charAt(cardType.length - 1); - - if (lastCharacter === 's') { - query.contentType = `cards:${cardType.slice(0, -1)}`; - } else { - query.contentType = `cards:${cardType}`; - } + query.contentType = { $in: [contentType, contentType.slice(0, -1)] }; } } @@ -66,10 +58,12 @@ const queries = { page: number; perPage: number; }, - { models }: IContext, + { models }: IContext ) { const selector = generateFilterQuery(params); + console.log('selector', selector); + return paginate(models.Invoices.find(selector).sort({ createdAt: -1 }), { ...params, }); @@ -120,7 +114,7 @@ const queries = { async invoiceDetailByContent( _root, { contentType, contentTypeId }, - { models }: IContext, + { models }: IContext ) { return models.Invoices.find({ contentType, contentTypeId }).lean(); },