기능구현중
This commit is contained in:
47
backend/api/repository/create.post.ts
Normal file
47
backend/api/repository/create.post.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { insertReturning } from '../../utils/db'
|
||||
import { requireAuth } from '../../utils/session'
|
||||
import { getClientIp } from '../../utils/ip'
|
||||
|
||||
interface CreateRepoBody {
|
||||
projectId: number
|
||||
serverId: number
|
||||
repoName: string
|
||||
repoPath: string
|
||||
repoUrl?: string
|
||||
defaultBranch?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장소 추가
|
||||
* POST /api/repository/create
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const employeeId = await requireAuth(event)
|
||||
const body = await readBody<CreateRepoBody>(event)
|
||||
const ip = getClientIp(event)
|
||||
|
||||
if (!body.projectId || !body.serverId || !body.repoPath) {
|
||||
throw createError({ statusCode: 400, message: '필수 항목을 입력해주세요.' })
|
||||
}
|
||||
|
||||
const repo = await insertReturning(`
|
||||
INSERT INTO wr_repository (
|
||||
project_id, server_id, repo_name, repo_path, repo_url,
|
||||
default_branch, description, created_by, created_at, created_ip
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW(), $9)
|
||||
RETURNING repo_id
|
||||
`, [
|
||||
body.projectId,
|
||||
body.serverId,
|
||||
body.repoName || body.repoPath,
|
||||
body.repoPath,
|
||||
body.repoUrl || null,
|
||||
body.defaultBranch || 'main',
|
||||
body.description || null,
|
||||
employeeId,
|
||||
ip
|
||||
])
|
||||
|
||||
return { success: true, repoId: repo.repo_id }
|
||||
})
|
||||
Reference in New Issue
Block a user