Skip to content

Commit

Permalink
Don't limit select to obsolete / not obsolete
Browse files Browse the repository at this point in the history
Signed-off-by: John Gomersall <[email protected]>
  • Loading branch information
john-gom committed Sep 13, 2024
1 parent 1a8dd3a commit 57b4e92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/domain/services/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -205,6 +206,7 @@ export class ImportService {
connection,
deletedProducts.map((p) => p.id),
);
deleteLog = `. Deleted ${deletedProducts.count}`;
}
}

Expand All @@ -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;
Expand Down
19 changes: 4 additions & 15 deletions src/domain/services/query.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/domain/services/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<object> = 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);

Expand Down

0 comments on commit 57b4e92

Please sign in to comment.