feat: add getProjectDetails method and corresponding endpoint

This commit is contained in:
lborv
2025-10-15 19:52:36 +03:00
parent 2671665e25
commit 6992041429
2 changed files with 30 additions and 1 deletions

View File

@ -1,7 +1,16 @@
import { Body, Controller, Inject, Put, UseGuards } from "@nestjs/common";
import {
Body,
Controller,
Get,
Inject,
Put,
Req,
UseGuards,
} from "@nestjs/common";
import { ProjectService } from "./project.service";
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
import { AdminGuard } from "src/api/guards/admin.guard";
import { Request } from "express";
@Controller("project")
@UseGuards(ApiTokenGuard)
@ -16,6 +25,13 @@ export class ProjectController {
return this.projectService.create(body.name);
}
@Get("details")
getProjectDetails(
@Req() req: Request & { apiToken: { project: { id: string } } }
) {
return this.projectService.getProjectDetails(req.apiToken.project.id);
}
@Put("create-without-db")
@UseGuards(AdminGuard)
createProjectWithoutDB(@Body() body: { name: string }) {

View File

@ -27,6 +27,19 @@ export class ProjectService {
return projectSaved;
}
async getProjectDetails(projectId: string) {
const project = await this.projectRepository.findOne({
where: { id: projectId },
relations: ["database", "database.migrations", "queries", "functions"],
});
return {
migrations: project?.database?.migrations || [],
queries: project?.queries || [],
functions: project?.functions || [],
};
}
async findById(id: string) {
const cached = await this.redisClient.get(`project_${id}`);