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,
|
||||
});
|
||||
};
|
||||
|
@@ -1,19 +1,13 @@
|
||||
const infoMock = (
|
||||
logoConfig,
|
||||
primaryDarkConfig,
|
||||
primaryLightConfig,
|
||||
primaryMainConfig,
|
||||
titleConfig
|
||||
) => {
|
||||
const configMock = (config) => {
|
||||
return {
|
||||
data: {
|
||||
disableFavicon: false,
|
||||
disableNotificationsPage: false,
|
||||
'logo.svgData': logoConfig.value.data,
|
||||
'palette.primary.dark': primaryDarkConfig.value.data,
|
||||
'palette.primary.light': primaryLightConfig.value.data,
|
||||
'palette.primary.main': primaryMainConfig.value.data,
|
||||
title: titleConfig.value.data,
|
||||
logoSvgData: config.logoSvgData,
|
||||
palettePrimaryDark: config.palettePrimaryDark,
|
||||
palettePrimaryMain: config.palettePrimaryMain,
|
||||
palettePrimaryLight: config.palettePrimaryLight,
|
||||
title: config.title,
|
||||
},
|
||||
meta: {
|
||||
count: 1,
|
||||
@@ -25,4 +19,4 @@ const infoMock = (
|
||||
};
|
||||
};
|
||||
|
||||
export default infoMock;
|
||||
export default configMock;
|
||||
|
Reference in New Issue
Block a user