feat: add getProjectDetails method and corresponding endpoint
This commit is contained in:
@ -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 { ProjectService } from "./project.service";
|
||||||
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
||||||
import { AdminGuard } from "src/api/guards/admin.guard";
|
import { AdminGuard } from "src/api/guards/admin.guard";
|
||||||
|
import { Request } from "express";
|
||||||
|
|
||||||
@Controller("project")
|
@Controller("project")
|
||||||
@UseGuards(ApiTokenGuard)
|
@UseGuards(ApiTokenGuard)
|
||||||
@ -16,6 +25,13 @@ export class ProjectController {
|
|||||||
return this.projectService.create(body.name);
|
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")
|
@Put("create-without-db")
|
||||||
@UseGuards(AdminGuard)
|
@UseGuards(AdminGuard)
|
||||||
createProjectWithoutDB(@Body() body: { name: string }) {
|
createProjectWithoutDB(@Body() body: { name: string }) {
|
||||||
|
|||||||
@ -27,6 +27,19 @@ export class ProjectService {
|
|||||||
return projectSaved;
|
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) {
|
async findById(id: string) {
|
||||||
const cached = await this.redisClient.get(`project_${id}`);
|
const cached = await this.redisClient.get(`project_${id}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user