diff --git a/package.json b/package.json index 398f5bd..7b04234 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "backend", - "version": "1.1.5", + "version": "1.1.6", "private": true, "homepage": "https://github.com/movie-web/backend", "engines": { diff --git a/src/routes/users/bookmark.ts b/src/routes/users/bookmark.ts index 4f2b909..feb50ee 100644 --- a/src/routes/users/bookmark.ts +++ b/src/routes/users/bookmark.ts @@ -6,7 +6,6 @@ import { import { StatusError } from '@/services/error'; import { handle } from '@/services/handler'; import { makeRouter } from '@/services/router'; -import { randomUUID } from 'crypto'; import { z } from 'zod'; const bookmarkDataSchema = z.object({ diff --git a/src/routes/users/progress.ts b/src/routes/users/progress.ts index cc3e649..bfd16c5 100644 --- a/src/routes/users/progress.ts +++ b/src/routes/users/progress.ts @@ -6,6 +6,7 @@ import { import { StatusError } from '@/services/error'; import { handle } from '@/services/handler'; import { makeRouter } from '@/services/router'; +import { FilterQuery } from '@mikro-orm/core'; import { randomUUID } from 'crypto'; import { z } from 'zod'; @@ -164,22 +165,28 @@ export const userProgressRouter = makeRouter((app) => { if (auth.user.id !== params.uid) throw new StatusError('Cannot modify user other than yourself', 403); - const progressItem = await em.findOne(ProgressItem, { + const query: FilterQuery = { userId: params.uid, tmdbId: params.tmdbid, - episodeId: body.episodeId, - seasonId: body.seasonId, - }); - if (!progressItem) { + }; + if (body.seasonId) query.seasonId = body.seasonId; + if (body.episodeId) query.episodeId = body.episodeId; + const progressItems = await em.find(ProgressItem, query); + + if (progressItems.length === 0) { return { + count: 0, tmdbId: params.tmdbid, episodeId: body.episodeId, seasonId: body.seasonId, }; } - await em.removeAndFlush(progressItem); + progressItems.forEach((v) => em.remove(v)); + await em.flush(); + return { + count: progressItems.length, tmdbId: params.tmdbid, episodeId: body.episodeId, seasonId: body.seasonId,