28 lines
672 B
TypeScript
28 lines
672 B
TypeScript
import Setting from "../models/Setting";
|
|
import fs from "fs";
|
|
import dir from "path";
|
|
import os from "os";
|
|
|
|
async function loadSettings() {
|
|
const setting = await Setting.findAll({});
|
|
|
|
if (setting) {
|
|
let sett = setting.map((s: any) => {
|
|
return { key: s.key, value: s.value };
|
|
});
|
|
|
|
try {
|
|
const keyFilename = dir.join(os.tmpdir(), `whaticket_settings.json`);
|
|
|
|
const jsonSettings = JSON.stringify(sett, null, 2);
|
|
|
|
fs.writeFileSync(keyFilename, jsonSettings);
|
|
console.log(`Settings saved to ${keyFilename}`);
|
|
} catch (err) {
|
|
console.error("Error saving Settings to file:", err);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default loadSettings;
|