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

Video.isLikedの認証をoptionalに #1030

Merged
merged 1 commit into from
Dec 6, 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
4 changes: 3 additions & 1 deletion src/Video/Video.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type Video implements Node {
events(input: VideoEventsInput!): VideoEventsConnection!
registeredAt: DateTime!

isLiked: Boolean! @auth
"現在ログイン中のユーザがいいね済みかどうか.認証していない場合は`null`"
isLiked: Boolean @auth(optional: true)

like: MylistRegistration @auth

nicovideoSources: [NicovideoVideoSource!]!
Expand Down
10 changes: 7 additions & 3 deletions src/Video/Video.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
}) satisfies VideoResolvers["similarVideos"];

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

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

View workflow job for this annotation

GitHub Actions / Lint

'ctxUser' is defined but never used
const connectionArgs = z
.union([
z.object({
Expand Down Expand Up @@ -166,7 +166,8 @@
neo4j,
logger,
ImagesService,
}: Pick<ResolverDeps, "prisma" | "neo4j" | "logger" | "ImagesService">) =>
VideoService,
}: Pick<ResolverDeps, "prisma" | "neo4j" | "logger" | "ImagesService" | "VideoService">) =>
({
id: ({ id }): string => buildGqlId("Video", id),

Expand Down Expand Up @@ -229,7 +230,10 @@
.then((es) => es.map((e) => new VideoEventDTO(e)));
return { nodes };
},

isLiked: resolveVideoIsLiked({ prisma, logger }),
isLiked: async ({ id: videoId }, _args, { currentUser }) => {
if (!currentUser) return null;
const like = await VideoService.findLike({ videoId, holderId: currentUser.id });
return !!like;
},
like: resolveVideoLike({ prisma, logger }),
}) satisfies Resolvers["Video"];
7 changes: 7 additions & 0 deletions src/Video/Video.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrismaClient } from "@prisma/client";

import { MylistRegistrationModel } from "../resolvers/MylistRegistration/model.js";
import { VideoDTO } from "../Video/dto.js";

export const mkVideoService = ({ prisma }: { prisma: PrismaClient }) => {
Expand Down Expand Up @@ -34,6 +35,12 @@ export const mkVideoService = ({ prisma }: { prisma: PrismaClient }) => {
nodes: nodes.map((v) => VideoDTO.fromPrisma(v)),
};
},
async findLike({ videoId, holderId }: { videoId: string; holderId: string }) {
const registration = await prisma.mylistRegistration.findFirst({
where: { mylist: { slug: "likes", holderId }, videoId, isRemoved: false },
});
return registration ? MylistRegistrationModel.fromPrisma(registration) : null;
},
};
};

Expand Down
Loading