feat: create getConfig GQL query

This commit is contained in:
Ali BARIN
2023-08-10 14:32:11 +00:00
parent bafb8b86db
commit efd243a340
4 changed files with 52 additions and 17 deletions

View File

@@ -0,0 +1,31 @@
import Context from '../../types/express/context';
import Config from '../../models/config';
type Params = {
keys: string[];
};
const getConfig = async (
_parent: unknown,
params: Params,
context: Context
) => {
const configQuery = Config
.query();
if (Array.isArray(params.keys)) {
configQuery.whereIn('key', params.keys);
}
const config = await configQuery;
return config.reduce((computedConfig, configEntry) => {
const { key, value } = configEntry;
computedConfig[key] = value?.data;
return computedConfig;
}, {} as Record<string, unknown>);
};
export default getConfig;