split in env required and dynamic values
This commit is contained in:
parent
f32143b7ac
commit
730c25a9a1
35 changed files with 491 additions and 198 deletions
|
@ -1,10 +1,8 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { refresh } from "../entity/refresh";
|
||||
import { PWA_REFRESH_EXPIRATION, REFRESH_EXPIRATION } from "../env.defaults";
|
||||
import DatabaseActionException from "../exceptions/databaseActionException";
|
||||
import InternalException from "../exceptions/internalException";
|
||||
import SettingHelper from "../helpers/settingsHelper";
|
||||
import { StringHelper } from "../helpers/stringHelper";
|
||||
import UserService from "../service/management/userService";
|
||||
import { CreateRefreshCommand, DeleteRefreshCommand } from "./refreshCommand";
|
||||
import ms from "ms";
|
||||
|
||||
|
@ -25,8 +23,8 @@ export default abstract class RefreshCommandHandler {
|
|||
token: refreshToken,
|
||||
userId: createRefresh.userId,
|
||||
expiry: createRefresh.isFromPwa
|
||||
? new Date(Date.now() + ms(PWA_REFRESH_EXPIRATION))
|
||||
: new Date(Date.now() + ms(REFRESH_EXPIRATION)),
|
||||
? new Date(Date.now() + ms(SettingHelper.getSetting("session.pwa_refresh_expiration") as ms.StringValue))
|
||||
: new Date(Date.now() + ms(SettingHelper.getSetting("session.refresh_expiration") as ms.StringValue)),
|
||||
})
|
||||
.execute()
|
||||
.then((result) => {
|
||||
|
|
10
src/command/settingCommand.ts
Normal file
10
src/command/settingCommand.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
export interface CreateOrUpdateSettingCommand {
|
||||
topic: string;
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface DeleteSettingCommand {
|
||||
topic: string;
|
||||
key: string;
|
||||
}
|
53
src/command/settingCommandHandler.ts
Normal file
53
src/command/settingCommandHandler.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { setting } from "../entity/setting";
|
||||
import DatabaseActionException from "../exceptions/databaseActionException";
|
||||
import { StringHelper } from "../helpers/stringHelper";
|
||||
import { CreateOrUpdateSettingCommand, DeleteSettingCommand } from "./settingCommand";
|
||||
|
||||
export default abstract class SettingCommandHandler {
|
||||
/**
|
||||
* @description create setting
|
||||
* @param {CreateOrUpdateSettingCommand} createSetting
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
static async create(createSetting: CreateOrUpdateSettingCommand): Promise<string> {
|
||||
const token = StringHelper.random(32);
|
||||
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(setting)
|
||||
.values({
|
||||
topic: createSetting.topic,
|
||||
key: createSetting.key,
|
||||
value: createSetting.value,
|
||||
})
|
||||
.orUpdate(["value"], ["topic", "key"])
|
||||
.execute()
|
||||
.then((result) => {
|
||||
return token;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("CREATE OR UPDATE", "setting", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete setting by topic and key
|
||||
* @param {DeleteRefreshCommand} deleteSetting
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
static async delete(deleteSetting: DeleteSettingCommand): Promise<any> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(setting)
|
||||
.where("setting.topic = :topic", { topic: deleteSetting.topic })
|
||||
.andWhere("setting.key = :key", { key: deleteSetting.key })
|
||||
.execute()
|
||||
.then((res) => {})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("DELETE", "setting", err);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue