feat: 添加短链管理功能,包括创建、更新、删除和列表接口
This commit is contained in:
24
src/routes/n5-link/n5-make/create.ts
Normal file
24
src/routes/n5-link/n5-make/create.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { app, db, schema } from '@/app.ts';
|
||||
|
||||
app.route({
|
||||
path: 'n5-make',
|
||||
key: 'create',
|
||||
middleware: ['auth'],
|
||||
description: `创建 Make, 参数:
|
||||
slug: 唯一业务ID, 必填
|
||||
resources: 资源列表(数组), 选填
|
||||
`,
|
||||
}).define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { userId, createdAt, updatedAt, id: _id, ...rest } = ctx.query.data || {};
|
||||
if (!rest.slug) {
|
||||
ctx.throw(400, 'slug 参数缺失');
|
||||
}
|
||||
const result = await db.insert(schema.n5Make).values({
|
||||
...rest,
|
||||
userId: tokenUser.id,
|
||||
}).returning();
|
||||
ctx.body = result[0];
|
||||
return ctx;
|
||||
}).addTo(app);
|
||||
Reference in New Issue
Block a user