작업계획서대로 진행
This commit is contained in:
47
backend/api/business/create.post.ts
Normal file
47
backend/api/business/create.post.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
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: '사업이 등록되었습니다.'
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user