@ruiapp/rapid-core 0.11.4 → 0.11.6
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/dist/index.js +19 -6
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +21 -11
- package/src/server.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -3174,7 +3174,7 @@ const UNDELETED_ENTITY_FILTER_OPTIONS = {
|
|
|
3174
3174
|
field: "deletedAt",
|
|
3175
3175
|
};
|
|
3176
3176
|
function tryAddUndeletedEntityFilter(model, baseModel, filters) {
|
|
3177
|
-
let isEntitySoftDeleteEnabled = baseModel ? baseModel.softDelete : model.softDelete;
|
|
3177
|
+
let isEntitySoftDeleteEnabled = baseModel ? (baseModel.softDelete || model.softDelete) : model.softDelete;
|
|
3178
3178
|
if (!isEntitySoftDeleteEnabled) {
|
|
3179
3179
|
return filters;
|
|
3180
3180
|
}
|
|
@@ -4279,6 +4279,12 @@ async function deleteEntityById(server, dataAccessor, options, plugin) {
|
|
|
4279
4279
|
};
|
|
4280
4280
|
}
|
|
4281
4281
|
const model = dataAccessor.getModel();
|
|
4282
|
+
let baseModel;
|
|
4283
|
+
if (model.base) {
|
|
4284
|
+
baseModel = server.getModel({
|
|
4285
|
+
singularCode: model.base,
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4282
4288
|
if (model.derivedTypePropertyCode) {
|
|
4283
4289
|
// TODO: should be allowed.
|
|
4284
4290
|
throw newEntityOperationError("Delete base entity directly is not allowed.");
|
|
@@ -4292,7 +4298,8 @@ async function deleteEntityById(server, dataAccessor, options, plugin) {
|
|
|
4292
4298
|
if (!entity) {
|
|
4293
4299
|
return;
|
|
4294
4300
|
}
|
|
4295
|
-
|
|
4301
|
+
const isEntitySoftDeleteEnabled = model.base ? (baseModel.softDelete || model.softDelete) : model.softDelete;
|
|
4302
|
+
if (isEntitySoftDeleteEnabled) {
|
|
4296
4303
|
if (entity.deletedAt) {
|
|
4297
4304
|
return;
|
|
4298
4305
|
}
|
|
@@ -4307,12 +4314,18 @@ async function deleteEntityById(server, dataAccessor, options, plugin) {
|
|
|
4307
4314
|
sender: plugin,
|
|
4308
4315
|
routeContext,
|
|
4309
4316
|
});
|
|
4310
|
-
if (
|
|
4317
|
+
if (isEntitySoftDeleteEnabled) {
|
|
4311
4318
|
const currentUserId = routeContext?.state?.userId;
|
|
4312
|
-
|
|
4319
|
+
const updateFields = {
|
|
4313
4320
|
deleted_at: getNowStringWithTimezone(),
|
|
4314
4321
|
deleter_id: currentUserId,
|
|
4315
|
-
}
|
|
4322
|
+
};
|
|
4323
|
+
const softDeleteDataAccessor = model.base
|
|
4324
|
+
? server.getDataAccessor({
|
|
4325
|
+
singularCode: model.base,
|
|
4326
|
+
})
|
|
4327
|
+
: dataAccessor;
|
|
4328
|
+
await softDeleteDataAccessor.updateById(id, updateFields, routeContext?.getDbTransactionClient());
|
|
4316
4329
|
}
|
|
4317
4330
|
else {
|
|
4318
4331
|
const relationPropertiesWithDeletingReaction = getEntityPropertiesIncludingBase(server, model, (property) => {
|
|
@@ -4986,7 +4999,7 @@ class RapidServer {
|
|
|
4986
4999
|
if (!response.status && !response.body) {
|
|
4987
5000
|
response.json({
|
|
4988
5001
|
error: {
|
|
4989
|
-
message:
|
|
5002
|
+
message: `No route handler was found to handle this request. ${rapidRequest.method} ${rapidRequest.url}`,
|
|
4990
5003
|
},
|
|
4991
5004
|
}, 404);
|
|
4992
5005
|
}
|
package/package.json
CHANGED
|
@@ -401,7 +401,7 @@ const UNDELETED_ENTITY_FILTER_OPTIONS: EntityFilterOptions = {
|
|
|
401
401
|
};
|
|
402
402
|
|
|
403
403
|
function tryAddUndeletedEntityFilter(model: RpdDataModel, baseModel: RpdDataModel, filters: EntityFilterOptions[] | undefined) {
|
|
404
|
-
let isEntitySoftDeleteEnabled = baseModel ? baseModel.softDelete : model.softDelete;
|
|
404
|
+
let isEntitySoftDeleteEnabled = baseModel ? (baseModel.softDelete || model.softDelete) : model.softDelete;
|
|
405
405
|
if (!isEntitySoftDeleteEnabled) {
|
|
406
406
|
return filters;
|
|
407
407
|
}
|
|
@@ -1639,6 +1639,12 @@ async function deleteEntityById(
|
|
|
1639
1639
|
}
|
|
1640
1640
|
|
|
1641
1641
|
const model = dataAccessor.getModel();
|
|
1642
|
+
let baseModel: RpdDataModel | undefined;
|
|
1643
|
+
if (model.base) {
|
|
1644
|
+
baseModel = server.getModel({
|
|
1645
|
+
singularCode: model.base,
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1642
1648
|
if (model.derivedTypePropertyCode) {
|
|
1643
1649
|
// TODO: should be allowed.
|
|
1644
1650
|
throw newEntityOperationError("Delete base entity directly is not allowed.");
|
|
@@ -1656,7 +1662,8 @@ async function deleteEntityById(
|
|
|
1656
1662
|
return;
|
|
1657
1663
|
}
|
|
1658
1664
|
|
|
1659
|
-
|
|
1665
|
+
const isEntitySoftDeleteEnabled = model.base ? (baseModel.softDelete || model.softDelete) : model.softDelete;
|
|
1666
|
+
if (isEntitySoftDeleteEnabled) {
|
|
1660
1667
|
if (entity.deletedAt) {
|
|
1661
1668
|
return;
|
|
1662
1669
|
}
|
|
@@ -1673,16 +1680,19 @@ async function deleteEntityById(
|
|
|
1673
1680
|
routeContext,
|
|
1674
1681
|
});
|
|
1675
1682
|
|
|
1676
|
-
if (
|
|
1683
|
+
if (isEntitySoftDeleteEnabled) {
|
|
1677
1684
|
const currentUserId = routeContext?.state?.userId;
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1685
|
+
const updateFields = {
|
|
1686
|
+
deleted_at: getNowStringWithTimezone(),
|
|
1687
|
+
deleter_id: currentUserId,
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
const softDeleteDataAccessor = model.base
|
|
1691
|
+
? server.getDataAccessor({
|
|
1692
|
+
singularCode: model.base,
|
|
1693
|
+
})
|
|
1694
|
+
: dataAccessor;
|
|
1695
|
+
await softDeleteDataAccessor.updateById(id, updateFields, routeContext?.getDbTransactionClient());
|
|
1686
1696
|
} else {
|
|
1687
1697
|
const relationPropertiesWithDeletingReaction = getEntityPropertiesIncludingBase(server, model, (property) => {
|
|
1688
1698
|
return isRelationProperty(property) && property.entityDeletingReaction && property.entityDeletingReaction !== "doNothing";
|
package/src/server.ts
CHANGED
|
@@ -472,7 +472,7 @@ export class RapidServer implements IRpdServer {
|
|
|
472
472
|
response.json(
|
|
473
473
|
{
|
|
474
474
|
error: {
|
|
475
|
-
message:
|
|
475
|
+
message: `No route handler was found to handle this request. ${rapidRequest.method} ${rapidRequest.url}`,
|
|
476
476
|
},
|
|
477
477
|
},
|
|
478
478
|
404,
|