|
|
@@ -8,9 +8,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
dateNotesRoutes.post('/', withAuth, async (c) => {
|
|
|
try {
|
|
|
const apiClient = c.get('apiClient')
|
|
|
- const { date, title, content } = await c.req.json()
|
|
|
+ const { code, note_date, note } = await c.req.json()
|
|
|
|
|
|
- if (!date || !title || !content) {
|
|
|
+ if (!code || !note_date || !note) {
|
|
|
return c.json({ error: '缺少必要参数' }, 400)
|
|
|
}
|
|
|
|
|
|
@@ -18,10 +18,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
if (!user) return c.json({ error: '未授权访问' }, 401)
|
|
|
|
|
|
const [noteId] = await apiClient.database.table('date_notes').insert({
|
|
|
- date,
|
|
|
- title,
|
|
|
- content,
|
|
|
- user_id: user.id,
|
|
|
+ code,
|
|
|
+ note_date,
|
|
|
+ note,
|
|
|
created_at: apiClient.database.fn.now(),
|
|
|
updated_at: apiClient.database.fn.now()
|
|
|
})
|
|
|
@@ -50,14 +49,13 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
if (!user) return c.json({ error: '未授权访问' }, 401)
|
|
|
|
|
|
const query = apiClient.database.table('date_notes')
|
|
|
- .where('user_id', user.id)
|
|
|
- .orderBy('date', 'desc')
|
|
|
+ .orderBy('note_date', 'desc')
|
|
|
.limit(pageSize)
|
|
|
.offset((page - 1) * pageSize)
|
|
|
|
|
|
// 日期范围查询
|
|
|
- if (startDate) query.where('date', '>=', startDate)
|
|
|
- if (endDate) query.where('date', '<=', endDate)
|
|
|
+ if (startDate) query.where('note_date', '>=', startDate)
|
|
|
+ if (endDate) query.where('note_date', '<=', endDate)
|
|
|
|
|
|
const countQuery = query.clone()
|
|
|
const notes = await query
|
|
|
@@ -78,7 +76,7 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
})
|
|
|
} catch (error) {
|
|
|
console.error('获取日期笔记列表失败:', error)
|
|
|
- return c.json({ error: '获取日期笔记列表失败' }, 500)
|
|
|
+ return c.json({ error: '获取日期笔记列表失败',message: error }, 500)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -94,7 +92,6 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
|
|
|
const note = await apiClient.database.table('date_notes')
|
|
|
.where('id', noteId)
|
|
|
- .where('user_id', user.id)
|
|
|
.first()
|
|
|
|
|
|
if (!note) {
|
|
|
@@ -115,9 +112,9 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
dateNotesRoutes.put('/:id', withAuth, async (c) => {
|
|
|
try {
|
|
|
const apiClient = c.get('apiClient')
|
|
|
- const { date, title, content } = await c.req.json()
|
|
|
+ const { code, note_date, note } = await c.req.json()
|
|
|
|
|
|
- if (!date || !title || !content) {
|
|
|
+ if (!code || !note_date || !note) {
|
|
|
return c.json({ error: '缺少必要参数' }, 400)
|
|
|
}
|
|
|
|
|
|
@@ -128,11 +125,10 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
|
|
|
await apiClient.database.table('date_notes')
|
|
|
.where('id', noteId)
|
|
|
- .where('user_id', user.id)
|
|
|
.update({
|
|
|
- date,
|
|
|
- title,
|
|
|
- content,
|
|
|
+ code,
|
|
|
+ note_date,
|
|
|
+ note,
|
|
|
updated_at: apiClient.database.fn.now()
|
|
|
})
|
|
|
|
|
|
@@ -154,7 +150,6 @@ export function createDateNotesRoutes(withAuth: WithAuth) {
|
|
|
|
|
|
await apiClient.database.table('date_notes')
|
|
|
.where('id', noteId)
|
|
|
- .where('user_id', user.id)
|
|
|
.delete()
|
|
|
|
|
|
return c.json({ message: '日期笔记已删除' })
|