48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { insertReturning } from '../../utils/db'
|
|
import { getCurrentUserId } from '../../utils/user'
|
|
|
|
interface CreateBusinessBody {
|
|
businessName: string
|
|
businessCode?: string
|
|
clientName?: string
|
|
contractStartDate?: string
|
|
contractEndDate?: string
|
|
description?: string
|
|
}
|
|
|
|
/**
|
|
* 사업 생성
|
|
* POST /api/business/create
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const body = await readBody<CreateBusinessBody>(event)
|
|
const userId = await getCurrentUserId(event)
|
|
|
|
if (!body.businessName) {
|
|
throw createError({ statusCode: 400, message: '사업명은 필수입니다.' })
|
|
}
|
|
|
|
const business = await insertReturning(`
|
|
INSERT INTO wr_business (
|
|
business_name, business_code, client_name,
|
|
contract_start_date, contract_end_date, description,
|
|
business_status, created_by, updated_by
|
|
) VALUES ($1, $2, $3, $4, $5, $6, 'active', $7, $7)
|
|
RETURNING *
|
|
`, [
|
|
body.businessName,
|
|
body.businessCode || null,
|
|
body.clientName || null,
|
|
body.contractStartDate || null,
|
|
body.contractEndDate || null,
|
|
body.description || null,
|
|
userId
|
|
])
|
|
|
|
return {
|
|
success: true,
|
|
businessId: business.business_id,
|
|
message: '사업이 등록되었습니다.'
|
|
}
|
|
})
|