feat: implement ApiTokenGuard for authentication and apply it to relevant controllers
This commit is contained in:
@ -1,46 +0,0 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Headers,
|
||||
Inject,
|
||||
Param,
|
||||
Post,
|
||||
Res,
|
||||
} from "@nestjs/common";
|
||||
import { Response } from "express";
|
||||
import { QueryExecuterService } from "./query.executer.service";
|
||||
|
||||
@Controller("query")
|
||||
export class QueryExecuterController {
|
||||
constructor(
|
||||
@Inject(QueryExecuterService)
|
||||
private readonly queryExecuterService: QueryExecuterService
|
||||
) {}
|
||||
|
||||
@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.runQuery(
|
||||
token,
|
||||
query,
|
||||
headers
|
||||
);
|
||||
|
||||
res.status(queryResult.statusCode);
|
||||
|
||||
if (queryResult.statusCode === 302 && 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user