@loomcore/api 0.0.47 → 0.0.49

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
- console.log('--- DIAGNOSTICS: Executing prepareDataForBatchUpdate ---');
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);
@@ -427,31 +406,14 @@ export class GenericApiService {
427
406
  this.auditForUpdate(userContext, preparedEntity);
428
407
  }
429
408
  }
430
- let cleanedEntity = preparedEntity;
431
- if (this.modelSpec) {
432
- let entityId = null;
433
- if (allowId) {
434
- console.log(`_id is present and equals ${preparedEntity._id}`);
435
- entityId = preparedEntity._id;
436
- }
437
- cleanedEntity = this.modelSpec.decode(preparedEntity);
438
- if (allowId && entityId) {
439
- console.log(`after decode, restoring _id to ${entityId}`);
440
- cleanedEntity._id = entityId;
441
- }
442
- }
443
409
  if (!this.modelSpec?.fullSchema) {
444
410
  throw new ServerError(`Cannot prepare entity: No model specification with schema provided for ${this.pluralResourceName}`);
445
411
  }
446
- const finalEntity = dbUtils.convertStringsToObjectIds(cleanedEntity, this.modelSpec.fullSchema);
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. ---');
412
+ let cleanedEntity = preparedEntity;
413
+ if (this.modelSpec) {
414
+ cleanedEntity = this.modelSpec.decode(preparedEntity);
453
415
  }
454
- return finalEntity;
416
+ return dbUtils.convertStringsToObjectIds(cleanedEntity, this.modelSpec.fullSchema);
455
417
  }
456
418
  prepareQuery(userContext, query) {
457
419
  return query;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
6
6
  "scripts": {