feat: implement ApiTokenGuard for authentication and apply it to relevant controllers
This commit is contained in:
@ -6,12 +6,15 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { QueryHandlerService } from "../handler/query.handler.service";
|
||||
import { QueryExecuterService } from "../executer/query.executer.service";
|
||||
import { Response } from "express";
|
||||
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
||||
|
||||
@Controller("command")
|
||||
@UseGuards(ApiTokenGuard)
|
||||
export class CommandController {
|
||||
constructor(
|
||||
@Inject(QueryHandlerService)
|
||||
|
||||
@ -6,17 +6,38 @@ import {
|
||||
Param,
|
||||
Post,
|
||||
Res,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { Response } from "express";
|
||||
import { QueryExecuterService } from "./query.executer.service";
|
||||
import { QueryHandlerService } from "./query.handler.service";
|
||||
import { ApiTokenGuard } from "src/api/guards/api-token.guard";
|
||||
import { QueryExecuterService } from "../executer/query.executer.service";
|
||||
|
||||
@Controller("query")
|
||||
export class QueryExecuterController {
|
||||
@UseGuards(ApiTokenGuard)
|
||||
export class QueryController {
|
||||
constructor(
|
||||
@Inject(QueryHandlerService)
|
||||
private readonly queryHandlerService: QueryHandlerService,
|
||||
@Inject(QueryExecuterService)
|
||||
private readonly queryExecuterService: QueryExecuterService
|
||||
) {}
|
||||
|
||||
@Post("create")
|
||||
async createQuery(
|
||||
@Body() queryData: { projectToken: string; source: string }
|
||||
) {
|
||||
return this.queryHandlerService.createQuery(queryData);
|
||||
}
|
||||
|
||||
@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,
|
||||
@ -1,25 +0,0 @@
|
||||
import { Body, Controller, Inject, Post } from "@nestjs/common";
|
||||
import { QueryHandlerService } from "./query.handler.service";
|
||||
|
||||
@Controller("query")
|
||||
export class QueryHandlerController {
|
||||
constructor(
|
||||
@Inject(QueryHandlerService)
|
||||
private readonly queryHandlerService: QueryHandlerService
|
||||
) {}
|
||||
|
||||
@Post("create")
|
||||
async createQuery(
|
||||
@Body() queryData: { projectToken: string; source: string }
|
||||
) {
|
||||
return this.queryHandlerService.createQuery(queryData);
|
||||
}
|
||||
|
||||
@Post("update/:id")
|
||||
async updateQuery(
|
||||
@Body() updateData: Partial<{ source: string }>,
|
||||
@Inject("id") id: string
|
||||
) {
|
||||
return this.queryHandlerService.updateQuery(id, updateData);
|
||||
}
|
||||
}
|
||||
@ -1,25 +1,22 @@
|
||||
import { forwardRef, Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { Query } from "./entities/query.entity";
|
||||
import { QueryExecuterController } from "./executer/query.executer.controller";
|
||||
import { QueryHandlerController } from "./handler/query.handler.controller";
|
||||
import { QueryController } from "./handler/query.controller";
|
||||
import { QueryExecuterService } from "./executer/query.executer.service";
|
||||
import { QueryHandlerService } from "./handler/query.handler.service";
|
||||
import { ProjectModule } from "src/project/project.module";
|
||||
import { DatabaseManagerModule } from "src/databaseManager/database.manager.module";
|
||||
import { CommandController } from "./command/command.controller";
|
||||
import { ApiModule } from "src/api/api.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
forwardRef(() => ProjectModule),
|
||||
forwardRef(() => DatabaseManagerModule),
|
||||
forwardRef(() => ApiModule),
|
||||
TypeOrmModule.forFeature([Query]),
|
||||
],
|
||||
controllers: [
|
||||
QueryExecuterController,
|
||||
QueryHandlerController,
|
||||
CommandController,
|
||||
],
|
||||
controllers: [QueryController, CommandController],
|
||||
providers: [QueryExecuterService, QueryHandlerService],
|
||||
})
|
||||
export class QueryModule {}
|
||||
|
||||
Reference in New Issue
Block a user