@adminforth/crud-approve-plugin 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +16 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -182,14 +182,24 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
182
182
|
updates,
|
|
183
183
|
oldRecord,
|
|
184
184
|
});
|
|
185
|
-
if (!resp || (
|
|
186
|
-
throw new Error(
|
|
185
|
+
if (!resp || (typeof resp.ok !== 'boolean' && (!resp.error && !resp.newRecordId))) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Invalid return value from beforeSave hook. Expected: { ok: boolean, error?: string | null, newRecordId?: any }.\n` +
|
|
188
|
+
`Note: Return { ok: false, error: null, newRecordId } to stop creation and redirect to an existing record.`
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
if (resp.ok === false && !resp.error) {
|
|
192
|
+
const { error, ok, newRecordId } = resp;
|
|
193
|
+
return {
|
|
194
|
+
error: error ?? 'Operation aborted by hook',
|
|
195
|
+
newRecordId: newRecordId
|
|
196
|
+
};
|
|
187
197
|
}
|
|
188
|
-
|
|
189
198
|
if (resp.error) {
|
|
190
199
|
return { error: resp.error };
|
|
191
200
|
}
|
|
192
201
|
}
|
|
202
|
+
|
|
193
203
|
return { ok: true, error: null };
|
|
194
204
|
}
|
|
195
205
|
|
|
@@ -345,6 +355,9 @@ export default class CRUDApprovePlugin extends AdminForthPlugin {
|
|
|
345
355
|
diffData['newRecord'], diffData['oldRecord'], this.adminforth, extra
|
|
346
356
|
);
|
|
347
357
|
if (beforeSaveResp.error) {
|
|
358
|
+
if (beforeSaveResp.error === 'Operation aborted by hook') {
|
|
359
|
+
return beforeSaveResp;
|
|
360
|
+
}
|
|
348
361
|
response.status = 500;
|
|
349
362
|
return { error: `Failed to apply approved changes: ${beforeSaveResp.error}` };
|
|
350
363
|
}
|