추가
This commit is contained in:
47
backend/api/project/create.post.ts
Normal file
47
backend/api/project/create.post.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { insertReturning } from '../../utils/db'
|
||||
|
||||
interface CreateProjectBody {
|
||||
projectCode?: string
|
||||
projectName: string
|
||||
clientName?: string
|
||||
projectDescription?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
contractAmount?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 프로젝트 등록
|
||||
* POST /api/project/create
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readBody<CreateProjectBody>(event)
|
||||
|
||||
if (!body.projectName) {
|
||||
throw createError({ statusCode: 400, message: '프로젝트명을 입력해주세요.' })
|
||||
}
|
||||
|
||||
const project = await insertReturning(`
|
||||
INSERT INTO wr_project_info (
|
||||
project_code, project_name, client_name, project_description,
|
||||
start_date, end_date, contract_amount
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
RETURNING *
|
||||
`, [
|
||||
body.projectCode || null,
|
||||
body.projectName,
|
||||
body.clientName || null,
|
||||
body.projectDescription || null,
|
||||
body.startDate || null,
|
||||
body.endDate || null,
|
||||
body.contractAmount || null
|
||||
])
|
||||
|
||||
return {
|
||||
success: true,
|
||||
project: {
|
||||
projectId: project.project_id,
|
||||
projectName: project.project_name
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user