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