@loomcore/api 0.0.50 → 0.0.52

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.
@@ -52,8 +52,10 @@ export class ApiController {
52
52
  apiUtils.apiResponse(res, 200, { data: pagedResult }, this.modelSpec, this.publicSchema);
53
53
  }
54
54
  async getById(req, res, next) {
55
+ console.log('Starting getById, id:', req.params?.id);
55
56
  let id = req.params?.id;
56
57
  res.set('Content-Type', 'application/json');
58
+ console.log('Calling this.service.getById()');
57
59
  const entity = await this.service.getById(req.userContext, id);
58
60
  apiUtils.apiResponse(res, 200, { data: entity }, this.modelSpec, this.publicSchema);
59
61
  }
@@ -73,6 +73,7 @@ export class GenericApiService {
73
73
  return pipeline;
74
74
  }
75
75
  async getAll(userContext) {
76
+ console.log('In GenericApiService.getAll');
76
77
  const query = this.prepareQuery(userContext, {});
77
78
  let entities = [];
78
79
  if (this.getAdditionalPipelineStages().length > 0) {
@@ -86,6 +87,7 @@ export class GenericApiService {
86
87
  return this.transformList(entities);
87
88
  }
88
89
  async get(userContext, queryOptions = { ...DefaultQueryOptions }) {
90
+ console.log('In GenericApiService.get');
89
91
  const preparedOptions = this.prepareQueryOptions(userContext, queryOptions);
90
92
  const match = dbUtils.buildMongoMatchFromQueryOptions(preparedOptions);
91
93
  const additionalStages = this.getAdditionalPipelineStages();
@@ -122,25 +124,35 @@ export class GenericApiService {
122
124
  return pagedResult;
123
125
  }
124
126
  async getById(userContext, id) {
127
+ console.log(`--- GenericApiService.getById ENTER ---`);
128
+ console.log(`ID received: ${id}`);
125
129
  if (!entityUtils.isValidObjectId(id)) {
126
130
  throw new BadRequestError('id is not a valid ObjectId');
127
131
  }
128
132
  const baseQuery = { _id: new ObjectId(id) };
129
133
  const query = this.prepareQuery(userContext, baseQuery);
134
+ console.log('Constructed query:', JSON.stringify(query, null, 2));
130
135
  let entity = null;
131
136
  if (this.getAdditionalPipelineStages().length > 0) {
137
+ console.log('Branch: Executing with aggregation pipeline.');
132
138
  const pipeline = [
133
139
  { $match: query },
134
140
  ...this.getAdditionalPipelineStages()
135
141
  ];
142
+ console.log('Aggregation Pipeline:', JSON.stringify(pipeline, null, 2));
136
143
  entity = await this.collection.aggregate(pipeline).next();
137
144
  }
138
145
  else {
146
+ console.log('Branch: Executing with findOne.');
139
147
  entity = await this.collection.findOne(query);
140
148
  }
149
+ console.log('IMMEDIATE DB RESULT (entity):', JSON.stringify(entity, null, 2));
141
150
  if (!entity) {
151
+ console.log('Entity not found, throwing IdNotFoundError.');
142
152
  throw new IdNotFoundError();
143
153
  }
154
+ console.log('Entity before transformSingle:', JSON.stringify(entity, null, 2));
155
+ console.log(`--- GenericApiService.getById EXIT ---`);
144
156
  return this.transformSingle(entity);
145
157
  }
146
158
  async getCount(userContext) {
@@ -361,12 +373,14 @@ export class GenericApiService {
361
373
  return list.map(item => this.transformSingle(item));
362
374
  }
363
375
  transformSingle(single) {
376
+ console.log('Starting base class transformSingle, entity:', JSON.stringify(single, null, 2));
364
377
  if (!single)
365
378
  return single;
366
379
  if (!this.modelSpec?.fullSchema) {
367
380
  throw new ServerError(`Cannot transform entity: No model specification with schema provided for ${this.pluralResourceName}`);
368
381
  }
369
382
  const transformedEntity = dbUtils.convertObjectIdsToStrings(single, this.modelSpec.fullSchema);
383
+ console.log('Leaving base class transformSingle, transformedEntity:', JSON.stringify(transformedEntity, null, 2));
370
384
  return transformedEntity;
371
385
  }
372
386
  stripSenderProvidedSystemProperties(userContext, doc, allowId = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
6
6
  "scripts": {