2023-03-04 23:29:00 +01:00
|
|
|
import {
|
|
|
|
Body,
|
|
|
|
Controller,
|
|
|
|
Get,
|
|
|
|
Param,
|
|
|
|
Patch,
|
|
|
|
Post,
|
|
|
|
UseGuards,
|
|
|
|
} from "@nestjs/common";
|
2023-02-04 18:12:49 +01:00
|
|
|
import { SkipThrottle } from "@nestjs/throttler";
|
2022-11-28 17:50:36 +01:00
|
|
|
import { AdministratorGuard } from "src/auth/guard/isAdmin.guard";
|
2022-12-01 23:07:49 +01:00
|
|
|
import { JwtGuard } from "src/auth/guard/jwt.guard";
|
2022-12-30 14:40:23 +01:00
|
|
|
import { EmailService } from "src/email/email.service";
|
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-12-30 14:40:23 +01:00
|
|
|
import { TestEmailDTO } from "./dto/testEmail.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 {
|
2022-12-30 14:40:23 +01:00
|
|
|
constructor(
|
|
|
|
private configService: ConfigService,
|
|
|
|
private emailService: EmailService
|
|
|
|
) {}
|
2022-11-28 15:04:32 +01:00
|
|
|
|
|
|
|
@Get()
|
2023-02-04 18:12:49 +01:00
|
|
|
@SkipThrottle()
|
2022-11-28 15:04:32 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-03-04 23:29:00 +01:00
|
|
|
@Get("admin/:category")
|
2022-12-01 23:07:49 +01:00
|
|
|
@UseGuards(JwtGuard, AdministratorGuard)
|
2023-03-04 23:29:00 +01:00
|
|
|
async getByCategory(@Param("category") category: string) {
|
2022-11-28 17:50:36 +01:00
|
|
|
return new AdminConfigDTO().fromList(
|
2023-03-04 23:29:00 +01:00
|
|
|
await this.configService.getByCategory(category)
|
2022-11-28 17:50:36 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:40:23 +01:00
|
|
|
@Patch("admin")
|
2022-12-01 23:07:49 +01:00
|
|
|
@UseGuards(JwtGuard, AdministratorGuard)
|
2022-12-30 14:40:23 +01:00
|
|
|
async updateMany(@Body() data: UpdateConfigDTO[]) {
|
2023-03-04 23:29:00 +01:00
|
|
|
return new AdminConfigDTO().fromList(
|
|
|
|
await this.configService.updateMany(data)
|
|
|
|
);
|
2022-12-01 23:07:49 +01:00
|
|
|
}
|
2022-12-30 14:40:23 +01:00
|
|
|
|
|
|
|
@Post("admin/testEmail")
|
|
|
|
@UseGuards(JwtGuard, AdministratorGuard)
|
|
|
|
async testEmail(@Body() { email }: TestEmailDTO) {
|
|
|
|
await this.emailService.sendTestMail(email);
|
|
|
|
}
|
2022-11-28 15:04:32 +01:00
|
|
|
}
|