Skip to content

Commit b83902e

Browse files
committed
Code Improvements: Feature/ Add series to link related articles
1 parent ab67084 commit b83902e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

server/api/router/series.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TRPCError } from "@trpc/server";
22
import { createTRPCRouter, protectedProcedure } from "../trpc";
33
import { series, post } from "@/server/db/schema";
44
import { UpdateSeriesSchema } from "@/schema/series";
5-
import {eq} from "drizzle-orm";
5+
import {eq, and} from "drizzle-orm";
66
export 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

Comments
 (0)