-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add add new config strategy to frontend
- Loading branch information
1 parent
1b5e53f
commit 493705e
Showing
20 changed files
with
183 additions
and
102 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
import { Controller, Get } from "@nestjs/common"; | ||
import { Body, Controller, Get, Param, Patch, UseGuards } from "@nestjs/common"; | ||
import { AdministratorGuard } from "src/auth/guard/isAdmin.guard"; | ||
import { ConfigService } from "./config.service"; | ||
import { AdminConfigDTO } from "./dto/adminConfig.dto"; | ||
import { ConfigDTO } from "./dto/config.dto"; | ||
import UpdateConfigDTO from "./dto/updateConfig.dto"; | ||
|
||
@Controller("configs") | ||
export class ConfigController { | ||
constructor(private configService: ConfigService) {} | ||
|
||
@Get() | ||
async list() { | ||
return new ConfigDTO().fromList(await this.configService.list()) | ||
return new ConfigDTO().fromList(await this.configService.list()); | ||
} | ||
|
||
@Get("admin") | ||
@UseGuards(AdministratorGuard) | ||
async listForAdmin() { | ||
return await this.configService.listForAdmin(); | ||
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) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Expose, plainToClass } from "class-transformer"; | ||
import { ConfigDTO } from "./config.dto"; | ||
|
||
export class AdminConfigDTO extends ConfigDTO { | ||
@Expose() | ||
default: string; | ||
|
||
@Expose() | ||
secret: boolean; | ||
|
||
@Expose() | ||
updatedAt: Date; | ||
|
||
from(partial: Partial<AdminConfigDTO>) { | ||
return plainToClass(AdminConfigDTO, partial, { excludeExtraneousValues: true }); | ||
} | ||
|
||
fromList(partial: Partial<AdminConfigDTO>[]) { | ||
return partial.map((part) => | ||
plainToClass(AdminConfigDTO, part, { excludeExtraneousValues: true }) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { IsNotEmpty } from "class-validator"; | ||
|
||
class UpdateConfigDTO { | ||
@IsNotEmpty() | ||
value: string | number | boolean; | ||
} | ||
|
||
export default UpdateConfigDTO; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
/** @type {import('next').NextConfig} */ | ||
|
||
const nextConfig = { | ||
publicRuntimeConfig: { | ||
ALLOW_REGISTRATION: process.env.ALLOW_REGISTRATION, | ||
SHOW_HOME_PAGE: process.env.SHOW_HOME_PAGE, | ||
MAX_FILE_SIZE: process.env.MAX_FILE_SIZE, | ||
ALLOW_UNAUTHENTICATED_SHARES: process.env.ALLOW_UNAUTHENTICATED_SHARES, | ||
EMAIL_RECIPIENTS_ENABLED: process.env.EMAIL_RECIPIENTS_ENABLED | ||
} | ||
} | ||
|
||
const withPWA = require("next-pwa")({ | ||
dest: "public", | ||
disable: process.env.NODE_ENV == "development" | ||
}); | ||
|
||
|
||
module.exports = withPWA(nextConfig); | ||
module.exports = withPWA(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { createContext, useContext } from "react"; | ||
import configService from "../services/config.service"; | ||
import Config from "../types/config.type"; | ||
|
||
export const ConfigContext = createContext<Config[] | null>(null); | ||
|
||
const useConfig = () => { | ||
const configVariables = useContext(ConfigContext) as Config[]; | ||
return { | ||
get: (key: string) => configService.get(key, configVariables), | ||
}; | ||
}; | ||
|
||
export default useConfig; |
Oops, something went wrong.