nestjs-query-mikro-orm 0.1.2 → 0.1.4
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.cjs +29 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +30 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { MikroOrmModule, getRepositoryToken } from '@mikro-orm/nestjs';
|
|
2
|
-
import { getFilterFields, AssemblerFactory, getQueryServiceToken } from '@ptc-org/nestjs-query-core';
|
|
2
|
+
import { getFilterFields, AssemblerFactory, AssemblerSerializer, AssemblerDeserializer, getQueryServiceToken } from '@ptc-org/nestjs-query-core';
|
|
3
3
|
import { raw, wrap } from '@mikro-orm/core';
|
|
4
|
+
import { getAssemblerSerializer } from '@ptc-org/nestjs-query-core/src/assemblers/assembler.serializer';
|
|
4
5
|
import { BadRequestException, NotFoundException, MethodNotAllowedException } from '@nestjs/common';
|
|
6
|
+
import { instanceToPlain } from 'class-transformer';
|
|
5
7
|
import merge from 'lodash.merge';
|
|
6
8
|
|
|
7
9
|
var __defProp = Object.defineProperty;
|
|
@@ -1563,6 +1565,28 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1563
1565
|
super(), this.repo = repo;
|
|
1564
1566
|
this.filterQueryBuilder = opts?.filterQueryBuilder ?? new FilterQueryBuilder(this.repo);
|
|
1565
1567
|
this.useSoftDelete = opts?.useSoftDelete ?? false;
|
|
1568
|
+
const serializer = getAssemblerSerializer(this.EntityClass);
|
|
1569
|
+
if (!serializer) {
|
|
1570
|
+
AssemblerSerializer((e) => {
|
|
1571
|
+
const json = instanceToPlain(e, {
|
|
1572
|
+
enableImplicitConversion: true,
|
|
1573
|
+
excludeExtraneousValues: true,
|
|
1574
|
+
exposeDefaultValues: true
|
|
1575
|
+
});
|
|
1576
|
+
const jsonWithRemovedEmptyObjects = Object.fromEntries(Object.entries(json).filter(([, value]) => !(value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)));
|
|
1577
|
+
const wrapped = wrap(e, true);
|
|
1578
|
+
const ormJson = "toObject" in wrapped ? wrapped.toObject() : {};
|
|
1579
|
+
const data = {
|
|
1580
|
+
...ormJson,
|
|
1581
|
+
...jsonWithRemovedEmptyObjects
|
|
1582
|
+
};
|
|
1583
|
+
return data;
|
|
1584
|
+
})(this.EntityClass);
|
|
1585
|
+
AssemblerDeserializer((d) => {
|
|
1586
|
+
const entity = this.repo.getEntityManager().merge(this.EntityClass, d);
|
|
1587
|
+
return entity;
|
|
1588
|
+
})(this.EntityClass);
|
|
1589
|
+
}
|
|
1566
1590
|
}
|
|
1567
1591
|
get EntityClass() {
|
|
1568
1592
|
const em = this.repo.getEntityManager();
|
|
@@ -1848,7 +1872,8 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1848
1872
|
* @param opts - Additional options.
|
|
1849
1873
|
*/
|
|
1850
1874
|
async updateOne(id, update, opts) {
|
|
1851
|
-
const
|
|
1875
|
+
const data = "toPOJO" in wrap(update) ? wrap(update).toPOJO() : update;
|
|
1876
|
+
const dateWithClearUndefined = Object.fromEntries(Object.entries(data).filter(([, value]) => value !== void 0));
|
|
1852
1877
|
this.ensureIdIsNotPresent(dateWithClearUndefined);
|
|
1853
1878
|
const entity = await this.getById(id, opts);
|
|
1854
1879
|
wrap(entity).assign(dateWithClearUndefined);
|
|
@@ -1869,12 +1894,14 @@ var MikroOrmQueryService = class extends RelationQueryService {
|
|
|
1869
1894
|
* @param filter - A Filter used to find the records to update
|
|
1870
1895
|
*/
|
|
1871
1896
|
async updateMany(update, filter) {
|
|
1897
|
+
const data = "toPOJO" in wrap(update) ? wrap(update).toPOJO() : update;
|
|
1898
|
+
const dateWithClearUndefined = Object.fromEntries(Object.entries(data).filter(([, value]) => value !== void 0));
|
|
1872
1899
|
this.ensureIdIsNotPresent(update);
|
|
1873
1900
|
const entities = await this.query({
|
|
1874
1901
|
filter
|
|
1875
1902
|
});
|
|
1876
1903
|
for (const entity of entities) {
|
|
1877
|
-
wrap(entity).assign(
|
|
1904
|
+
wrap(entity).assign(dateWithClearUndefined);
|
|
1878
1905
|
}
|
|
1879
1906
|
await this.repo.getEntityManager().flush();
|
|
1880
1907
|
return {
|