@@ -2,7 +2,7 @@ import { TRPCError } from "@trpc/server";
22import { createTRPCRouter , protectedProcedure } from "../trpc" ;
33import { series , post } from "@/server/db/schema" ;
44import { UpdateSeriesSchema } from "@/schema/series" ;
5- import { eq } from "drizzle-orm" ;
5+ import { eq , and } from "drizzle-orm" ;
66export const seriesRouter = createTRPCRouter ( {
77 update : protectedProcedure
88 . input ( UpdateSeriesSchema )
@@ -47,7 +47,10 @@ export const seriesRouter = createTRPCRouter({
4747 columns : {
4848 id : true
4949 } ,
50- where : ( series , { eq } ) => eq ( series . title , seriesTitle ) ,
50+ where : ( series , { eq, and } ) => and (
51+ eq ( series . title , seriesTitle ) ,
52+ eq ( series . userId , ctx . session . user . id )
53+ ) ,
5154 } )
5255
5356 if ( ! currSeries ) {
@@ -80,13 +83,18 @@ export const seriesRouter = createTRPCRouter({
8083 where : ( post , { eq, and, ne } ) =>
8184 and (
8285 ne ( post . id , currentPost . id ) ,
83- eq ( post . seriesId , currentPost . seriesId ! )
86+ eq ( post . seriesId , seriesId )
8487 )
8588 } )
8689 // if another post with the same seriesId is present, then do nothing
8790 // else remove the series from the series table
8891 if ( ! anotherPostInThisSeries ) {
89- await tx . delete ( series ) . where ( eq ( series . id , seriesId ) ) ;
92+ await tx . delete ( series ) . where (
93+ and (
94+ eq ( series . id , seriesId ) ,
95+ eq ( series . userId , ctx . session . user . id )
96+ )
97+ ) ;
9098 }
9199 // update that series id in the current post
92100 await tx
0 commit comments