Skip to content

Commit

Permalink
Add Query.tokensCount
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikearaya committed Dec 28, 2024
1 parent 455e7c3 commit bf24779
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/api/src/resolvers/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import warehousingProviders from './warehousing/warehousingProviders.js';
import warehousingProvidersCount from './warehousing/warehousingProvidersCount.js';
import token from './warehousing/token.js';
import tokens from './warehousing/tokens.js';
import tokensCount from './warehousing/tokensCount.js';
import work from './worker/work.js';
import workQueue from './worker/workQueue.js';
import workStatistics from './worker/workStatistics.js';
Expand Down Expand Up @@ -104,6 +105,7 @@ export default {
warehousingInterfaces: acl(actions.viewWarehousingInterfaces)(warehousingInterfaces),
token: acl(actions.viewToken)(token),
tokens: acl(actions.viewTokens)(tokens),
tokensCount: acl(actions.viewTokens)(tokensCount),
translatedProductTexts: acl(actions.viewTranslations)(translatedProductTexts),
translatedProductMediaTexts: acl(actions.viewTranslations)(translatedProductMediaTexts),
translatedProductVariationTexts: acl(actions.viewTranslations)(translatedProductVariationTexts),
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/resolvers/queries/warehousing/tokensCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { log } from '@unchainedshop/logger';
import { Context } from '../../../context.js';

export default async function tokensCount(root: never, _, { modules, userId }: Context) {
log(`query tokensCount`, { userId });

return modules.warehousing.tokensCount();
}
5 changes: 5 additions & 0 deletions packages/api/src/schema/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ export default [
"""
tokens(limit: Int = 10, offset: Int = 0): [Token!]!
"""
Returns total tokens
"""
tokensCount: Int!
"""
Returns total number of payment providers, optionally filtered by type
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const configureWarehousingModule = async ({ db }: ModuleInput<Record<stri
return TokenSurrogates.find(selector, options).toArray();
},

tokensCount: async (): Promise<number> => {
const tokenCount = await TokenSurrogates.countDocuments();
return tokenCount;
},

findTokensForUser: async (
params: { userId: string } | { walletAddresses: string[] },
options?: mongodb.FindOptions,
Expand Down

0 comments on commit bf24779

Please sign in to comment.