@ruiapp/rapid-core 0.1.14 → 0.1.15
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 +13 -10
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +18 -10
package/dist/index.js
CHANGED
|
@@ -1813,6 +1813,17 @@ async function findEntity(server, dataAccessor, options) {
|
|
|
1813
1813
|
const entities = await findEntities(server, dataAccessor, options);
|
|
1814
1814
|
return ___namespace.first(entities);
|
|
1815
1815
|
}
|
|
1816
|
+
async function findById(server, dataAccessor, id) {
|
|
1817
|
+
return await findEntity(server, dataAccessor, {
|
|
1818
|
+
filters: [
|
|
1819
|
+
{
|
|
1820
|
+
operator: "eq",
|
|
1821
|
+
field: "id",
|
|
1822
|
+
value: id,
|
|
1823
|
+
}
|
|
1824
|
+
]
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1816
1827
|
async function replaceFiltersWithFiltersOperator(server, model, filters) {
|
|
1817
1828
|
if (!filters || !filters.length) {
|
|
1818
1829
|
return [];
|
|
@@ -2108,7 +2119,7 @@ async function updateEntityById(server, dataAccessor, options, plugin) {
|
|
|
2108
2119
|
if (!id) {
|
|
2109
2120
|
throw new Error("Id is required when updating an entity.");
|
|
2110
2121
|
}
|
|
2111
|
-
const entity = await
|
|
2122
|
+
const entity = await findById(server, dataAccessor, id);
|
|
2112
2123
|
if (!entity) {
|
|
2113
2124
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
2114
2125
|
}
|
|
@@ -2247,15 +2258,7 @@ class EntityManager {
|
|
|
2247
2258
|
return await findEntity(this.#server, this.#dataAccessor, options);
|
|
2248
2259
|
}
|
|
2249
2260
|
async findById(id) {
|
|
2250
|
-
return await this
|
|
2251
|
-
filters: [
|
|
2252
|
-
{
|
|
2253
|
-
operator: "eq",
|
|
2254
|
-
field: "id",
|
|
2255
|
-
value: id,
|
|
2256
|
-
}
|
|
2257
|
-
]
|
|
2258
|
-
});
|
|
2261
|
+
return await findById(this.#server, this.#dataAccessor, id);
|
|
2259
2262
|
}
|
|
2260
2263
|
async createEntity(options, plugin) {
|
|
2261
2264
|
const model = this.getModel();
|
package/package.json
CHANGED
|
@@ -173,6 +173,22 @@ async function findEntity(
|
|
|
173
173
|
return _.first(entities);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
async function findById(
|
|
177
|
+
server: IRpdServer,
|
|
178
|
+
dataAccessor: IRpdDataAccessor,
|
|
179
|
+
id: any,
|
|
180
|
+
): Promise<any> {
|
|
181
|
+
return await findEntity(server, dataAccessor, {
|
|
182
|
+
filters: [
|
|
183
|
+
{
|
|
184
|
+
operator: "eq",
|
|
185
|
+
field: "id",
|
|
186
|
+
value: id,
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
176
192
|
async function replaceFiltersWithFiltersOperator(
|
|
177
193
|
server: IRpdServer,
|
|
178
194
|
model: RpdDataModel,
|
|
@@ -544,7 +560,7 @@ async function updateEntityById(
|
|
|
544
560
|
throw new Error("Id is required when updating an entity.")
|
|
545
561
|
}
|
|
546
562
|
|
|
547
|
-
const entity = await
|
|
563
|
+
const entity = await findById(server, dataAccessor, id);
|
|
548
564
|
if (!entity) {
|
|
549
565
|
throw new Error(`${model.namespace}.${model.singularCode} with id "${id}" was not found.`);
|
|
550
566
|
}
|
|
@@ -702,15 +718,7 @@ export default class EntityManager<TEntity=any> {
|
|
|
702
718
|
}
|
|
703
719
|
|
|
704
720
|
async findById(id: any): Promise<TEntity | null> {
|
|
705
|
-
return await this
|
|
706
|
-
filters: [
|
|
707
|
-
{
|
|
708
|
-
operator: "eq",
|
|
709
|
-
field: "id",
|
|
710
|
-
value: id,
|
|
711
|
-
}
|
|
712
|
-
]
|
|
713
|
-
});
|
|
721
|
+
return await findById(this.#server, this.#dataAccessor, id);
|
|
714
722
|
}
|
|
715
723
|
|
|
716
724
|
async createEntity(options: CreateEntityOptions, plugin: RapidPlugin): Promise<TEntity> {
|