adminforth 1.2.33 → 1.2.34

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.
@@ -248,14 +248,25 @@ export default class ConfigValidator {
248
248
  allowed: (_b) => __awaiter(this, [_b], void 0, function* ({ resource, adminUser, allowedActions }) { return allowedActions.delete; }),
249
249
  action: (_c) => __awaiter(this, [_c], void 0, function* ({ selectedIds, adminUser }) {
250
250
  const connector = this.adminforth.connectors[res.dataSource];
251
+ let error = null;
251
252
  yield Promise.all(selectedIds.map((recordId) => __awaiter(this, void 0, void 0, function* () {
252
253
  const record = yield connector.getRecordByPrimaryKey(res, recordId);
254
+ yield Promise.all(res.hooks.delete.beforeSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
255
+ const resp = yield hook({ resource: res, record, adminUser });
256
+ if (!error && resp.error) {
257
+ error = resp.error;
258
+ }
259
+ })));
253
260
  yield connector.deleteRecord({ resource: res, recordId });
254
261
  // call afterDelete hook
255
262
  yield Promise.all(res.hooks.delete.afterSave.map((hook) => __awaiter(this, void 0, void 0, function* () {
256
263
  yield hook({ resource: res, record, adminUser });
257
264
  })));
258
265
  })));
266
+ if (error) {
267
+ return { error, ok: false };
268
+ }
269
+ return { ok: true };
259
270
  })
260
271
  });
261
272
  }
@@ -269,20 +269,40 @@ export default class ConfigValidator implements IConfigValidator {
269
269
  allowed: async ({ resource, adminUser, allowedActions }) => { return allowedActions.delete },
270
270
  action: async ({ selectedIds, adminUser }) => {
271
271
  const connector = this.adminforth.connectors[res.dataSource];
272
- await Promise.all(selectedIds.map(async (recordId) => {
273
- const record = await connector.getRecordByPrimaryKey(res, recordId);
274
-
275
- await connector.deleteRecord({ resource: res, recordId });
276
- // call afterDelete hook
277
- await Promise.all(
278
- (res.hooks.delete.afterSave as AfterSaveFunction[]).map(
279
- async (hook) => {
280
- await hook({ resource: res, record, adminUser });
281
- }
272
+ let error = null;
273
+
274
+ await Promise.all(
275
+ selectedIds.map(async (recordId) => {
276
+ const record = await connector.getRecordByPrimaryKey(res, recordId);
277
+
278
+ await Promise.all(
279
+ (res.hooks.delete.beforeSave as AfterSaveFunction[]).map(
280
+ async (hook) => {
281
+ const resp = await hook({ resource: res, record, adminUser });
282
+ if (!error && resp.error) {
283
+ error = resp.error;
284
+ }
285
+ }
286
+ )
282
287
  )
283
- )
284
-
285
- }));
288
+
289
+ await connector.deleteRecord({ resource: res, recordId });
290
+ // call afterDelete hook
291
+ await Promise.all(
292
+ (res.hooks.delete.afterSave as AfterSaveFunction[]).map(
293
+ async (hook) => {
294
+ await hook({ resource: res, record, adminUser });
295
+ }
296
+ )
297
+ )
298
+
299
+ })
300
+ );
301
+
302
+ if (error) {
303
+ return { error, ok: false };
304
+ }
305
+ return { ok: true };
286
306
  }
287
307
  });
288
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adminforth",
3
- "version": "1.2.33",
3
+ "version": "1.2.34",
4
4
  "description": "OpenSource Vue3 powered forth-generation admin panel",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -680,7 +680,7 @@ export type AdminForthBulkAction = {
680
680
  * Callback which will be called on backend when user clicks on action button.
681
681
  * It should return Promise which will be resolved when action is done.
682
682
  */
683
- action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<void>,
683
+ action: ({ resource, selectedIds, adminUser }: { resource: AdminForthResource, selectedIds: Array<any>, adminUser: AdminUser }) => Promise<{ ok: boolean, error?: string }>,
684
684
 
685
685
  /**
686
686
  * Confirmation message which will be displayed to user before action is executed.