37 lines
787 B
TypeScript
37 lines
787 B
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Inject,
|
|
Param,
|
|
Post,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { ApiService } from "./api.service";
|
|
import { AdminGuard } from "./guards/admin.guard";
|
|
import { ApiTokenGuard } from "./guards/api-token.guard";
|
|
|
|
@Controller("api")
|
|
@UseGuards(ApiTokenGuard)
|
|
@UseGuards(AdminGuard)
|
|
export class ApiController {
|
|
constructor(
|
|
@Inject(ApiService)
|
|
private readonly apiService: ApiService
|
|
) {}
|
|
|
|
@Post("token/generate")
|
|
generateToken(@Body() body: { id: string }) {
|
|
if (!body.id) {
|
|
throw new Error("Project ID is required");
|
|
}
|
|
|
|
return this.apiService.generateToken(body.id);
|
|
}
|
|
|
|
@Delete("token/revoke/:token")
|
|
revokeToken(@Param("token") token: string) {
|
|
return this.apiService.revokeToken(token);
|
|
}
|
|
}
|