Merge pull request #23 from movie-web/fix-show-delete
Fix show deletion
This commit is contained in:
commit
d84cdc4239
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "backend",
|
"name": "backend",
|
||||||
"version": "1.1.5",
|
"version": "1.1.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"homepage": "https://github.com/movie-web/backend",
|
"homepage": "https://github.com/movie-web/backend",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
import { StatusError } from '@/services/error';
|
import { StatusError } from '@/services/error';
|
||||||
import { handle } from '@/services/handler';
|
import { handle } from '@/services/handler';
|
||||||
import { makeRouter } from '@/services/router';
|
import { makeRouter } from '@/services/router';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const bookmarkDataSchema = z.object({
|
const bookmarkDataSchema = z.object({
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
import { StatusError } from '@/services/error';
|
import { StatusError } from '@/services/error';
|
||||||
import { handle } from '@/services/handler';
|
import { handle } from '@/services/handler';
|
||||||
import { makeRouter } from '@/services/router';
|
import { makeRouter } from '@/services/router';
|
||||||
|
import { FilterQuery } from '@mikro-orm/core';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
@ -164,22 +165,28 @@ export const userProgressRouter = makeRouter((app) => {
|
||||||
if (auth.user.id !== params.uid)
|
if (auth.user.id !== params.uid)
|
||||||
throw new StatusError('Cannot modify user other than yourself', 403);
|
throw new StatusError('Cannot modify user other than yourself', 403);
|
||||||
|
|
||||||
const progressItem = await em.findOne(ProgressItem, {
|
const query: FilterQuery<ProgressItem> = {
|
||||||
userId: params.uid,
|
userId: params.uid,
|
||||||
tmdbId: params.tmdbid,
|
tmdbId: params.tmdbid,
|
||||||
episodeId: body.episodeId,
|
};
|
||||||
seasonId: body.seasonId,
|
if (body.seasonId) query.seasonId = body.seasonId;
|
||||||
});
|
if (body.episodeId) query.episodeId = body.episodeId;
|
||||||
if (!progressItem) {
|
const progressItems = await em.find(ProgressItem, query);
|
||||||
|
|
||||||
|
if (progressItems.length === 0) {
|
||||||
return {
|
return {
|
||||||
|
count: 0,
|
||||||
tmdbId: params.tmdbid,
|
tmdbId: params.tmdbid,
|
||||||
episodeId: body.episodeId,
|
episodeId: body.episodeId,
|
||||||
seasonId: body.seasonId,
|
seasonId: body.seasonId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await em.removeAndFlush(progressItem);
|
progressItems.forEach((v) => em.remove(v));
|
||||||
|
await em.flush();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
count: progressItems.length,
|
||||||
tmdbId: params.tmdbid,
|
tmdbId: params.tmdbid,
|
||||||
episodeId: body.episodeId,
|
episodeId: body.episodeId,
|
||||||
seasonId: body.seasonId,
|
seasonId: body.seasonId,
|
||||||
|
|
Loading…
Reference in New Issue