feat: 更新 mark 路由,添加 metadata 验证,移除未使用的代码

This commit is contained in:
xiongxiao
2026-03-18 22:55:08 +08:00
committed by cnb
parent 6467e6dea8
commit 6a92ee7a2d

View File

@@ -1,8 +1,7 @@
import { eq, desc, and, like, or, count, sql } from 'drizzle-orm';
import { app, db, schema } from '../../app.ts';
import { MarkServices } from './services/mark.ts';
import dayjs from 'dayjs';
import { nanoid } from 'nanoid';
import z from 'zod';
app
.route({
@@ -10,6 +9,13 @@ app
key: 'list',
description: 'mark list.',
middleware: ['auth'],
metadata: {
page: z.number().optional().describe('页码'),
pageSize: z.number().optional().describe('每页数量'),
search: z.string().optional().describe('搜索关键词'),
markType: z.string().optional().describe('mark类型,simple,wallnote,md,draw等'),
sort: z.enum(['DESC', 'ASC']).default('DESC').describe('排序字段'),
}
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -26,6 +32,9 @@ app
path: 'mark',
key: 'getVersion',
middleware: ['auth'],
metadata: {
id: z.string().describe('mark id'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -47,26 +56,6 @@ app
};
} else {
ctx.throw(400, 'id is required');
// const [markModel, created] = await MarkModel.findOrCreate({
// where: {
// uid: tokenUser.id,
// puid: tokenUser.uid,
// title: dayjs().format('YYYY-MM-DD'),
// },
// defaults: {
// title: dayjs().format('YYYY-MM-DD'),
// uid: tokenUser.id,
// markType: 'wallnote',
// tags: ['daily'],
// },
// });
// ctx.body = {
// version: Number(markModel.version),
// updatedAt: markModel.updatedAt,
// createdAt: markModel.createdAt,
// id: markModel.id,
// created: created,
// };
}
})
.addTo(app);
@@ -76,6 +65,9 @@ app
path: 'mark',
key: 'get',
middleware: ['auth'],
metadata: {
id: z.string().describe('mark id'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -92,24 +84,6 @@ app
ctx.body = markModel;
} else {
ctx.throw(400, 'id is required');
// id 不存在获取当天的title为 日期的一条数据
// const [markModel, created] = await MarkModel.findOrCreate({
// where: {
// uid: tokenUser.id,
// puid: tokenUser.uid,
// title: dayjs().format('YYYY-MM-DD'),
// },
// defaults: {
// title: dayjs().format('YYYY-MM-DD'),
// uid: tokenUser.id,
// markType: 'wallnote',
// tags: ['daily'],
// uname: tokenUser.username,
// puid: tokenUser.uid,
// version: 1,
// },
// });
// ctx.body = markModel;
}
})
.addTo(app);
@@ -120,6 +94,9 @@ app
key: 'update',
middleware: ['auth'],
isDebug: true,
metadata: {
id: z.string().describe('mark id'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -166,6 +143,14 @@ app
path: 'mark',
key: 'updateNode',
middleware: ['auth'],
metadata: {
id: z.string().describe('mark id'),
operate: z.enum(['update', 'delete']).default('update').describe('节点操作类型update或delete'),
data: z.object({
id: z.string().describe('节点id'),
node: z.any().describe('要更新的节点数据'),
}).describe('要更新的节点数据'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -211,6 +196,13 @@ app
path: 'mark',
key: 'updateNodes',
middleware: ['auth'],
metadata: {
id: z.string().describe('mark id'),
nodeOperateList: z.array(z.object({
operate: z.enum(['update', 'delete']).default('update').describe('节点操作类型update或delete'),
node: z.any().describe('要更新的节点数据'),
})).describe('要更新的节点列表'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -265,6 +257,9 @@ app
path: 'mark',
key: 'delete',
middleware: ['auth'],
metadata: {
id: z.string().describe('mark id'),
},
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
@@ -283,7 +278,12 @@ app
.addTo(app);
app
.route({ path: 'mark', key: 'getMenu', description: '获取菜单', middleware: ['auth'] })
.route({
path: 'mark',
key: 'getMenu',
description: '获取菜单',
middleware: ['auth']
})
.define(async (ctx) => {
const tokenUser = ctx.state.tokenUser;
const [rows, totalResult] = await Promise.all([