feat(config): make data structure horizontal

This commit is contained in:
Ali BARIN
2024-09-20 10:43:06 +00:00
parent f4a1ad6c8c
commit 8a17c5eaab
9 changed files with 183 additions and 154 deletions

View File

@@ -1,35 +1,11 @@
import { faker } from '@faker-js/faker';
import Config from '../../src/models/config';
export const createConfig = async (params = {}) => {
const configData = {
key: params?.key || faker.lorem.word(),
value: params?.value || { data: 'sampleConfig' },
};
const config = await Config.query().insertAndFetch(configData);
return config;
export const updateConfig = async (params = {}) => {
return await Config.update(params);
};
export const createBulkConfig = async (params = {}) => {
const updateQueries = Object.entries(params).map(([key, value]) => {
const config = {
key,
value: { data: value },
};
return createConfig(config);
});
await Promise.all(updateQueries);
return await Config.query().whereIn('key', Object.keys(params));
};
export const createInstallationCompletedConfig = async () => {
return await createConfig({
key: 'installation.completed',
value: { data: true },
export const markInstallationCompleted = async () => {
return await updateConfig({
installationCompleted: true,
});
};