init: Todo Monitor 初始提交
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { Router } from 'express'
|
||||
import { getDb } from '../db.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const db = getDb()
|
||||
const { notes = [] } = req.body
|
||||
|
||||
const updateNote = db.prepare(`
|
||||
UPDATE notes
|
||||
SET x = ?, y = ?, width = ?, height = ?, group_id = ?,
|
||||
updated_at = datetime('now', 'localtime')
|
||||
WHERE id = ?
|
||||
`)
|
||||
|
||||
const transaction = db.transaction((items) => {
|
||||
for (const item of items) {
|
||||
updateNote.run(item.x, item.y, item.width, item.height, item.group_id ?? null, item.id)
|
||||
}
|
||||
})
|
||||
|
||||
transaction(notes)
|
||||
res.json({ success: true, count: notes.length })
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user