enforce unique position per article

This commit is contained in:
2026-08-22 18:14:26 -05:00
parent 6f21248132
commit 562ec61802
2 changed files with 14 additions and 4 deletions
+4 -4
View File
@@ -38,7 +38,7 @@ export const articles = pgTable("articles", {
name: varchar({ length: 255 }).notNull(),
article_status: articleStatusEnum().notNull().default("draft"),
author_id: uuid().notNull().references(() => users.id, { onDelete: "cascade" }),
slug: varchar({ length: 511 }).unique().notNull(),
slug: varchar({ length: 511 }).notNull(),
summary: varchar({ length: 255 }).notNull(),
date_created: timestamp({ mode: "date", withTimezone: true }).defaultNow().notNull(),
@@ -74,10 +74,10 @@ export const articleBlocks = pgTable("article_blocks", {
content: jsonb().$type<Record<string, unknown>>().notNull(),
},
(table) => [{
postPositionIdx: uniqueIndex("no_repeat_block_position_per_article")
(table) => [
uniqueIndex("no_repeat_block_position_per_article")
.on(table.article_id, table.position)
}]);
]);
export const images = pgTable("images", {
id: uuid().notNull().primaryKey().defaultRandom(), // Linked in 'content' of articleBlock with type 'image'
+10
View File
@@ -30,6 +30,16 @@ usersRouter.get("/getUser/:userId", async (req: Request, res: Response) => {
res.json(resp);
});
usersRouter.get("/getSelf", loadJWT, async (req: Request, res: Response) => {
const userId = req.jwt.payload.uid;
const resp = await db.select()
.from(users)
.where(eq(users.id, userId));
res.json(resp[0]);
});
usersRouter.get("/getUserName/:userId", async (req: Request, res: Response) => {
const { userId } = req.params;
const parsedId = Array.isArray(userId) ? userId[0] : userId;