diff --git a/src/app.controller.ts b/src/app.controller.ts index a056052..9b86f72 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -44,8 +44,8 @@ export class AppController { } @Post('select') - async select(@Body() body: any, @Query('obsolete') obsolete) { - return await this.queryService.select(body, this.parseBoolean(obsolete)); + async select(@Body() body: any) { + return await this.queryService.select(body); } // Temporary code for initial import diff --git a/src/domain/services/import.service.ts b/src/domain/services/import.service.ts index b35f499..c78fb55 100644 --- a/src/domain/services/import.service.ts +++ b/src/domain/services/import.service.ts @@ -188,6 +188,7 @@ export class ImportService { await client.close(); // If doing an event import flag all products that weren't found in MongoDB as deleted (obsolete = null) + let deleteLog = ''; if (source === ProductSource.EVENT) { const missingProducts = inputCodes.filter( (code) => !foundCodes.includes(code), @@ -205,6 +206,7 @@ export class ImportService { connection, deletedProducts.map((p) => p.id), ); + deleteLog = `. Deleted ${deletedProducts.count}`; } } @@ -220,7 +222,7 @@ export class ImportService { connection.release(); this.logger.log( - `Imported ${collections.normal.count} Products and ${collections.obsolete.count} Obsolete Products from ${source}`, + `Imported ${collections.normal.count} Products and ${collections.obsolete.count} Obsolete Products from ${source}${deleteLog}`, ); return latestModified; diff --git a/src/domain/services/query.service.spec.ts b/src/domain/services/query.service.spec.ts index 3f97c9d..d663c69 100644 --- a/src/domain/services/query.service.spec.ts +++ b/src/domain/services/query.service.spec.ts @@ -408,30 +408,19 @@ describe('aggregate', () => { describe('select', () => { it('should return matching products', async () => { await createTestingModule([DomainModule], async (app) => { - const { aminoValue, product1 } = await createTestTags(app); + const { aminoValue, product1, product4 } = await createTestTags(app); const queryService = app.get(QueryService); const response = await queryService.select({ amino_acids_tags: aminoValue, }); - expect(response).toHaveLength(2); + expect(response).toHaveLength(3); // Includes obsolete const p1 = response.find((r) => r.code === product1.code); expect(p1).toBeTruthy(); - }); - }); + expect(p1.obsolete).toBe(false); - it('should return obsolete matching products', async () => { - await createTestingModule([DomainModule], async (app) => { - const { aminoValue, product4 } = await createTestTags(app); - const queryService = app.get(QueryService); - const response = await queryService.select( - { - amino_acids_tags: aminoValue, - }, - true, - ); - expect(response).toHaveLength(1); const p4 = response.find((r) => r.code === product4.code); expect(p4).toBeTruthy(); + expect(p4.obsolete).toBe(true); }); }); diff --git a/src/domain/services/query.service.ts b/src/domain/services/query.service.ts index 7ee1ef4..47ad61e 100644 --- a/src/domain/services/query.service.ts +++ b/src/domain/services/query.service.ts @@ -237,14 +237,13 @@ export class QueryService { } /** Fetches the entire document record for the filter. Not used by Product Opener */ - async select(body: any, obsolete = false) { + async select(body: any) { const start = Date.now(); this.logger.debug(body); const entity: EntityName = Product; const qb = this.em.createQueryBuilder(entity, 'pt'); qb.select(`*`); - qb.where(this.obsoleteWhere(obsolete)); const whereLog = await this.addMatches(this.parseFilter(body), qb, entity);