feat: Introduce DTOs for API validation and new deployment features, including a Git controller and UI components.

This commit is contained in:
2025-11-23 12:03:11 +08:00
parent 02b7c3edb2
commit 378070179f
24 changed files with 809 additions and 302 deletions

View File

@@ -1,45 +1,61 @@
import { Controller, Get, Post } from '../../decorators/route.ts';
import type { Prisma } from '../../generated/prisma/index.js';
import type { Prisma } from '../../generated/client.ts';
import { prisma } from '../../libs/prisma.ts';
import type { Context } from 'koa';
import { listDeploymentsQuerySchema, createDeploymentSchema } from './dto.ts';
@Controller('/deployments')
export class DeploymentController {
@Get('')
async list(ctx: Context) {
const { page = 1, pageSize = 10 } = ctx.query;
const { page, pageSize, projectId } = listDeploymentsQuerySchema.parse(ctx.query);
const where: Prisma.DeploymentWhereInput = {
valid: 1,
};
if (projectId) {
where.projectId = projectId;
}
const result = await prisma.deployment.findMany({
where: {
valid: 1,
},
take: Number(pageSize),
skip: (Number(page) - 1) * Number(pageSize),
where,
take: pageSize,
skip: (page - 1) * pageSize,
orderBy: {
createdAt: 'desc',
},
});
const total = await prisma.deployment.count();
const total = await prisma.deployment.count({ where });
return {
data: result,
page: Number(page),
pageSize: Number(pageSize),
total: total,
page,
pageSize,
total,
};
}
@Post('')
async create(ctx: Context) {
const body = ctx.request.body as Prisma.DeploymentCreateInput;
const body = createDeploymentSchema.parse(ctx.request.body);
prisma.deployment.create({
const result = await prisma.deployment.create({
data: {
branch: body.branch,
commitHash: body.commitHash,
commitMessage: body.commitMessage,
status: 'pending',
Project: {
connect: { id: body.projectId },
},
pipelineId: body.pipelineId,
env: body.env || 'dev',
buildLog: '',
createdBy: 'system', // TODO: get from user
updatedBy: 'system',
valid: 1,
},
});
return result;
}
}