Skip to content

Commit c636a64

Browse files
committed
Add onRemove function
1 parent c8dc568 commit c636a64

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

server/data_form.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,17 +1063,31 @@ DataForm.prototype.entityPut = function () {
10631063
};
10641064
DataForm.prototype.entityDelete = function () {
10651065
return _.bind(function (req, res, next) {
1066-
this.processEntity(req, res, function () {
1067-
if (!req.resource) {
1068-
next();
1069-
return;
1070-
}
1071-
req.doc.remove(function (err) {
1066+
function internalRemove(doc) {
1067+
doc.remove(function (err) {
10721068
if (err) {
10731069
return res.send({ success: false });
10741070
}
10751071
return res.send({ success: true });
10761072
});
1073+
}
1074+
this.processEntity(req, res, function () {
1075+
if (!req.resource) {
1076+
next();
1077+
return;
1078+
}
1079+
var doc = req.doc;
1080+
if (typeof req.resource.options.onRemove === 'function') {
1081+
req.resource.options.onRemove(doc, req, function (err) {
1082+
if (err) {
1083+
throw err;
1084+
}
1085+
internalRemove(doc);
1086+
});
1087+
}
1088+
else {
1089+
internalRemove(doc);
1090+
}
10771091
});
10781092
}, this);
10791093
};

server/data_form.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,18 +1180,34 @@ DataForm.prototype.entityPut = function () {
11801180
DataForm.prototype.entityDelete = function () {
11811181
return _.bind(function (req, res, next) {
11821182

1183+
function internalRemove(doc) {
1184+
doc.remove(function (err) {
1185+
if (err) {
1186+
return res.send({success: false});
1187+
}
1188+
return res.send({success: true});
1189+
});
1190+
}
1191+
11831192
this.processEntity(req, res, function () {
11841193
if (!req.resource) {
11851194
next();
11861195
return;
11871196
}
11881197

1189-
req.doc.remove(function (err) {
1190-
if (err) {
1191-
return res.send({success: false});
1192-
}
1193-
return res.send({success: true});
1194-
});
1198+
let doc = req.doc;
1199+
if (typeof req.resource.options.onRemove === 'function') {
1200+
1201+
req.resource.options.onRemove(doc, req, function (err) {
1202+
if (err) {
1203+
throw err;
1204+
}
1205+
internalRemove(doc);
1206+
});
1207+
} else {
1208+
internalRemove(doc);
1209+
}
1210+
11951211
});
11961212
}, this);
11971213
};

0 commit comments

Comments
 (0)