2022-11-28 17:50:36 +01:00
|
|
|
import { Body, Controller, Get, Param, Patch, UseGuards } from "@nestjs/common";
|
|
|
|
import { AdministratorGuard } from "src/auth/guard/isAdmin.guard";
|
2022-11-28 15:04:32 +01:00
|
|
|
import { ConfigService } from "./config.service";
|
2022-11-28 17:50:36 +01:00
|
|
|
import { AdminConfigDTO } from "./dto/adminConfig.dto";
|
2022-11-28 15:04:32 +01:00
|
|
|
import { ConfigDTO } from "./dto/config.dto";
|
2022-11-28 17:50:36 +01:00
|
|
|
import UpdateConfigDTO from "./dto/updateConfig.dto";
|
2022-11-28 15:04:32 +01:00
|
|
|
|
|
|
|
@Controller("configs")
|
|
|
|
export class ConfigController {
|
|
|
|
constructor(private configService: ConfigService) {}
|
|
|
|
|
|
|
|
@Get()
|
|
|
|
async list() {
|
2022-11-28 17:50:36 +01:00
|
|
|
return new ConfigDTO().fromList(await this.configService.list());
|
2022-11-28 15:04:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Get("admin")
|
2022-11-28 17:50:36 +01:00
|
|
|
@UseGuards(AdministratorGuard)
|
2022-11-28 15:04:32 +01:00
|
|
|
async listForAdmin() {
|
2022-11-28 17:50:36 +01:00
|
|
|
return new AdminConfigDTO().fromList(
|
|
|
|
await this.configService.listForAdmin()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Patch("admin/:key")
|
|
|
|
@UseGuards(AdministratorGuard)
|
|
|
|
async update(@Param("key") key: string, @Body() data: UpdateConfigDTO) {
|
|
|
|
return new AdminConfigDTO().from(
|
|
|
|
await this.configService.update(key, data.value)
|
|
|
|
);
|
2022-11-28 15:04:32 +01:00
|
|
|
}
|
|
|
|
}
|