feat: 添加短链管理功能,包括创建、更新、删除和列表接口
This commit is contained in:
25
src/routes/n5-link/n5-make/delete.ts
Normal file
25
src/routes/n5-link/n5-make/delete.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { app, db, schema } from '@/app.ts';
|
||||
|
||||
app.route({
|
||||
path: 'n5-make',
|
||||
key: 'delete',
|
||||
middleware: ['auth'],
|
||||
description: '删除 Make, 参数: id Make ID',
|
||||
}).define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { id } = ctx.query.data || {};
|
||||
if (!id) {
|
||||
ctx.throw(400, 'id 参数缺失');
|
||||
}
|
||||
const existing = await db.select().from(schema.n5Make).where(eq(schema.n5Make.id, id)).limit(1);
|
||||
if (existing.length === 0) {
|
||||
ctx.throw(404, 'Make 不存在');
|
||||
}
|
||||
if (existing[0].userId !== tokenUser.id) {
|
||||
ctx.throw(403, '没有权限删除该 Make');
|
||||
}
|
||||
await db.delete(schema.n5Make).where(eq(schema.n5Make.id, id));
|
||||
ctx.body = { success: true };
|
||||
return ctx;
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user