feat(config): make data structure horizontal
This commit is contained in:
@@ -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,
|
||||
});
|
||||
};
|
||||
|
Reference in New Issue
Block a user