feat: implement command functionality with new CommandController, update Query entity, and enhance query execution with headers support
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Inject, Param, Post } from "@nestjs/common";
|
||||
import { Body, Controller, Headers, Inject, Param, Post } from "@nestjs/common";
|
||||
import { QueryExecuterService } from "./query.executer.service";
|
||||
|
||||
@Controller("query")
|
||||
@ -11,8 +11,9 @@ export class QueryExecuterController {
|
||||
@Post("/run/:token")
|
||||
async runQuery(
|
||||
@Param("token") token: string,
|
||||
@Body() query: Record<string, any>
|
||||
@Body() query: Record<string, any>,
|
||||
@Headers() headers: Record<string, any>
|
||||
) {
|
||||
return this.queryExecuterService.runQuery(token, query);
|
||||
return this.queryExecuterService.runQuery(token, query, headers);
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,11 @@ export class QueryExecuterService {
|
||||
.trim();
|
||||
}
|
||||
|
||||
async runQuery(token: string, queryData: any) {
|
||||
async runQuery(
|
||||
token: string,
|
||||
queryData: any,
|
||||
headers: Record<string, any> = {}
|
||||
) {
|
||||
const query = await this.queryRepository.findOne({
|
||||
where: { id: token },
|
||||
relations: ["project"],
|
||||
@ -47,7 +51,8 @@ export class QueryExecuterService {
|
||||
const vm = await this.createVm(query);
|
||||
const result = await vm.runScript(
|
||||
this.clearImports(query.source),
|
||||
queryData
|
||||
queryData,
|
||||
headers
|
||||
);
|
||||
|
||||
return { message: "Query executed", result, query: queryData };
|
||||
|
||||
Reference in New Issue
Block a user