diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 62c9c2c..9ceb80d 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -32,4 +32,4 @@ jobs: with: context: "." push: true - tags: samagragovernance/uci-apis:${{ steps.vars.outputs.tag }} \ No newline at end of file + tags: samagragovernance/uci-apis:${{ steps.vars.outputs.tag }}, latest \ No newline at end of file diff --git a/src/modules/bot/bot.service.spec.ts b/src/modules/bot/bot.service.spec.ts index 6350099..9d3372e 100644 --- a/src/modules/bot/bot.service.spec.ts +++ b/src/modules/bot/bot.service.spec.ts @@ -589,14 +589,18 @@ describe('BotService', () => { }) it('bot report fetches data correctly', async () => { + const urlRegex = /^http:\/\/uci_core_base_urltestbotreportendpoint\/\?botId=testBotId&createdAt=\d+&limit=10&nextPage=testNextPage$/; + fetchMock.getOnce(`${configService.get('MINIO_GET_SIGNED_FILE_URL')}/?fileName=testImageFile`, + 'testImageUrl' + ); fetchMock.getOnce( - `${configService.get('UCI_CORE_BASE_URL')}${configService.get('BROADCAST_BOT_REPORT_ENDPOINT')}?botId=testBotId&limit=10&nextPage=testNextPage`, + urlRegex, true ); await botService.getBroadcastReport('testBotId', 10, 'testNextPage'); expect( fetchMock.called( - `${configService.get('UCI_CORE_BASE_URL')}${configService.get('BROADCAST_BOT_REPORT_ENDPOINT')}?botId=testBotId&limit=10&nextPage=testNextPage` + urlRegex ) ).toBe(true); fetchMock.restore(); diff --git a/src/modules/bot/bot.service.ts b/src/modules/bot/bot.service.ts index f491b74..bbe92f5 100644 --- a/src/modules/bot/bot.service.ts +++ b/src/modules/bot/bot.service.ts @@ -431,6 +431,10 @@ export class BotService { } } + if (!requiredBot) { + throw new NotFoundException('Bot does not exist!'); + } + const requiredData: { 'bot': { 'id': string, @@ -571,7 +575,11 @@ export class BotService { this.logger.error(`Config data missing. UCI_CORE_BASE_URL: ${inbound_base}, BROADCAST_BOT_REPORT_ENDPOINT: ${broadcast_bot_report_endpoint}`) throw new InternalServerErrorException('Config data missing!'); } - let report_endpoint = `${inbound_base}${broadcast_bot_report_endpoint}?botId=${botId}`; + const broadcastBotData = await this.findOne(botId); + if (!broadcastBotData) { + throw new NotFoundException('Bot does not exist!'); + } + let report_endpoint = `${inbound_base}${broadcast_bot_report_endpoint}?botId=${botId}&createdAt=${new Date(broadcastBotData.createdAt).getTime()}`; if (limit) { report_endpoint += `&limit=${limit}`; } @@ -580,7 +588,15 @@ export class BotService { } this.logger.log(`Calling inbound for report with link: ${report_endpoint}`); return await fetch(report_endpoint) - .then(resp => resp.json()) - .then(resp => resp); + .then(resp => { + if (!resp.ok) { + throw new ServiceUnavailableException('Could not pull data from database!'); + } + return resp.json(); + }) + .then(resp => resp) + .catch(err => { + throw new ServiceUnavailableException('Could not pull data from database!'); + }); } }