mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 14:27:23 +00:00
25 lines
689 B
TypeScript
25 lines
689 B
TypeScript
import { IServerConfig, ServerConfig } from "../models/serverConfig";
|
|
|
|
let serverConfig: IServerConfig;
|
|
|
|
export const serverConfigInit = async () => {
|
|
const cfg = await ServerConfig.findOne({});
|
|
if (!cfg) {
|
|
const cfg = new ServerConfig();
|
|
await cfg.save();
|
|
serverConfig = cfg;
|
|
} else {
|
|
serverConfig = cfg;
|
|
}
|
|
return serverConfig;
|
|
};
|
|
|
|
export const getServerConfig = () => serverConfig;
|
|
|
|
export const updateServerConfig = async (data: Partial<IServerConfig>) => {
|
|
const cfg = await ServerConfig.findByIdAndUpdate(serverConfig._id, data, { new: true });
|
|
if (!cfg) throw new Error("Failed to update server config");
|
|
serverConfig = cfg;
|
|
return serverConfig;
|
|
};
|