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:
71
src/query/base/base-query.controller.ts
Normal file
71
src/query/base/base-query.controller.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user