feat: add getProjectInfo method and corresponding endpoint in ProjectController; refactor logger methods to include projectId
This commit is contained in:
@ -65,4 +65,9 @@ export class ProjectController {
|
||||
getAllApiTokens(@Req() req: Request & { apiToken: { id: string } }) {
|
||||
return this.projectService.getAllApiTokens(req.apiToken.id);
|
||||
}
|
||||
|
||||
@Get("info")
|
||||
getProjectInfo(@Req() req: Request & { apiToken: { id: string } }) {
|
||||
return this.projectService.getProjectInfo(req.apiToken.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,4 +84,13 @@ export class ProjectService {
|
||||
});
|
||||
return project?.apiTokens || [];
|
||||
}
|
||||
|
||||
async getProjectInfo(projectId: string) {
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: { id: projectId },
|
||||
relations: ["queries", "apiTokens", "functions", "settings"],
|
||||
});
|
||||
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 { FunctionService } from "./function.service";
|
||||
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);
|
||||
}
|
||||
|
||||
@Post("delete")
|
||||
@Delete("delete/:name")
|
||||
async deleteFunction(
|
||||
@Req() req: Request & { apiToken: Token },
|
||||
name: string
|
||||
@Param("name") name: string
|
||||
) {
|
||||
return this.functionService.deleteFunction(req.apiToken.project.id, name);
|
||||
}
|
||||
|
||||
@ -5,11 +5,14 @@ import {
|
||||
Inject,
|
||||
Param,
|
||||
Post,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { LoggerService } from "./logger.service";
|
||||
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
||||
import { QueryGuard } from "../guards/query.guard";
|
||||
import { Token } from "src/api/entities/token.entity";
|
||||
import { Query } from "../entities/query.entity";
|
||||
|
||||
@Controller("logger")
|
||||
@UseGuards(ApiTokenGuard)
|
||||
@ -19,14 +22,17 @@ export class LoggerController {
|
||||
private readonly loggerService: LoggerService
|
||||
) {}
|
||||
|
||||
@Get("/:id/:traceId")
|
||||
getByTraceId(@Param("traceId") traceId: string) {
|
||||
return this.loggerService.findByTraceId(traceId);
|
||||
@Get("/:traceId")
|
||||
getByTraceId(
|
||||
@Req() req: Request & { apiToken: Token },
|
||||
@Param("traceId") traceId: string
|
||||
) {
|
||||
return this.loggerService.findByTraceId(req.apiToken.project.id, traceId);
|
||||
}
|
||||
|
||||
@Post("/:id/findAll")
|
||||
@Post("/findAll")
|
||||
findAll(
|
||||
@Param("id") projectId: string,
|
||||
@Req() req: Request & { apiToken: Token },
|
||||
@Body()
|
||||
body: {
|
||||
traceId?: string;
|
||||
@ -37,13 +43,13 @@ export class LoggerController {
|
||||
offset: number;
|
||||
}
|
||||
) {
|
||||
return this.loggerService.findByProjectId(projectId, body);
|
||||
return this.loggerService.findByProjectId(req.apiToken.project.id, body);
|
||||
}
|
||||
|
||||
@Post("/:id/find")
|
||||
@Post("/find")
|
||||
@UseGuards(QueryGuard)
|
||||
find(
|
||||
@Param("id") _id: string,
|
||||
@Req() req: Request & { query: Query },
|
||||
@Body()
|
||||
body: {
|
||||
traceId?: string;
|
||||
@ -54,6 +60,6 @@ export class LoggerController {
|
||||
offset: number;
|
||||
}
|
||||
) {
|
||||
return this.loggerService.find(_id, body);
|
||||
return this.loggerService.find(req.query.id, body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,8 +22,15 @@ export class LoggerService {
|
||||
return await this.logRepository.save(log);
|
||||
}
|
||||
|
||||
async findByTraceId(traceId: string): Promise<Log[]> {
|
||||
return await this.logRepository.find({ where: { traceId } });
|
||||
async findByTraceId(projectId: string, traceId: string): Promise<Log[]> {
|
||||
return await this.logRepository.find({
|
||||
where: {
|
||||
traceId,
|
||||
project: {
|
||||
id: projectId,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private prepareQuery(data: {
|
||||
|
||||
Reference in New Issue
Block a user