@postxl/generator 0.64.0 → 0.65.0
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.
|
@@ -74,7 +74,7 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
74
74
|
[schemaMeta.view.serviceLocation.import]: schemaMeta.view.serviceClassName,
|
|
75
75
|
});
|
|
76
76
|
for (const relation of (0, fields_1.getRelationFields)(model)) {
|
|
77
|
-
// NOTE: We add
|
|
77
|
+
// NOTE: We add `toBrandedType` functions for foreign models for decoders.
|
|
78
78
|
if (relation.relationToModel.typeName === model.typeName) {
|
|
79
79
|
continue;
|
|
80
80
|
}
|
|
@@ -84,9 +84,6 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
84
84
|
from: refMeta.types.importPath,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
for (const { referencingModel } of model.references) {
|
|
88
|
-
imports.addTypeImport({ items: [referencingModel.brandedIdType], from: meta.types.importPath });
|
|
89
|
-
}
|
|
90
87
|
/**
|
|
91
88
|
* The name of the variable that holds the repository instance for the current model
|
|
92
89
|
* (e.g. when we generate business logic service for Aggregation, the AggregationRepository
|
|
@@ -100,6 +97,8 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
100
97
|
];
|
|
101
98
|
const decoders = meta.update.decoders;
|
|
102
99
|
const { view, update } = meta;
|
|
100
|
+
const deleteFn = generateDeleteFunction({ model, meta, m });
|
|
101
|
+
const deleteManyFn = generateDeleteManyMethod({ imports, model, meta, m });
|
|
103
102
|
/* prettier-ignore */
|
|
104
103
|
return /* ts */ `
|
|
105
104
|
import { Inject, Injectable, forwardRef } from '@nestjs/common'
|
|
@@ -259,10 +258,9 @@ function generateModelBusinessLogicUpdate({ model, meta }) {
|
|
|
259
258
|
return this.data.upsertMany({ items: data, execution })
|
|
260
259
|
}
|
|
261
260
|
|
|
262
|
-
|
|
263
|
-
${generateDeleteFunction({ model, meta, m })}
|
|
261
|
+
${deleteFn}
|
|
264
262
|
|
|
265
|
-
${
|
|
263
|
+
${deleteManyFn}
|
|
266
264
|
|
|
267
265
|
${generateCloneMethod({ model, meta, m })}
|
|
268
266
|
}
|
|
@@ -303,11 +301,16 @@ function generateDeleteFunction({ model, meta, m }) {
|
|
|
303
301
|
/**
|
|
304
302
|
* Returns a function that deletes multiple entities and all their related entities.
|
|
305
303
|
*/
|
|
306
|
-
function generateDeleteManyMethod({ model, meta, m }) {
|
|
304
|
+
function generateDeleteManyMethod({ imports, model, meta, m, }) {
|
|
307
305
|
const idArrays = [];
|
|
308
306
|
const idAssignments = [];
|
|
309
307
|
const deleteCalls = [];
|
|
310
308
|
for (const { referencingField, referencingModel } of model.references) {
|
|
309
|
+
// NOTE: We only delete back references that are required references.
|
|
310
|
+
if (!referencingField.isRequired) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
imports.addTypeImport({ items: [referencingModel.brandedIdType], from: meta.types.importPath });
|
|
311
314
|
const refModelMeta = (0, meta_1.getModelMetadata)({ model: referencingModel });
|
|
312
315
|
const refFieldMeta = (0, meta_1.getFieldMetadata)({ field: referencingField });
|
|
313
316
|
const idArray = `${refModelMeta.internalSingularName}${(0, string_1.capitalize)(referencingField.name)}s`;
|
|
@@ -322,7 +325,7 @@ function generateDeleteManyMethod({ model, meta, m }) {
|
|
|
322
325
|
deleteCalls.push(`await this.updateService.${refModelMeta.update.serviceVariableName}.deleteMany({ data: ${idArray}, execution })`);
|
|
323
326
|
}
|
|
324
327
|
let relatedEntities = '';
|
|
325
|
-
if (
|
|
328
|
+
if (idArrays.length > 0) {
|
|
326
329
|
relatedEntities = `
|
|
327
330
|
${idArrays.join('\n')}
|
|
328
331
|
|