Skip to content

Commit

Permalink
feat(ministry brands): added extra for getEkklesiaFields
Browse files Browse the repository at this point in the history
added extra to updateEkklesiaFields
  • Loading branch information
zeleniucvladislav authored and DanielGherjavca committed Mar 28, 2024
1 parent 54daa86 commit b555e1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 11 additions & 4 deletions public/editor-client/src/ekklesia/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from "config";
import { ChoicesAsync, ChoicesSync } from "types/Choices";
import {
EkklesiaExtra,
EkklesiaFieldMap,
EkklesiaFields,
EkklesiaKeys,
Expand All @@ -14,7 +15,8 @@ export const getEkklesiaFields = (config: Config) => ({
async handler<T extends keyof EkklesiaFields = keyof EkklesiaFields>(
res: Response<ChoicesAsync | ChoicesSync>,
rej: Response<string>,
keys: EkklesiaParams<T>
keys: EkklesiaParams<T>,
extra?: EkklesiaExtra
): Promise<void> {
const { ekklesiaApiUrl } = config.api;
if (!ekklesiaApiUrl) {
Expand All @@ -25,7 +27,7 @@ export const getEkklesiaFields = (config: Config) => ({
return;
}
try {
const fields = await getFields(ekklesiaApiUrl, keys);
const fields = await getFields(ekklesiaApiUrl, keys, extra);
res(fields);
} catch (error) {
if (process.env.NODE_ENV === "development") {
Expand All @@ -42,7 +44,8 @@ export const updateEkklesiaFields = (config: Config) => ({
rej: Response<string>,
keys: {
fields: Array<EkklesiaFieldMap[T]>;
}
},
extra?: EkklesiaExtra
): Promise<void> {
const { ekklesiaApiUrl } = config.api;

Expand All @@ -57,7 +60,11 @@ export const updateEkklesiaFields = (config: Config) => ({
const dataToChange: EkklesiaKeys = {};
try {
for (const field of keys.fields) {
const choiches = await getFields<T>(ekklesiaApiUrl, field.module);
const choiches = await getFields<T>(
ekklesiaApiUrl,
field.module,
extra
);

if (!choiches.length) continue;

Expand Down
6 changes: 4 additions & 2 deletions public/editor-client/src/ekklesia/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { makeUrl } from "api/utils";
import { ChoicesSync } from "types/Choices";
import {
EkklesiaChoiceParamsWithSubKey,
EkklesiaExtra,
EkklesiaFields,
EkklesiaParams,
EkklesiaParentsChilds,
Expand Down Expand Up @@ -44,11 +45,12 @@ export const getFields = async <
T extends keyof EkklesiaFields = keyof EkklesiaFields
>(
_url: string,
keys: EkklesiaParams<T>
keys: EkklesiaParams<T>,
extra?: EkklesiaExtra
): Promise<ChoicesSync> => {
const { key } = keys;

const url = makeUrl(_url, { module: key });
const url = makeUrl(_url, { module: key, ...extra });

const { data = {} } = await requestFields(url);
const field = data[key];
Expand Down
4 changes: 4 additions & 0 deletions public/editor-client/src/types/Ekklesia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface EkklesiaFields {
smallgroupsLvl: EkklesiaParentsChilds;
}

export interface EkklesiaExtra {
find_group?: string;
}

export interface EkklesiaParentsChilds {
parents: Record<string, Literal>;
childs: Record<string, Literal>;
Expand Down

0 comments on commit b555e1b

Please sign in to comment.