Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag.totalTaggedVideosの実装 #968

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Tag/Tag.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type Tag implements Node {
categoryTag: Boolean
): TagParentConnection!

totalTaggedVideos: Int!

taggedVideos(
first: Int
after: String
Expand Down
2 changes: 2 additions & 0 deletions src/Tag/Tag.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(async (
{ id: tagId, isCategoryTag },
{ orderBy: unparsedOrderBy, ...unparsedConnectionArgs },
{ currentUser: ctxUser },

Check warning on line 19 in src/Tag/Tag.resolver.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/Tag/Tag.resolver.ts#L19

[@typescript-eslint/no-unused-vars] 'ctxUser' is defined but never used.
info,
) => {
const connectionArgs = z
Expand Down Expand Up @@ -64,7 +64,7 @@
(async (
{ id: tagId },
{ orderBy: unparsedOrderBy, categoryTag, ...unparsedConnectionArgs },
{ currentUser: ctxUser },

Check warning on line 67 in src/Tag/Tag.resolver.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/Tag/Tag.resolver.ts#L67

[@typescript-eslint/no-unused-vars] 'ctxUser' is defined but never used.
info,
) => {
const connectionArgs = z
Expand Down Expand Up @@ -114,7 +114,7 @@
}) satisfies TagResolvers["parents"];

export const resolveTaggedVideos = ({ prisma, logger }: Pick<ResolverDeps, "prisma" | "logger">) =>
(async ({ id: tagId }, { orderBy: unparsedOrderBy, ...unparsedConnectionArgs }, { currentUser: ctxUser }, info) => {

Check warning on line 117 in src/Tag/Tag.resolver.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

src/Tag/Tag.resolver.ts#L117

[@typescript-eslint/no-unused-vars] 'ctxUser' is defined but never used.
const connectionArgs = z
.union([
z.object({
Expand Down Expand Up @@ -216,6 +216,8 @@
},
children: resolverChildren({ prisma, logger }),

totalTaggedVideos: ({ id: tagId }) => TagsService.totalTaggedVideos(tagId),

taggedVideos: resolveTaggedVideos({ prisma, logger }),

taggedVideosByOffset: async ({ id: tagId }, { input: { offset, take, orderBy: unparsedOrderBy } }, _ctx, info) => {
Expand Down
3 changes: 3 additions & 0 deletions src/Tag/Tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const mkTagService = ({ prisma }: { prisma: PrismaClient }) => {
countAll() {
return prisma.tag.count();
},
async totalTaggedVideos(tagId: string) {
return prisma.videoTag.count({ where: { tagId } });
},
async taggedVideosByOffset(
tagId: string,
{ offset, take, orderBy }: { offset: number; take: number; orderBy: { createdAt?: "desc" | "asc" } },
Expand Down