diff --git a/src/controller/recon/recon.controller.ts b/src/controller/recon/recon.controller.ts index 665d2ee..cc2d88a 100644 --- a/src/controller/recon/recon.controller.ts +++ b/src/controller/recon/recon.controller.ts @@ -1,8 +1,7 @@ import { Body, Controller, Get, Post, Query } from "@nestjs/common"; import { ApiBody, ApiOperation, ApiQuery, ApiResponse, ApiTags } from "@nestjs/swagger"; -import { ReconciliationQuery, ReconciliationResponse } from "../../dto"; +import { ReconciliationResponse } from "../../dto"; import { ReconciliationService } from "../../service"; -import { ReconciliationTypesEnum } from "../../enum"; @Controller() @ApiTags("APIs") @@ -18,10 +17,10 @@ export class ReconciliationController { name: "queries", description: "Queries", required: false, - explode: false, + explode: false }) async reconcileByQuery( - @Query("queries") rawQueries: string, + @Query("queries") rawQueries: string ): Promise { return await this._reconciliationService.reconcileByRawQueries(rawQueries); } @@ -30,9 +29,10 @@ export class ReconciliationController { @ApiOperation({ summary: "Reconcile" }) @ApiResponse({ status: 200, type: ReconciliationResponse, isArray: true, description: "Reconciliation response" }) @ApiResponse({ status: 500, description: "Internal server error" }) - @ApiBody({type: ReconciliationQuery, isArray: true}) + @ApiBody({}) - async reconcileByQueries(@Body() reconciliationRequest: any): Promise{ + + async reconcileByQueries(@Body() reconciliationRequest: any): Promise { return await this._reconciliationService.reconcileByQueries(reconciliationRequest); } diff --git a/src/service/recon/recon.service.ts b/src/service/recon/recon.service.ts index c2c7319..924b0d1 100644 --- a/src/service/recon/recon.service.ts +++ b/src/service/recon/recon.service.ts @@ -1,14 +1,13 @@ import { Injectable } from "@nestjs/common"; import { ArtsdataService } from "../artsdata"; -import { ReconciliationQuery, ReconciliationResponse } from "../../dto"; import { ManifestService } from "../manifest"; +import { ReconciliationResponse } from "../../dto"; @Injectable() export class ReconciliationService { constructor(private readonly _artsdataService: ArtsdataService, - private readonly _manifestService: ManifestService - ) { + private readonly _manifestService: ManifestService) { } async reconcileByRawQueries(rawQueries: string): Promise { @@ -16,8 +15,11 @@ export class ReconciliationService { if (!rawQueries) { return this._manifestService.getServiceManifest(); } - const queries = JSON.parse(rawQueries); + return await this.reconcileByQueries(queries); + } + + async reconcileByQueries(queries: any): Promise { let index = 0; const results: any = {}; while (true) { @@ -26,7 +28,7 @@ export class ReconciliationService { if (!query) { break; } - const result = + const result: ReconciliationResponse[] = await this._artsdataService.getReconciliationResult(query.query, query.type, query.limit); results["q0"] = { result: result }; index++; @@ -34,20 +36,4 @@ export class ReconciliationService { return results; } - async reconcileByQueries(reconciliationRequest: ReconciliationQuery[]): Promise { - const promises = reconciliationRequest.map(query => - this._artsdataService.getReconciliationResult(query.query, query.type) - ); - - const results = (await Promise.all(promises)).flat(); - - const uniqueResults = results.filter((result, index, self) => - index === self.findIndex((object) => ( - object.id === result.id - )) - ); - - return uniqueResults; - } - }