From 4086c37b830c3c4141b37052e3c192a750470084 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 20 Oct 2024 16:00:17 +0000 Subject: fix: Improve field names in the tag APIs --- packages/shared/types/tags.ts | 4 ++-- packages/trpc/routers/tags.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'packages') diff --git a/packages/shared/types/tags.ts b/packages/shared/types/tags.ts index 7828c645..54dc3eb5 100644 --- a/packages/shared/types/tags.ts +++ b/packages/shared/types/tags.ts @@ -12,8 +12,8 @@ export type ZBookmarkTags = z.infer; export const zGetTagResponseSchema = z.object({ id: z.string(), name: z.string(), - count: z.number(), - countAttachedBy: z.record(zAttachedByEnumSchema, z.number()), + numBookmarks: z.number(), + numBookmarksByAttachedType: z.record(zAttachedByEnumSchema, z.number()), }); export type ZGetTagResponse = z.infer; diff --git a/packages/trpc/routers/tags.ts b/packages/trpc/routers/tags.ts index c04593c9..c080bad8 100644 --- a/packages/trpc/routers/tags.ts +++ b/packages/trpc/routers/tags.ts @@ -80,7 +80,9 @@ export const tagsAppRouter = router({ throw new TRPCError({ code: "NOT_FOUND" }); } - const countAttachedBy = res.reduce>( + const numBookmarksByAttachedType = res.reduce< + Record + >( (acc, curr) => { if (curr.attachedBy) { acc[curr.attachedBy]++; @@ -93,8 +95,11 @@ export const tagsAppRouter = router({ return { id: res[0].id, name: res[0].name, - count: Object.values(countAttachedBy).reduce((s, a) => s + a, 0), - countAttachedBy, + numBookmarks: Object.values(numBookmarksByAttachedType).reduce( + (s, a) => s + a, + 0, + ), + numBookmarksByAttachedType, }; }), delete: authedProcedure @@ -343,8 +348,8 @@ export const tagsAppRouter = router({ const resp = tags.map(({ tagsOnBookmarks, ...rest }) => ({ ...rest, - count: tagsOnBookmarks.length, - countAttachedBy: tagsOnBookmarks.reduce< + numBookmarks: tagsOnBookmarks.length, + numBookmarksByAttachedType: tagsOnBookmarks.reduce< Record >( (acc, curr) => { -- cgit v1.2.3-70-g09d2