provide setting endbpoints
This commit is contained in:
parent
a8edc19f34
commit
7aa9038a61
11 changed files with 137 additions and 13 deletions
10
src/command/management/setting/settingCommand.ts
Normal file
10
src/command/management/setting/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/management/setting/settingCommandHandler.ts
Normal file
53
src/command/management/setting/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