provide setting endbpoints

This commit is contained in:
Julian Krauser 2025-04-20 16:15:27 +02:00
parent a8edc19f34
commit 7aa9038a61
11 changed files with 137 additions and 13 deletions

View file

@ -0,0 +1,43 @@
import { dataSource } from "../../data-source";
import { setting } from "../../entity/setting";
import InternalException from "../../exceptions/internalException";
import { SettingString } from "../../type/settingTypes";
export default abstract class SettingService {
/**
* @description get settings
* @returns {Promise<setting[]>}
*/
static async getSettings(): Promise<setting[]> {
return await dataSource
.getRepository(setting)
.createQueryBuilder("setting")
.getMany()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("setting not found", err);
});
}
/**
* @description get setting
* @param token SettingString
* @returns {Promise<setting>}
*/
static async getBySettingString(key: SettingString): Promise<setting> {
return await dataSource
.getRepository(setting)
.createQueryBuilder("setting")
.where("setting.topic = :topic", { topic: key.split(".")[0] })
.andWhere("setting.key >= :key", { key: key.split(".")[1] })
.getOneOrFail()
.then((res) => {
return res;
})
.catch((err) => {
throw new InternalException("setting not found", err);
});
}
}