enforce unique position per article
This commit is contained in:
@@ -38,7 +38,7 @@ export const articles = pgTable("articles", {
|
|||||||
name: varchar({ length: 255 }).notNull(),
|
name: varchar({ length: 255 }).notNull(),
|
||||||
article_status: articleStatusEnum().notNull().default("draft"),
|
article_status: articleStatusEnum().notNull().default("draft"),
|
||||||
author_id: uuid().notNull().references(() => users.id, { onDelete: "cascade" }),
|
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(),
|
summary: varchar({ length: 255 }).notNull(),
|
||||||
|
|
||||||
date_created: timestamp({ mode: "date", withTimezone: true }).defaultNow().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(),
|
content: jsonb().$type<Record<string, unknown>>().notNull(),
|
||||||
|
|
||||||
},
|
},
|
||||||
(table) => [{
|
(table) => [
|
||||||
postPositionIdx: uniqueIndex("no_repeat_block_position_per_article")
|
uniqueIndex("no_repeat_block_position_per_article")
|
||||||
.on(table.article_id, table.position)
|
.on(table.article_id, table.position)
|
||||||
}]);
|
]);
|
||||||
|
|
||||||
export const images = pgTable("images", {
|
export const images = pgTable("images", {
|
||||||
id: uuid().notNull().primaryKey().defaultRandom(), // Linked in 'content' of articleBlock with type 'image'
|
id: uuid().notNull().primaryKey().defaultRandom(), // Linked in 'content' of articleBlock with type 'image'
|
||||||
|
|||||||
@@ -30,6 +30,16 @@ usersRouter.get("/getUser/:userId", async (req: Request, res: Response) => {
|
|||||||
res.json(resp);
|
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) => {
|
usersRouter.get("/getUserName/:userId", async (req: Request, res: Response) => {
|
||||||
const { userId } = req.params;
|
const { userId } = req.params;
|
||||||
const parsedId = Array.isArray(userId) ? userId[0] : userId;
|
const parsedId = Array.isArray(userId) ? userId[0] : userId;
|
||||||
|
|||||||
Reference in New Issue
Block a user