@ruiapp/rapid-core 0.1.45 → 0.1.47
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 +41 -6
- package/package.json +1 -1
- package/src/dataAccess/entityManager.ts +43 -6
package/dist/index.js
CHANGED
|
@@ -2028,6 +2028,18 @@ async function findEntities(server, dataAccessor, options) {
|
|
|
2028
2028
|
}
|
|
2029
2029
|
}
|
|
2030
2030
|
});
|
|
2031
|
+
// if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
|
|
2032
|
+
if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
|
|
2033
|
+
const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter(property => property.relation === "one" && !property.linkTableName);
|
|
2034
|
+
oneRelationPropertiesWithNoLinkTable.forEach((property) => {
|
|
2035
|
+
if (property.targetIdColumnName) {
|
|
2036
|
+
columnsToSelect.push({
|
|
2037
|
+
name: property.targetIdColumnName,
|
|
2038
|
+
tableName: property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2031
2043
|
const rowFilters = await convertEntityFiltersToRowFilters(server, model, baseModel, options.filters);
|
|
2032
2044
|
const findRowOptions = {
|
|
2033
2045
|
filters: rowFilters,
|
|
@@ -2265,16 +2277,39 @@ async function convertEntityFiltersToRowFilters(server, model, baseModel, filter
|
|
|
2265
2277
|
}
|
|
2266
2278
|
}
|
|
2267
2279
|
else {
|
|
2268
|
-
const
|
|
2269
|
-
|
|
2270
|
-
return property.code ===
|
|
2280
|
+
const filterField = filter.field;
|
|
2281
|
+
let property = getEntityProperty(server, model, (property) => {
|
|
2282
|
+
return property.code === filterField;
|
|
2271
2283
|
});
|
|
2284
|
+
let columnName = "";
|
|
2285
|
+
if (property) {
|
|
2286
|
+
columnName = property.columnName || property.code;
|
|
2287
|
+
}
|
|
2288
|
+
else {
|
|
2289
|
+
property = getEntityProperty(server, model, (property) => {
|
|
2290
|
+
return property.columnName === filterField;
|
|
2291
|
+
});
|
|
2292
|
+
if (property) {
|
|
2293
|
+
columnName = property.columnName;
|
|
2294
|
+
}
|
|
2295
|
+
else {
|
|
2296
|
+
property = getEntityProperty(server, model, (property) => {
|
|
2297
|
+
return property.targetIdColumnName === filterField;
|
|
2298
|
+
});
|
|
2299
|
+
if (property) {
|
|
2300
|
+
columnName = property.targetIdColumnName;
|
|
2301
|
+
}
|
|
2302
|
+
else {
|
|
2303
|
+
columnName = filterField;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2272
2307
|
// TODO: do not use `any` here
|
|
2273
2308
|
replacedFilters.push({
|
|
2274
2309
|
operator: filter.operator,
|
|
2275
2310
|
field: {
|
|
2276
|
-
name:
|
|
2277
|
-
tableName: property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
2311
|
+
name: columnName,
|
|
2312
|
+
tableName: (property && property.isBaseProperty) ? baseModel.tableName : model.tableName,
|
|
2278
2313
|
},
|
|
2279
2314
|
value: filter.value,
|
|
2280
2315
|
itemType: filter.itemType,
|
|
@@ -2407,7 +2442,7 @@ async function createEntity(server, dataAccessor, options, plugin) {
|
|
|
2407
2442
|
row.id = newBaseRow.id;
|
|
2408
2443
|
}
|
|
2409
2444
|
const newRow = await dataAccessor.create(row);
|
|
2410
|
-
const newEntity = mapDbRowToEntity(server, model, Object.assign(newBaseRow, newRow), true);
|
|
2445
|
+
const newEntity = mapDbRowToEntity(server, model, newBaseRow ? Object.assign(newBaseRow, newRow) : newRow, true);
|
|
2411
2446
|
// save many-relation properties
|
|
2412
2447
|
for (const property of manyRelationPropertiesToCreate) {
|
|
2413
2448
|
newEntity[property.code] = [];
|
package/package.json
CHANGED
|
@@ -109,6 +109,19 @@ async function findEntities(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
109
109
|
}
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
// if `keepNonPropertyFields` is true and `properties` are not specified, then select relation columns automatically.
|
|
113
|
+
if (options.keepNonPropertyFields && (!options.properties || !options.properties.length)) {
|
|
114
|
+
const oneRelationPropertiesWithNoLinkTable = getEntityPropertiesIncludingBase(server, model).filter(property => property.relation === "one" && !property.linkTableName);
|
|
115
|
+
oneRelationPropertiesWithNoLinkTable.forEach((property) => {
|
|
116
|
+
if (property.targetIdColumnName) {
|
|
117
|
+
columnsToSelect.push({
|
|
118
|
+
name: property.targetIdColumnName,
|
|
119
|
+
tableName: property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
112
125
|
const rowFilters = await convertEntityFiltersToRowFilters(server, model, baseModel, options.filters);
|
|
113
126
|
const findRowOptions: FindRowOptions = {
|
|
114
127
|
filters: rowFilters,
|
|
@@ -363,16 +376,40 @@ async function convertEntityFiltersToRowFilters(server: IRpdServer, model: RpdDa
|
|
|
363
376
|
});
|
|
364
377
|
}
|
|
365
378
|
} else {
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
return property.code ===
|
|
379
|
+
const filterField = (filter as EntityNonRelationPropertyFilterOptions).field;
|
|
380
|
+
let property: RpdDataModelProperty = getEntityProperty(server, model, (property) => {
|
|
381
|
+
return property.code === filterField;
|
|
369
382
|
});
|
|
383
|
+
|
|
384
|
+
let columnName = "";
|
|
385
|
+
if (property) {
|
|
386
|
+
columnName = property.columnName || property.code;
|
|
387
|
+
} else {
|
|
388
|
+
property = getEntityProperty(server, model, (property) => {
|
|
389
|
+
return property.columnName === filterField;
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
if (property) {
|
|
393
|
+
columnName = property.columnName;
|
|
394
|
+
} else {
|
|
395
|
+
property = getEntityProperty(server, model, (property) => {
|
|
396
|
+
return property.targetIdColumnName === filterField;
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
if (property) {
|
|
400
|
+
columnName = property.targetIdColumnName;
|
|
401
|
+
} else {
|
|
402
|
+
columnName = filterField;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
370
407
|
// TODO: do not use `any` here
|
|
371
408
|
replacedFilters.push({
|
|
372
409
|
operator: filter.operator,
|
|
373
410
|
field: {
|
|
374
|
-
name:
|
|
375
|
-
tableName: property.isBaseProperty ? baseModel.tableName : model.tableName,
|
|
411
|
+
name: columnName,
|
|
412
|
+
tableName: (property && property.isBaseProperty) ? baseModel.tableName : model.tableName,
|
|
376
413
|
},
|
|
377
414
|
value: (filter as any).value,
|
|
378
415
|
itemType: (filter as any).itemType,
|
|
@@ -523,7 +560,7 @@ async function createEntity(server: IRpdServer, dataAccessor: IRpdDataAccessor,
|
|
|
523
560
|
row.id = newBaseRow.id;
|
|
524
561
|
}
|
|
525
562
|
const newRow = await dataAccessor.create(row);
|
|
526
|
-
const newEntity = mapDbRowToEntity(server, model, Object.assign(newBaseRow, newRow), true);
|
|
563
|
+
const newEntity = mapDbRowToEntity(server, model, newBaseRow ? Object.assign(newBaseRow, newRow) : newRow, true);
|
|
527
564
|
|
|
528
565
|
// save many-relation properties
|
|
529
566
|
for (const property of manyRelationPropertiesToCreate) {
|