diff --git a/src/project/project.controller.ts b/src/project/project.controller.ts index ebaaaef..a269d63 100644 --- a/src/project/project.controller.ts +++ b/src/project/project.controller.ts @@ -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 }) { diff --git a/src/project/project.service.ts b/src/project/project.service.ts index 7dd8249..ab33b41 100644 --- a/src/project/project.service.ts +++ b/src/project/project.service.ts @@ -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}`);