2023-03-04 23:29:00 +01:00
|
|
|
import {
|
|
|
|
Body,
|
|
|
|
Controller,
|
2023-03-08 14:47:41 +01:00
|
|
|
FileTypeValidator,
|
2023-03-04 23:29:00 +01:00
|
|
|
Get,
|
|
|
|
Param,
|
2023-03-08 14:47:41 +01:00
|
|
|
ParseFilePipe,
|
2023-03-04 23:29:00 +01:00
|
|
|
Patch,
|
|
|
|
Post,
|
2023-03-08 14:47:41 +01:00
|
|
|
UploadedFile,
|
2023-03-04 23:29:00 +01:00
|
|
|
UseGuards,
|
2023-03-08 14:47:41 +01:00
|
|
|
UseInterceptors,
|
2023-03-04 23:29:00 +01:00
|
|
|
} from "@nestjs/common";
|
2023-03-08 14:47:41 +01:00
|
|
|
import { FileInterceptor } from "@nestjs/platform-express";
|
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";
|
2023-03-08 14:47:41 +01:00
|
|
|
import { LogoService } from "./logo.service";
|
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,
|
2023-03-08 14:47:41 +01:00
|
|
|
private logoService: LogoService,
|
2022-12-30 14:40:23 +01:00
|
|
|
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);
|
|
|
|
}
|
2023-03-08 14:47:41 +01:00
|
|
|
|
|
|
|
@Post("admin/logo")
|
|
|
|
@UseInterceptors(FileInterceptor("file"))
|
|
|
|
@UseGuards(JwtGuard, AdministratorGuard)
|
|
|
|
async uploadLogo(
|
|
|
|
@UploadedFile(
|
|
|
|
new ParseFilePipe({
|
|
|
|
validators: [new FileTypeValidator({ fileType: "image/png" })],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
file: Express.Multer.File
|
|
|
|
) {
|
|
|
|
return await this.logoService.create(file.buffer);
|
|
|
|
}
|
2022-11-28 15:04:32 +01:00
|
|
|
}
|