@loomcore/api 0.0.47 → 0.0.48
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.
|
@@ -195,16 +195,6 @@ export class GenericApiService {
|
|
|
195
195
|
const entities = await this.onBeforeUpdate(userContext, preparedEntities);
|
|
196
196
|
const operations = [];
|
|
197
197
|
const entityIds = [];
|
|
198
|
-
console.log('--- DIAGNOSTICS: Entities received in batchUpdate ---');
|
|
199
|
-
entities.forEach((entity, index) => {
|
|
200
|
-
const entityWithId = entity;
|
|
201
|
-
if (entityWithId && entityWithId._id) {
|
|
202
|
-
console.log(` [${index}]: ID is ${entityWithId._id.toString()}, Type is ${entityWithId._id.constructor.name}`);
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
console.log(` [${index}]: Entity has no _id or is null.`);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
198
|
for (const entity of entities) {
|
|
209
199
|
const { _id, ...updateData } = entity;
|
|
210
200
|
if (!_id || !(_id instanceof ObjectId)) {
|
|
@@ -380,7 +370,6 @@ export class GenericApiService {
|
|
|
380
370
|
return transformedEntity;
|
|
381
371
|
}
|
|
382
372
|
stripSenderProvidedSystemProperties(userContext, doc, allowId = false) {
|
|
383
|
-
console.log(`in stripSenderProvidedSystemProperties, allowId is ${allowId}`);
|
|
384
373
|
const isSystemUser = userContext.user?._id === 'system';
|
|
385
374
|
if (isSystemUser) {
|
|
386
375
|
return;
|
|
@@ -404,21 +393,11 @@ export class GenericApiService {
|
|
|
404
393
|
}
|
|
405
394
|
}
|
|
406
395
|
async prepareDataForBatchUpdate(userContext, entities) {
|
|
407
|
-
|
|
408
|
-
return Promise.all(entities.map(item => {
|
|
409
|
-
const allowId = true;
|
|
410
|
-
console.log(`in prepareDataForBatchUpdate, item is ${JSON.stringify(item)}, and allowId is ${allowId}`);
|
|
411
|
-
return this.prepareEntity(userContext, item, false, allowId);
|
|
412
|
-
}));
|
|
396
|
+
return Promise.all(entities.map(item => this.prepareEntity(userContext, item, false, true)));
|
|
413
397
|
}
|
|
414
398
|
async prepareEntity(userContext, entity, isCreate, allowId = false) {
|
|
415
|
-
console.log(`ENTRY: prepareEntity called with allowId = ${allowId}`);
|
|
416
399
|
const preparedEntity = _.clone(entity);
|
|
417
|
-
console.log(`in prepareEntity, pluralResourceName is ${this.pluralResourceName}`);
|
|
418
|
-
console.log(`before stripping system properties, preparedEntity is ${JSON.stringify(preparedEntity)}`);
|
|
419
|
-
console.log(`allowId is ${allowId}`);
|
|
420
400
|
this.stripSenderProvidedSystemProperties(userContext, preparedEntity, allowId);
|
|
421
|
-
console.log(`after stripping system properties, preparedEntity is ${JSON.stringify(preparedEntity)}`);
|
|
422
401
|
if (this.modelSpec?.isAuditable) {
|
|
423
402
|
if (isCreate) {
|
|
424
403
|
this.auditForCreate(userContext, preparedEntity);
|
|
@@ -431,27 +410,19 @@ export class GenericApiService {
|
|
|
431
410
|
if (this.modelSpec) {
|
|
432
411
|
let entityId = null;
|
|
433
412
|
if (allowId) {
|
|
434
|
-
console.log(`_id is present and equals ${preparedEntity._id}`);
|
|
435
413
|
entityId = preparedEntity._id;
|
|
436
414
|
}
|
|
415
|
+
console.log(`preparedEntity is ${JSON.stringify(preparedEntity)}`);
|
|
437
416
|
cleanedEntity = this.modelSpec.decode(preparedEntity);
|
|
417
|
+
console.log(`cleanedEntity is ${JSON.stringify(cleanedEntity)}`);
|
|
438
418
|
if (allowId && entityId) {
|
|
439
|
-
console.log(`after decode, restoring _id to ${entityId}`);
|
|
440
419
|
cleanedEntity._id = entityId;
|
|
441
420
|
}
|
|
442
421
|
}
|
|
443
422
|
if (!this.modelSpec?.fullSchema) {
|
|
444
423
|
throw new ServerError(`Cannot prepare entity: No model specification with schema provided for ${this.pluralResourceName}`);
|
|
445
424
|
}
|
|
446
|
-
|
|
447
|
-
const finalEntityWithId = finalEntity;
|
|
448
|
-
if (finalEntityWithId && finalEntityWithId._id) {
|
|
449
|
-
console.log(`--- DIAGNOSTICS: In prepareEntity, after conversion, ID is ${finalEntityWithId._id.toString()}, Type is ${finalEntityWithId._id.constructor.name} ---`);
|
|
450
|
-
}
|
|
451
|
-
else {
|
|
452
|
-
console.log('--- DIAGNOSTICS: In prepareEntity, after conversion, entity has no _id or is null. ---');
|
|
453
|
-
}
|
|
454
|
-
return finalEntity;
|
|
425
|
+
return dbUtils.convertStringsToObjectIds(cleanedEntity, this.modelSpec.fullSchema);
|
|
455
426
|
}
|
|
456
427
|
prepareQuery(userContext, query) {
|
|
457
428
|
return query;
|