feat: dashboard interface
This commit is contained in:
22
server/api/links/[id]/index.delete.ts
Normal file
22
server/api/links/[id]/index.delete.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { db } from "#server/db";
|
||||
import * as tables from "#server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
|
||||
const paramsSchema = z.object({
|
||||
id: z.string().transform(Number),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
||||
|
||||
const [link] = await db
|
||||
.delete(tables.links)
|
||||
.where(eq(tables.links.id, params.id))
|
||||
.returning();
|
||||
if (!link) {
|
||||
throw createError({ statusCode: 404, message: "Link not found" });
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
21
server/api/links/[id]/index.get.ts
Normal file
21
server/api/links/[id]/index.get.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { db } from "#server/db";
|
||||
import * as tables from "#server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
|
||||
const paramsSchema = z.object({
|
||||
id: z.string().transform(Number),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
||||
|
||||
const link = await db.query.links.findFirst({
|
||||
where: eq(tables.links.id, params.id),
|
||||
});
|
||||
if (!link) {
|
||||
throw createError({ statusCode: 404, message: "Link not found" });
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
30
server/api/links/[id]/index.patch.ts
Normal file
30
server/api/links/[id]/index.patch.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { db } from "#server/db";
|
||||
import * as tables from "#server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { z } from "zod";
|
||||
|
||||
const paramsSchema = z.object({
|
||||
id: z.string().transform(Number),
|
||||
});
|
||||
|
||||
const bodySchema = z.object({
|
||||
name: z.string().min(1).optional(),
|
||||
path: z.string().min(1).optional(),
|
||||
url: z.url().optional(),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const params = await getValidatedRouterParams(event, paramsSchema.parse);
|
||||
const body = await readValidatedBody(event, bodySchema.parse);
|
||||
|
||||
const [link] = await db
|
||||
.update(tables.links)
|
||||
.set(body)
|
||||
.where(eq(tables.links.id, params.id))
|
||||
.returning();
|
||||
if (!link) {
|
||||
throw createError({ statusCode: 404, message: "Link not found" });
|
||||
}
|
||||
|
||||
return link;
|
||||
});
|
||||
Reference in New Issue
Block a user