mirror of
https://github.com/p-stream/backend.git
synced 2026-01-11 20:10:33 +00:00
Fixed up the lists, looking much nicer and it should be perfectly ready
This commit is contained in:
parent
3be055bb48
commit
9e3959b2fc
4 changed files with 17 additions and 4 deletions
|
|
@ -0,0 +1,2 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "list_items" ADD COLUMN "type" VARCHAR(255);
|
||||
|
|
@ -95,6 +95,7 @@ model list_items {
|
|||
id String @id @db.Uuid @default(uuid())
|
||||
list_id String @db.Uuid
|
||||
tmdb_id String @db.VarChar(255)
|
||||
type String? @db.VarChar(255)
|
||||
added_at DateTime @default(now()) @db.Timestamptz(0)
|
||||
list lists @relation(fields: [list_id], references: [id])
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@ import { z } from "zod";
|
|||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
// Schema for validating the request body
|
||||
const listItemSchema = z.object({
|
||||
tmdb_id: z.string(),
|
||||
type: z.enum(["movie", "tv"]),
|
||||
});
|
||||
|
||||
const updateListSchema = z.object({
|
||||
list_id: z.string().uuid(),
|
||||
name: z.string().min(1).max(255).optional(),
|
||||
description: z.string().max(255).optional().nullable(),
|
||||
public: z.boolean().optional(),
|
||||
addItems: z.array(listItemSchema).optional(),
|
||||
removeItems: z.array(listItemSchema).optional(),
|
||||
});
|
||||
|
|
@ -51,15 +52,20 @@ export default defineEventHandler(async (event) => {
|
|||
}
|
||||
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
if (validatedBody.name || validatedBody.description !== undefined) {
|
||||
if (
|
||||
validatedBody.name ||
|
||||
validatedBody.description !== undefined ||
|
||||
validatedBody.public !== undefined
|
||||
) {
|
||||
await tx.lists.update({
|
||||
where: { id: list.id },
|
||||
data: {
|
||||
name: validatedBody.name || list.name,
|
||||
name: validatedBody.name ?? list.name,
|
||||
description:
|
||||
validatedBody.description !== undefined
|
||||
? validatedBody.description
|
||||
: list.description,
|
||||
public: validatedBody.public ?? list.public,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -76,6 +82,7 @@ export default defineEventHandler(async (event) => {
|
|||
data: itemsToAdd.map((item) => ({
|
||||
list_id: list.id,
|
||||
tmdb_id: item.tmdb_id,
|
||||
type: item.type,
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@ import { z } from "zod";
|
|||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
// Schema for validating the request body
|
||||
const listItemSchema = z.object({
|
||||
tmdb_id: z.string(),
|
||||
type: z.enum(["movie", "tv"]),
|
||||
});
|
||||
|
||||
const createListSchema = z.object({
|
||||
name: z.string().min(1).max(255),
|
||||
description: z.string().max(255).optional().nullable(),
|
||||
items: z.array(listItemSchema).optional(),
|
||||
public: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
|
@ -46,6 +47,7 @@ export default defineEventHandler(async (event) => {
|
|||
user_id: userId,
|
||||
name: validatedBody.name,
|
||||
description: validatedBody.description || null,
|
||||
public: validatedBody.public || false,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -54,6 +56,7 @@ export default defineEventHandler(async (event) => {
|
|||
data: validatedBody.items.map((item) => ({
|
||||
list_id: newList.id,
|
||||
tmdb_id: item.tmdb_id,
|
||||
type: item.type, // Type is mapped here
|
||||
})),
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue