Files
system-monitor/backend/api/network/privnet/targets/index.post.ts
2025-12-28 12:03:48 +09:00

28 lines
585 B
TypeScript

import { getDb } from '../../../../utils/db'
export default defineEventHandler(async (event) => {
const db = getDb()
const body = await readBody(event)
const { name, url, is_active } = body
if (!name || !url) {
throw createError({
statusCode: 400,
message: 'name과 url은 필수입니다'
})
}
const result = db.prepare(`
INSERT INTO privnet_targets (name, url, is_active)
VALUES (?, ?, ?)
`).run(name, url, is_active ? 1 : 0)
return {
id: result.lastInsertRowid,
name,
url,
is_active: is_active ? 1 : 0
}
})