update
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { eq, desc, and, like, or } from 'drizzle-orm';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { app, db, schema } from '../../app.ts';
|
||||
|
||||
import { filter } from '@kevisual/js-filter'
|
||||
import { z } from 'zod';
|
||||
app
|
||||
.route({
|
||||
path: 'light-code',
|
||||
@@ -9,10 +10,22 @@ app
|
||||
description: `获取轻代码列表,参数
|
||||
type: 代码类型light-code, ts`,
|
||||
middleware: ['auth'],
|
||||
metadata: {
|
||||
args: {
|
||||
type: z.string().optional().describe('代码类型light-code, ts'),
|
||||
search: z.string().optional().describe('搜索关键词,匹配标题和描述'),
|
||||
filter: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'过滤条件,SQL like格式字符串,例如:WHERE tags LIKE \'%tag1%\' AND tags LIKE \'%tag2%\'',
|
||||
),
|
||||
}
|
||||
}
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
const { type, search } = ctx.query || {};
|
||||
const { type, search, filter: filterQuery } = ctx.query || {};
|
||||
const conditions = [eq(schema.kvContainer.uid, tokenUser.id)];
|
||||
if (type) {
|
||||
conditions.push(eq(schema.kvContainer.type, type as string));
|
||||
@@ -43,7 +56,12 @@ app
|
||||
.from(schema.kvContainer)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(schema.kvContainer.updatedAt));
|
||||
ctx.body = { list };
|
||||
if (filterQuery) {
|
||||
const filteredList = filter(list, filterQuery);
|
||||
ctx.body = { list: filteredList }
|
||||
} else {
|
||||
ctx.body = { list };
|
||||
}
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
@@ -140,7 +158,7 @@ app
|
||||
|
||||
app
|
||||
.route({
|
||||
path: 'container',
|
||||
path: 'light-code',
|
||||
key: 'delete',
|
||||
middleware: ['auth'],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user