48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
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 }
|
|
})
|