nestjs-query-mikro-orm 0.0.9 → 0.1.1
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/README.md +1 -1
- package/dist/index.cjs +150 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.mjs +129 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ The package automatically detects the import method and serves the appropriate f
|
|
|
30
30
|
pnpm add nestjs-query-mikro-orm
|
|
31
31
|
|
|
32
32
|
# Install peer dependencies if you haven't already
|
|
33
|
-
pnpm add @mikro-orm/core @nestjs/common @nestjs/core @nestjs-query
|
|
33
|
+
pnpm add @mikro-orm/core @nestjs/common @nestjs/core @ptc-org/nestjs-query-core reflect-metadata rxjs
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
## Quick Start
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var nestjs = require('@mikro-orm/nestjs');
|
|
4
|
-
var
|
|
5
|
-
var core
|
|
6
|
-
var assembler_serializer = require('@nestjs-query
|
|
4
|
+
var nestjsQueryCore = require('@ptc-org/nestjs-query-core');
|
|
5
|
+
var core = require('@mikro-orm/core');
|
|
6
|
+
var assembler_serializer = require('@ptc-org/nestjs-query-core/src/assemblers/assembler.serializer');
|
|
7
7
|
var common = require('@nestjs/common');
|
|
8
8
|
var classTransformer = require('class-transformer');
|
|
9
9
|
var merge = require('lodash.merge');
|
|
@@ -383,7 +383,7 @@ var FilterQueryBuilder = class {
|
|
|
383
383
|
}
|
|
384
384
|
getReferencedRelations(filter) {
|
|
385
385
|
const relationNames = this.relationNames;
|
|
386
|
-
const referencedFields =
|
|
386
|
+
const referencedFields = nestjsQueryCore.getFilterFields(filter);
|
|
387
387
|
return referencedFields.filter((f) => relationNames.includes(f));
|
|
388
388
|
}
|
|
389
389
|
getReferencedRelationsRecursive(metadataOrFilter = {}, filter) {
|
|
@@ -840,7 +840,14 @@ var RelationQueryBuilder = class {
|
|
|
840
840
|
const entityKeys = Object.keys(entityAsRecord);
|
|
841
841
|
const matchingKey = entityKeys.find((key) => {
|
|
842
842
|
const keyLower = key.toLowerCase();
|
|
843
|
-
|
|
843
|
+
if (keyLower === "id" || !keyLower.endsWith("id")) {
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
const base = keyLower.replace(/id$/, "");
|
|
847
|
+
if (!base) {
|
|
848
|
+
return false;
|
|
849
|
+
}
|
|
850
|
+
return relationNameLower.includes(base);
|
|
844
851
|
});
|
|
845
852
|
if (matchingKey) {
|
|
846
853
|
fkValue = entityAsRecord[matchingKey];
|
|
@@ -970,7 +977,8 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
970
977
|
});
|
|
971
978
|
const funcSelects = [];
|
|
972
979
|
aggs.forEach(([func, fields]) => {
|
|
973
|
-
|
|
980
|
+
if (!fields || fields.length === 0) return;
|
|
981
|
+
const aliases = fields.map((f) => {
|
|
974
982
|
const col = alias ? `\`${alias}\`.\`${String(f)}\`` : `\`${String(f)}\``;
|
|
975
983
|
return [
|
|
976
984
|
`${func}(${col})`,
|
|
@@ -1025,7 +1033,8 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
1025
1033
|
]
|
|
1026
1034
|
];
|
|
1027
1035
|
return aggs.reduce((cols, [func, fields]) => {
|
|
1028
|
-
|
|
1036
|
+
if (!fields || fields.length === 0) return cols;
|
|
1037
|
+
const aliases = fields.map((f) => this.getAggregateAlias(func, f));
|
|
1029
1038
|
return [
|
|
1030
1039
|
...cols,
|
|
1031
1040
|
...aliases
|
|
@@ -1101,19 +1110,39 @@ var AggregateBuilder = class _AggregateBuilder {
|
|
|
1101
1110
|
*/
|
|
1102
1111
|
build(qb, aggregate, alias) {
|
|
1103
1112
|
const metadata = qb.mainAlias?.metadata;
|
|
1104
|
-
const selects = [
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1113
|
+
const selects = [];
|
|
1114
|
+
selects.push(...this.createGroupBySelect(aggregate.groupBy, alias, metadata));
|
|
1115
|
+
const aggs = [
|
|
1116
|
+
[
|
|
1117
|
+
"COUNT",
|
|
1118
|
+
aggregate.count
|
|
1119
|
+
],
|
|
1120
|
+
[
|
|
1121
|
+
"SUM",
|
|
1122
|
+
aggregate.sum
|
|
1123
|
+
],
|
|
1124
|
+
[
|
|
1125
|
+
"AVG",
|
|
1126
|
+
aggregate.avg
|
|
1127
|
+
],
|
|
1128
|
+
[
|
|
1129
|
+
"MAX",
|
|
1130
|
+
aggregate.max
|
|
1131
|
+
],
|
|
1132
|
+
[
|
|
1133
|
+
"MIN",
|
|
1134
|
+
aggregate.min
|
|
1135
|
+
]
|
|
1111
1136
|
];
|
|
1137
|
+
aggs.forEach(([func, fields]) => {
|
|
1138
|
+
if (!fields || fields.length === 0) return;
|
|
1139
|
+
selects.push(...this.createAggSelect(func, fields, alias, metadata));
|
|
1140
|
+
});
|
|
1112
1141
|
if (!selects.length) {
|
|
1113
1142
|
throw new common.BadRequestException("No aggregate fields found.");
|
|
1114
1143
|
}
|
|
1115
1144
|
selects.forEach(([selectExpr, selectAlias]) => {
|
|
1116
|
-
qb.addSelect(core
|
|
1145
|
+
qb.addSelect(core.raw(`${selectExpr} as "${selectAlias}"`));
|
|
1117
1146
|
});
|
|
1118
1147
|
return qb;
|
|
1119
1148
|
}
|
|
@@ -1152,15 +1181,19 @@ var RelationQueryService = class {
|
|
|
1152
1181
|
if (Array.isArray(dto)) {
|
|
1153
1182
|
return this.batchQueryRelations(RelationClass, relationName, dto, query);
|
|
1154
1183
|
}
|
|
1155
|
-
|
|
1184
|
+
if (this.isRelationClassIdentity(RelationClass, relationName)) {
|
|
1185
|
+
const relationQueryBuilder2 = this.getRelationQueryBuilder(relationName);
|
|
1186
|
+
return await relationQueryBuilder2.selectAndExecute(dto, query);
|
|
1187
|
+
}
|
|
1188
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1156
1189
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1157
|
-
return assembler.
|
|
1190
|
+
return assembler.convertToDTOs(await relationQueryBuilder.selectAndExecute(dto, assembler.convertQuery(query)));
|
|
1158
1191
|
}
|
|
1159
1192
|
async aggregateRelations(RelationClass, relationName, dto, filter, aggregate) {
|
|
1160
1193
|
if (Array.isArray(dto)) {
|
|
1161
1194
|
return this.batchAggregateRelations(RelationClass, relationName, dto, filter, aggregate);
|
|
1162
1195
|
}
|
|
1163
|
-
const assembler =
|
|
1196
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1164
1197
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1165
1198
|
const rawResults = await relationQueryBuilder.aggregate(dto, assembler.convertQuery({
|
|
1166
1199
|
filter
|
|
@@ -1175,7 +1208,7 @@ var RelationQueryService = class {
|
|
|
1175
1208
|
if (Array.isArray(dto)) {
|
|
1176
1209
|
return this.batchCountRelations(RelationClass, relationName, dto, filter);
|
|
1177
1210
|
}
|
|
1178
|
-
const assembler =
|
|
1211
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1179
1212
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1180
1213
|
return relationQueryBuilder.count(dto, assembler.convertQuery({
|
|
1181
1214
|
filter
|
|
@@ -1185,7 +1218,17 @@ var RelationQueryService = class {
|
|
|
1185
1218
|
if (Array.isArray(dto)) {
|
|
1186
1219
|
return this.batchFindRelations(RelationClass, relationName, dto, opts);
|
|
1187
1220
|
}
|
|
1188
|
-
|
|
1221
|
+
if (this.isRelationClassIdentity(RelationClass, relationName)) {
|
|
1222
|
+
const relationQueryBuilder2 = this.getRelationQueryBuilder(relationName);
|
|
1223
|
+
const relations2 = await relationQueryBuilder2.selectAndExecute(dto, {
|
|
1224
|
+
filter: opts?.filter,
|
|
1225
|
+
paging: {
|
|
1226
|
+
limit: 1
|
|
1227
|
+
}
|
|
1228
|
+
});
|
|
1229
|
+
return relations2[0];
|
|
1230
|
+
}
|
|
1231
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1189
1232
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1190
1233
|
const relations = await relationQueryBuilder.selectAndExecute(dto, {
|
|
1191
1234
|
filter: opts?.filter,
|
|
@@ -1205,10 +1248,20 @@ var RelationQueryService = class {
|
|
|
1205
1248
|
*/
|
|
1206
1249
|
async addRelations(relationName, id, relationIds, opts) {
|
|
1207
1250
|
const entity = await this.getById(id, opts);
|
|
1251
|
+
const meta = this.getRelationMeta(relationName);
|
|
1208
1252
|
const relations = await this.getRelations(relationName, relationIds, opts?.relationFilter);
|
|
1209
1253
|
if (!this.foundAllRelations(relationIds, relations)) {
|
|
1210
1254
|
throw new Error(`Unable to find all ${relationName} to add to ${this.EntityClass.name}`);
|
|
1211
1255
|
}
|
|
1256
|
+
if (meta.kind === "1:m" && meta.mappedBy) {
|
|
1257
|
+
for (const relation of relations) {
|
|
1258
|
+
core.wrap(relation).assign({
|
|
1259
|
+
[meta.mappedBy]: entity
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
await this.repo.getEntityManager().flush();
|
|
1263
|
+
return entity;
|
|
1264
|
+
}
|
|
1212
1265
|
const collection = entity[relationName];
|
|
1213
1266
|
if (collection && typeof collection.add === "function") {
|
|
1214
1267
|
for (const relation of relations) {
|
|
@@ -1229,12 +1282,33 @@ var RelationQueryService = class {
|
|
|
1229
1282
|
*/
|
|
1230
1283
|
async setRelations(relationName, id, relationIds, opts) {
|
|
1231
1284
|
const entity = await this.getById(id, opts);
|
|
1285
|
+
const meta = this.getRelationMeta(relationName);
|
|
1232
1286
|
const relations = await this.getRelations(relationName, relationIds, opts?.relationFilter);
|
|
1233
1287
|
if (relationIds.length) {
|
|
1234
1288
|
if (!this.foundAllRelations(relationIds, relations)) {
|
|
1235
1289
|
throw new Error(`Unable to find all ${relationName} to set on ${this.EntityClass.name}`);
|
|
1236
1290
|
}
|
|
1237
1291
|
}
|
|
1292
|
+
if (meta.kind === "1:m" && meta.mappedBy) {
|
|
1293
|
+
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1294
|
+
const currentRelations = await relationQueryBuilder.selectAndExecute(entity, {});
|
|
1295
|
+
const nextSet = new Set(relations.map((r) => core.wrap(r).getPrimaryKey()));
|
|
1296
|
+
for (const currentRelation of currentRelations) {
|
|
1297
|
+
const currentPk = core.wrap(currentRelation).getPrimaryKey();
|
|
1298
|
+
if (!nextSet.has(currentPk)) {
|
|
1299
|
+
core.wrap(currentRelation).assign({
|
|
1300
|
+
[meta.mappedBy]: null
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
for (const relation of relations) {
|
|
1305
|
+
core.wrap(relation).assign({
|
|
1306
|
+
[meta.mappedBy]: entity
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
await this.repo.getEntityManager().flush();
|
|
1310
|
+
return entity;
|
|
1311
|
+
}
|
|
1238
1312
|
const collection = entity[relationName];
|
|
1239
1313
|
if (collection && typeof collection.set === "function") {
|
|
1240
1314
|
await collection.init();
|
|
@@ -1259,7 +1333,7 @@ var RelationQueryService = class {
|
|
|
1259
1333
|
if (!relation) {
|
|
1260
1334
|
throw new Error(`Unable to find ${relationName} to set on ${this.EntityClass.name}`);
|
|
1261
1335
|
}
|
|
1262
|
-
core
|
|
1336
|
+
core.wrap(entity).assign({
|
|
1263
1337
|
[relationName]: relation
|
|
1264
1338
|
});
|
|
1265
1339
|
await this.repo.getEntityManager().flush();
|
|
@@ -1274,10 +1348,20 @@ var RelationQueryService = class {
|
|
|
1274
1348
|
*/
|
|
1275
1349
|
async removeRelations(relationName, id, relationIds, opts) {
|
|
1276
1350
|
const entity = await this.getById(id, opts);
|
|
1351
|
+
const meta = this.getRelationMeta(relationName);
|
|
1277
1352
|
const relations = await this.getRelations(relationName, relationIds, opts?.relationFilter);
|
|
1278
1353
|
if (!this.foundAllRelations(relationIds, relations)) {
|
|
1279
1354
|
throw new Error(`Unable to find all ${relationName} to remove from ${this.EntityClass.name}`);
|
|
1280
1355
|
}
|
|
1356
|
+
if (meta.kind === "1:m" && meta.mappedBy) {
|
|
1357
|
+
for (const relation of relations) {
|
|
1358
|
+
core.wrap(relation).assign({
|
|
1359
|
+
[meta.mappedBy]: null
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
await this.repo.getEntityManager().flush();
|
|
1363
|
+
return entity;
|
|
1364
|
+
}
|
|
1281
1365
|
const collection = entity[relationName];
|
|
1282
1366
|
if (collection && typeof collection.remove === "function") {
|
|
1283
1367
|
await collection.init();
|
|
@@ -1306,14 +1390,25 @@ var RelationQueryService = class {
|
|
|
1306
1390
|
const meta = this.getRelationMeta(relationName);
|
|
1307
1391
|
if (meta.kind === "1:1" || meta.kind === "m:1") {
|
|
1308
1392
|
const fkFieldName = `${relationName}Id`;
|
|
1309
|
-
const assignData = {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1393
|
+
const assignData = {};
|
|
1394
|
+
const ownDescriptor = Object.getOwnPropertyDescriptor(entity, fkFieldName);
|
|
1395
|
+
const protoDescriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(entity), fkFieldName);
|
|
1396
|
+
const descriptor = ownDescriptor ?? protoDescriptor;
|
|
1397
|
+
const canAssignFk = fkFieldName in entity && (!descriptor || Boolean(descriptor.set) || descriptor.writable === true);
|
|
1398
|
+
if (canAssignFk) {
|
|
1313
1399
|
assignData[fkFieldName] = null;
|
|
1400
|
+
} else {
|
|
1401
|
+
assignData[relationName] = null;
|
|
1314
1402
|
}
|
|
1315
|
-
core
|
|
1403
|
+
core.wrap(entity).assign(assignData);
|
|
1316
1404
|
} else {
|
|
1405
|
+
if (meta.kind === "1:m" && meta.mappedBy) {
|
|
1406
|
+
core.wrap(relation).assign({
|
|
1407
|
+
[meta.mappedBy]: null
|
|
1408
|
+
});
|
|
1409
|
+
await this.repo.getEntityManager().flush();
|
|
1410
|
+
return entity;
|
|
1411
|
+
}
|
|
1317
1412
|
const collection = entity[relationName];
|
|
1318
1413
|
if (collection && typeof collection.remove === "function") {
|
|
1319
1414
|
await collection.init();
|
|
@@ -1334,13 +1429,14 @@ var RelationQueryService = class {
|
|
|
1334
1429
|
* @param query - A query to filter, page or sort relations.
|
|
1335
1430
|
*/
|
|
1336
1431
|
async batchQueryRelations(RelationClass, relationName, entities, query) {
|
|
1337
|
-
const
|
|
1432
|
+
const bypassAssembler = this.isRelationClassIdentity(RelationClass, relationName);
|
|
1433
|
+
const assembler = bypassAssembler ? void 0 : nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1338
1434
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1339
|
-
const convertedQuery = assembler.convertQuery(query);
|
|
1435
|
+
const convertedQuery = assembler ? assembler.convertQuery(query) : query;
|
|
1340
1436
|
const results = /* @__PURE__ */ new Map();
|
|
1341
1437
|
await Promise.all(entities.map(async (entity) => {
|
|
1342
1438
|
const relations = await relationQueryBuilder.selectAndExecute(entity, convertedQuery);
|
|
1343
|
-
const relationDtos = assembler.convertToDTOs(relations);
|
|
1439
|
+
const relationDtos = bypassAssembler ? relations : await assembler.convertToDTOs(relations);
|
|
1344
1440
|
if (relationDtos.length > 0) {
|
|
1345
1441
|
results.set(entity, relationDtos);
|
|
1346
1442
|
}
|
|
@@ -1355,7 +1451,7 @@ var RelationQueryService = class {
|
|
|
1355
1451
|
* @param query - A query to filter, page or sort relations.
|
|
1356
1452
|
*/
|
|
1357
1453
|
async batchAggregateRelations(RelationClass, relationName, entities, filter, aggregate) {
|
|
1358
|
-
const assembler =
|
|
1454
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1359
1455
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1360
1456
|
const convertedQuery = assembler.convertQuery({
|
|
1361
1457
|
filter
|
|
@@ -1376,7 +1472,7 @@ var RelationQueryService = class {
|
|
|
1376
1472
|
* @param filter - The filter to apply to the relation query.
|
|
1377
1473
|
*/
|
|
1378
1474
|
async batchCountRelations(RelationClass, relationName, entities, filter) {
|
|
1379
|
-
const assembler =
|
|
1475
|
+
const assembler = nestjsQueryCore.AssemblerFactory.getAssembler(RelationClass, this.getRelationEntity(relationName));
|
|
1380
1476
|
const relationQueryBuilder = this.getRelationQueryBuilder(relationName);
|
|
1381
1477
|
const convertedQuery = assembler.convertQuery({
|
|
1382
1478
|
filter
|
|
@@ -1410,6 +1506,10 @@ var RelationQueryService = class {
|
|
|
1410
1506
|
});
|
|
1411
1507
|
return results;
|
|
1412
1508
|
}
|
|
1509
|
+
isRelationClassIdentity(RelationClass, relationName) {
|
|
1510
|
+
const relationEntity = this.getRelationEntity(relationName);
|
|
1511
|
+
return RelationClass === relationEntity || RelationClass.name === relationEntity.name;
|
|
1512
|
+
}
|
|
1413
1513
|
getRelationMeta(relationName) {
|
|
1414
1514
|
const em = this.repo.getEntityManager();
|
|
1415
1515
|
const metadata = em.getMetadata().get(this.repo.getEntityName());
|
|
@@ -1420,12 +1520,14 @@ var RelationQueryService = class {
|
|
|
1420
1520
|
return {
|
|
1421
1521
|
kind: relationMeta.kind,
|
|
1422
1522
|
type: relationMeta.type,
|
|
1423
|
-
entity: relationMeta.entity
|
|
1523
|
+
entity: relationMeta.entity,
|
|
1524
|
+
mappedBy: relationMeta.mappedBy
|
|
1424
1525
|
};
|
|
1425
1526
|
}
|
|
1426
1527
|
getRelationEntity(relationName) {
|
|
1427
1528
|
const relationMeta = this.getRelationMeta(relationName);
|
|
1428
|
-
|
|
1529
|
+
const entity = relationMeta.entity();
|
|
1530
|
+
return entity && "class" in entity ? entity.class : entity;
|
|
1429
1531
|
}
|
|
1430
1532
|
async getRelations(relationName, ids, filter) {
|
|
1431
1533
|
const em = this.repo.getEntityManager();
|
|
@@ -1471,14 +1573,14 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1471
1573
|
this.useSoftDelete = opts?.useSoftDelete ?? false;
|
|
1472
1574
|
const serializer = assembler_serializer.getAssemblerSerializer(this.EntityClass);
|
|
1473
1575
|
if (!serializer) {
|
|
1474
|
-
|
|
1576
|
+
nestjsQueryCore.AssemblerSerializer((e) => {
|
|
1475
1577
|
const json = classTransformer.instanceToPlain(e, {
|
|
1476
1578
|
enableImplicitConversion: true,
|
|
1477
1579
|
excludeExtraneousValues: true,
|
|
1478
1580
|
exposeDefaultValues: true
|
|
1479
1581
|
});
|
|
1480
1582
|
const jsonWithRemovedEmptyObjects = Object.fromEntries(Object.entries(json).filter(([, value]) => !(value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)));
|
|
1481
|
-
const wrapped = core
|
|
1583
|
+
const wrapped = core.wrap(e, true);
|
|
1482
1584
|
const ormJson = "toObject" in wrapped ? wrapped.toObject() : {};
|
|
1483
1585
|
const data = {
|
|
1484
1586
|
...ormJson,
|
|
@@ -1486,8 +1588,8 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1486
1588
|
};
|
|
1487
1589
|
return data;
|
|
1488
1590
|
})(this.EntityClass);
|
|
1489
|
-
|
|
1490
|
-
const entity = this.repo.getEntityManager().
|
|
1591
|
+
nestjsQueryCore.AssemblerDeserializer((d) => {
|
|
1592
|
+
const entity = this.repo.getEntityManager().merge(this.EntityClass, d);
|
|
1491
1593
|
return entity;
|
|
1492
1594
|
})(this.EntityClass);
|
|
1493
1595
|
}
|
|
@@ -1498,7 +1600,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1498
1600
|
return metadata.class;
|
|
1499
1601
|
}
|
|
1500
1602
|
/**
|
|
1501
|
-
* Query for multiple entities, using a Query from `@nestjs-query
|
|
1603
|
+
* Query for multiple entities, using a Query from `@ptc-org/nestjs-query-core`.
|
|
1502
1604
|
*
|
|
1503
1605
|
* @example
|
|
1504
1606
|
* ```ts
|
|
@@ -1779,12 +1881,12 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1779
1881
|
const dateWithClearUndefined = Object.fromEntries(Object.entries(update).filter(([, value]) => value !== void 0));
|
|
1780
1882
|
this.ensureIdIsNotPresent(dateWithClearUndefined);
|
|
1781
1883
|
const entity = await this.getById(id, opts);
|
|
1782
|
-
core
|
|
1884
|
+
core.wrap(entity).assign(dateWithClearUndefined);
|
|
1783
1885
|
await this.repo.getEntityManager().flush();
|
|
1784
1886
|
return entity;
|
|
1785
1887
|
}
|
|
1786
1888
|
/**
|
|
1787
|
-
* Update multiple entities with a `@nestjs-query
|
|
1889
|
+
* Update multiple entities with a `@ptc-org/nestjs-query-core` Filter.
|
|
1788
1890
|
*
|
|
1789
1891
|
* @example
|
|
1790
1892
|
* ```ts
|
|
@@ -1802,7 +1904,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1802
1904
|
filter
|
|
1803
1905
|
});
|
|
1804
1906
|
for (const entity of entities) {
|
|
1805
|
-
core
|
|
1907
|
+
core.wrap(entity).assign(update);
|
|
1806
1908
|
}
|
|
1807
1909
|
await this.repo.getEntityManager().flush();
|
|
1808
1910
|
return {
|
|
@@ -1825,7 +1927,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1825
1927
|
const entity = await this.getById(id, opts);
|
|
1826
1928
|
const em = this.repo.getEntityManager();
|
|
1827
1929
|
if (this.useSoftDelete) {
|
|
1828
|
-
core
|
|
1930
|
+
core.wrap(entity).assign({
|
|
1829
1931
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1830
1932
|
});
|
|
1831
1933
|
await em.flush();
|
|
@@ -1835,7 +1937,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1835
1937
|
return entity;
|
|
1836
1938
|
}
|
|
1837
1939
|
/**
|
|
1838
|
-
* Delete multiple records with a `@nestjs-query
|
|
1940
|
+
* Delete multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
1839
1941
|
*
|
|
1840
1942
|
* @example
|
|
1841
1943
|
*
|
|
@@ -1854,7 +1956,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1854
1956
|
const em = this.repo.getEntityManager();
|
|
1855
1957
|
if (this.useSoftDelete) {
|
|
1856
1958
|
for (const entity of entities) {
|
|
1857
|
-
core
|
|
1959
|
+
core.wrap(entity).assign({
|
|
1858
1960
|
deletedAt: /* @__PURE__ */ new Date()
|
|
1859
1961
|
});
|
|
1860
1962
|
}
|
|
@@ -1904,14 +2006,14 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1904
2006
|
if (!entity) {
|
|
1905
2007
|
throw new common.NotFoundException(`Unable to find ${this.EntityClass.name} with id: ${id}`);
|
|
1906
2008
|
}
|
|
1907
|
-
core
|
|
2009
|
+
core.wrap(entity).assign({
|
|
1908
2010
|
deletedAt: null
|
|
1909
2011
|
});
|
|
1910
2012
|
await em.flush();
|
|
1911
2013
|
return entity;
|
|
1912
2014
|
}
|
|
1913
2015
|
/**
|
|
1914
|
-
* Restores multiple records with a `@nestjs-query
|
|
2016
|
+
* Restores multiple records with a `@ptc-org/nestjs-query-core` `Filter`.
|
|
1915
2017
|
*
|
|
1916
2018
|
* @example
|
|
1917
2019
|
*
|
|
@@ -1932,7 +2034,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1932
2034
|
filters: false
|
|
1933
2035
|
});
|
|
1934
2036
|
for (const entity of entities) {
|
|
1935
|
-
core
|
|
2037
|
+
core.wrap(entity).assign({
|
|
1936
2038
|
deletedAt: null
|
|
1937
2039
|
});
|
|
1938
2040
|
}
|
|
@@ -1984,7 +2086,7 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1984
2086
|
function createMikroOrmQueryServiceProvider(EntityClass, contextName) {
|
|
1985
2087
|
return {
|
|
1986
2088
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1987
|
-
provide:
|
|
2089
|
+
provide: nestjsQueryCore.getQueryServiceToken(EntityClass),
|
|
1988
2090
|
useFactory(repo) {
|
|
1989
2091
|
return new MikroOrmQueryService(repo);
|
|
1990
2092
|
},
|