feat: implement function management with FunctionEntity, FunctionService, and FunctionController; enhance QueryExecuterService to utilize functions; refactor CommandController and QueryController to extend BaseQueryController; update Vm class to handle functions; remove obsolete log entities

This commit is contained in:
lborv
2025-10-09 19:35:30 +03:00
parent 5b30b876e5
commit e89af0dd20
14 changed files with 261 additions and 160 deletions

View File

@ -0,0 +1,71 @@
import {
Body,
Headers,
Inject,
Param,
Post,
Res,
UseGuards,
} from "@nestjs/common";
import { Response } from "express";
import { QueryHandlerService } from "../handler/query.handler.service";
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
import { QueryExecuterService } from "../executer/query.executer.service";
@UseGuards(ApiTokenGuard)
export abstract class BaseQueryController {
constructor(
@Inject(QueryHandlerService)
protected readonly queryHandlerService: QueryHandlerService,
@Inject(QueryExecuterService)
protected readonly queryExecuterService: QueryExecuterService
) {}
protected abstract getIsCommand(): boolean;
@Post("create")
async createQuery(
@Body() queryData: { projectToken: string; source: string }
) {
return this.queryHandlerService.createQuery(queryData, this.getIsCommand());
}
@Post("update/:id")
async updateQuery(
@Body() updateData: Partial<{ source: string }>,
@Inject("id") id: string
) {
return this.queryHandlerService.updateQuery(id, updateData);
}
@Post("/run/:token")
async runQuery(
@Param("token") token: string,
@Body() query: Record<string, any>,
@Headers() headers: Record<string, any>,
@Res() res: Response
) {
const queryResult = await this.queryExecuterService.runQueryQueued(
token,
query,
headers
);
res.status(queryResult?.statusCode || 200);
if (
queryResult?.statusCode === 302 &&
queryResult?.headers &&
queryResult?.headers["Location"]
) {
res.redirect(queryResult?.headers["Location"]);
return;
}
for (const [key, value] of Object.entries(queryResult?.headers || {})) {
res.setHeader(key, value);
}
res.send(queryResult?.response || null);
}
}