Skip to content

Commit 3b97f13

Browse files
👌 [#180] fix: filter URL's and UUID from related object when copying zaaktype
1 parent 3884472 commit 3b97f13

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

frontend/src/pages/zaaktype/zaaktype.action.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,54 @@ export type SaveAsZaaktypePayload = {
130130
export async function saveAsAction(actionFunctionArgs: ActionFunctionArgs) {
131131
const data = await actionFunctionArgs.request.json();
132132
const payload = data.payload as PublishZaaktypeVersionPayload;
133-
const uuid = getZaaktypeUUID(payload.zaaktype);
134133

134+
const serviceSlug = payload.serviceSlug;
135135
const zaaktype = payload.zaaktype;
136136
delete zaaktype.broncatalogus;
137137
delete zaaktype.bronzaaktype;
138138

139+
// 1/2 - Filter these fields from related objects in `_expand`
140+
const expandFieldBlackList = ["url", "uuid"];
141+
142+
// 2/2 - Unless the related object's key is one of
143+
const expandObjectWhitelist = [
144+
"besluittypen",
145+
"informatieobjecttypen",
146+
"selectielijstProcestype",
147+
];
148+
149+
// Perform filtering as describe above.
150+
for (const _key in zaaktype._expand) {
151+
const key = _key as keyof typeof zaaktype._expand;
152+
const value = zaaktype._expand[key];
153+
154+
// Don't filter if key is in expandObjectWhitelist
155+
if (expandObjectWhitelist.includes(_key.toLowerCase())) {
156+
continue;
157+
}
158+
159+
// Handler, can be used with Array item or direct value
160+
const handle = <T>(obj: T) => {
161+
if (!obj) return obj;
162+
return Object.fromEntries(
163+
Object.entries(obj).filter(([k]) => !expandFieldBlackList.includes(k)),
164+
);
165+
};
166+
167+
// Reassign filtered value
168+
// @ts-expect-error - Dropping keys here.
169+
zaaktype._expand[key] = Array.isArray(value)
170+
? value.map(handle)
171+
: handle(value);
172+
}
173+
139174
try {
140-
await _saveZaaktypeVersion(zaaktype as TargetType, payload.serviceSlug);
175+
const { uuid } = await request<components["schemas"]["ZaakTypeWithUUID"]>(
176+
"POST",
177+
`/service/${serviceSlug}/zaaktypen/`,
178+
{},
179+
zaaktype,
180+
);
141181
return redirect(`../${uuid}`);
142182
} catch (e) {
143183
return await (e as Response).json();

0 commit comments

Comments
 (0)