Files
system-monitor/backend/api/network/pubnet/targets/[id].put.ts
2025-12-28 14:31:12 +09:00

29 lines
652 B
TypeScript

import { execute } from '../../../../utils/db'
export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id')
const body = await readBody(event)
const { name, url, is_active } = body
if (!name || !url) {
throw createError({
statusCode: 400,
message: 'name과 url은 필수입니다'
})
}
await execute(`
UPDATE pubnet_targets
SET name = $1, url = $2, is_active = $3, updated_at = TO_CHAR(NOW(), 'YYYY-MM-DD HH24:MI:SS')
WHERE id = $4
`, [name, url, is_active ? 1 : 0, id])
return {
id: Number(id),
name,
url,
is_active: is_active ? 1 : 0
}
})