68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { query } from '../../utils/db'
|
|
|
|
/**
|
|
* 저장소 목록 조회
|
|
* GET /api/repository/list
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const params = getQuery(event)
|
|
const projectId = params.projectId ? Number(params.projectId) : null
|
|
const serverId = params.serverId ? Number(params.serverId) : null
|
|
const includeInactive = params.includeInactive === 'true'
|
|
|
|
const conditions: string[] = []
|
|
const values: any[] = []
|
|
let paramIndex = 1
|
|
|
|
if (projectId) {
|
|
conditions.push(`r.project_id = $${paramIndex++}`)
|
|
values.push(projectId)
|
|
}
|
|
|
|
if (serverId) {
|
|
conditions.push(`r.server_id = $${paramIndex++}`)
|
|
values.push(serverId)
|
|
}
|
|
|
|
if (!includeInactive) {
|
|
conditions.push('r.is_active = true')
|
|
}
|
|
|
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
|
|
|
|
const repos = await query(`
|
|
SELECT
|
|
r.*,
|
|
s.server_name,
|
|
s.server_type,
|
|
p.project_name,
|
|
e.employee_name as created_by_name
|
|
FROM wr_repository r
|
|
JOIN wr_vcs_server s ON r.server_id = s.server_id
|
|
LEFT JOIN wr_project_info p ON r.project_id = p.project_id
|
|
LEFT JOIN wr_employee_info e ON r.created_by = e.employee_id
|
|
${whereClause}
|
|
ORDER BY r.repo_name
|
|
`, values)
|
|
|
|
return {
|
|
repositories: repos.map((r: any) => ({
|
|
repoId: r.repo_id,
|
|
serverId: r.server_id,
|
|
serverName: r.server_name,
|
|
serverType: r.server_type,
|
|
projectId: r.project_id,
|
|
projectName: r.project_name,
|
|
repoName: r.repo_name,
|
|
repoPath: r.repo_path,
|
|
repoUrl: r.repo_url,
|
|
defaultBranch: r.default_branch,
|
|
description: r.description,
|
|
isActive: r.is_active,
|
|
lastSyncAt: r.last_sync_at,
|
|
createdAt: r.created_at,
|
|
createdByName: r.created_by_name
|
|
}))
|
|
}
|
|
})
|