feat: return user data when marking episode as watched

This commit is contained in:
2024-11-14 07:37:04 -05:00
parent 0a07cdc415
commit ce82ae8990
4 changed files with 66 additions and 25 deletions

View File

@@ -8,9 +8,9 @@ import {
EpisodeNumberSchema,
ErrorResponse,
ErrorResponseSchema,
SuccessResponse,
SuccessResponseSchema,
} from "~/types/schema";
import { User } from "~/types/user";
import { markEpisodeAsWatched } from "./anilist";
@@ -39,7 +39,7 @@ const route = createRoute({
200: {
content: {
"application/json": {
schema: SuccessResponseSchema(),
schema: SuccessResponseSchema(User),
},
},
description: "Returns whether the episode was marked as watched",
@@ -78,7 +78,7 @@ app.openapi(route, async (c) => {
await c.req.json<typeof MarkEpisodeAsWatchedRequest._type>();
try {
await markEpisodeAsWatched(
const user = await markEpisodeAsWatched(
aniListToken,
aniListId,
episodeNumber,
@@ -93,13 +93,18 @@ app.openapi(route, async (c) => {
"COMPLETED",
);
}
if (!user) {
console.error("Failed to mark episode as watched - user not found?");
return c.json(ErrorResponse, { status: 500 });
}
return c.json({ success: true, result: user }, 200);
} catch (error) {
console.error("Failed to mark episode as watched");
console.error(error);
return c.json(ErrorResponse, { status: 500 });
}
return c.json(SuccessResponse, 200);
});
export default app;