feat: add getProjectInfo method and corresponding endpoint in ProjectController; refactor logger methods to include projectId

This commit is contained in:
lborv
2025-10-28 20:36:53 +02:00
parent bbc378dc95
commit 84c48dd482
5 changed files with 49 additions and 14 deletions

View File

@ -65,4 +65,9 @@ export class ProjectController {
getAllApiTokens(@Req() req: Request & { apiToken: { id: string } }) { getAllApiTokens(@Req() req: Request & { apiToken: { id: string } }) {
return this.projectService.getAllApiTokens(req.apiToken.id); return this.projectService.getAllApiTokens(req.apiToken.id);
} }
@Get("info")
getProjectInfo(@Req() req: Request & { apiToken: { id: string } }) {
return this.projectService.getProjectInfo(req.apiToken.id);
}
} }

View File

@ -84,4 +84,13 @@ export class ProjectService {
}); });
return project?.apiTokens || []; return project?.apiTokens || [];
} }
async getProjectInfo(projectId: string) {
const project = await this.projectRepository.findOne({
where: { id: projectId },
relations: ["queries", "apiTokens", "functions", "settings"],
});
return project;
}
} }

View File

@ -1,4 +1,12 @@
import { Controller, Inject, Post, Req, UseGuards } from "@nestjs/common"; import {
Controller,
Delete,
Inject,
Param,
Post,
Req,
UseGuards,
} from "@nestjs/common";
import { ApiTokenGuard } from "src/api/guards/api-token.guard"; import { ApiTokenGuard } from "src/api/guards/api-token.guard";
import { FunctionService } from "./function.service"; import { FunctionService } from "./function.service";
import { Token } from "src/api/entities/token.entity"; import { Token } from "src/api/entities/token.entity";
@ -20,10 +28,10 @@ export class FunctionController {
return this.functionService.create(req.apiToken.project.id, name, source); return this.functionService.create(req.apiToken.project.id, name, source);
} }
@Post("delete") @Delete("delete/:name")
async deleteFunction( async deleteFunction(
@Req() req: Request & { apiToken: Token }, @Req() req: Request & { apiToken: Token },
name: string @Param("name") name: string
) { ) {
return this.functionService.deleteFunction(req.apiToken.project.id, name); return this.functionService.deleteFunction(req.apiToken.project.id, name);
} }

View File

@ -5,11 +5,14 @@ import {
Inject, Inject,
Param, Param,
Post, Post,
Req,
UseGuards, UseGuards,
} from "@nestjs/common"; } from "@nestjs/common";
import { LoggerService } from "./logger.service"; import { LoggerService } from "./logger.service";
import { ApiTokenGuard } from "src/api/guards/api-token.guard"; import { ApiTokenGuard } from "src/api/guards/api-token.guard";
import { QueryGuard } from "../guards/query.guard"; import { QueryGuard } from "../guards/query.guard";
import { Token } from "src/api/entities/token.entity";
import { Query } from "../entities/query.entity";
@Controller("logger") @Controller("logger")
@UseGuards(ApiTokenGuard) @UseGuards(ApiTokenGuard)
@ -19,14 +22,17 @@ export class LoggerController {
private readonly loggerService: LoggerService private readonly loggerService: LoggerService
) {} ) {}
@Get("/:id/:traceId") @Get("/:traceId")
getByTraceId(@Param("traceId") traceId: string) { getByTraceId(
return this.loggerService.findByTraceId(traceId); @Req() req: Request & { apiToken: Token },
@Param("traceId") traceId: string
) {
return this.loggerService.findByTraceId(req.apiToken.project.id, traceId);
} }
@Post("/:id/findAll") @Post("/findAll")
findAll( findAll(
@Param("id") projectId: string, @Req() req: Request & { apiToken: Token },
@Body() @Body()
body: { body: {
traceId?: string; traceId?: string;
@ -37,13 +43,13 @@ export class LoggerController {
offset: number; offset: number;
} }
) { ) {
return this.loggerService.findByProjectId(projectId, body); return this.loggerService.findByProjectId(req.apiToken.project.id, body);
} }
@Post("/:id/find") @Post("/find")
@UseGuards(QueryGuard) @UseGuards(QueryGuard)
find( find(
@Param("id") _id: string, @Req() req: Request & { query: Query },
@Body() @Body()
body: { body: {
traceId?: string; traceId?: string;
@ -54,6 +60,6 @@ export class LoggerController {
offset: number; offset: number;
} }
) { ) {
return this.loggerService.find(_id, body); return this.loggerService.find(req.query.id, body);
} }
} }

View File

@ -22,8 +22,15 @@ export class LoggerService {
return await this.logRepository.save(log); return await this.logRepository.save(log);
} }
async findByTraceId(traceId: string): Promise<Log[]> { async findByTraceId(projectId: string, traceId: string): Promise<Log[]> {
return await this.logRepository.find({ where: { traceId } }); return await this.logRepository.find({
where: {
traceId,
project: {
id: projectId,
},
},
});
} }
private prepareQuery(data: { private prepareQuery(data: {