Skip to content

Commit

Permalink
MAP-1625 get report using db query that doesn't require user (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
GurnankCheema authored Oct 15, 2024
1 parent f4fd560 commit acea4e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/routes/adhocReportActions/addhocActionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class AddhocActionController {

for (let reportId = fromId; reportId <= toId; reportId += 1) {
try {
const report = await this.reportService.getReport(req.user.username, reportId)
const report = await this.reportService.getReportUsingReportIdOnly(reportId)

const { locationId } = report.form.incidentDetails

Expand Down
14 changes: 7 additions & 7 deletions server/routes/adhocReportActions/adhocActionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ describe('Adhoc actions', () => {
it('calls the report service to get reports correctly', async () => {
await controller.updateReport(req, res)

expect(reportService.getReport).toHaveBeenCalledTimes(2)
expect(reportService.getReport).toHaveBeenCalledWith('user_name', 1)
expect(reportService.getReport).toHaveBeenCalledWith('user_name', 2)
expect(reportService.getReportUsingReportIdOnly).toHaveBeenCalledTimes(2)
expect(reportService.getReportUsingReportIdOnly).toHaveBeenCalledWith(1)
expect(reportService.getReportUsingReportIdOnly).toHaveBeenCalledWith(2)
})

it('does not do update if incidentLocationId already exists', async () => {
Expand All @@ -75,7 +75,7 @@ describe('Adhoc actions', () => {
},
}

reportService.getReport.mockResolvedValue(report as any)
reportService.getReportUsingReportIdOnly.mockResolvedValue(report as any)
await controller.updateReport(req, res)

expect(reportService.update).not.toHaveBeenCalled()
Expand All @@ -95,8 +95,8 @@ describe('Adhoc actions', () => {
},
}

reportService.getReport.mockResolvedValueOnce(report as any)
reportService.getReport.mockRejectedValueOnce(Error(`Report does not exist: 2`))
reportService.getReportUsingReportIdOnly.mockResolvedValueOnce(report as any)
reportService.getReportUsingReportIdOnly.mockRejectedValueOnce(Error(`Report does not exist: 2`))

nomisMappingService.getDpsLocationDetailsHavingCorrespondingNomisLocationId.mockResolvedValue({
dpsLocationId: 'some-uuid',
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('Adhoc actions', () => {
},
}

reportService.getReport.mockResolvedValue(report as any)
reportService.getReportUsingReportIdOnly.mockResolvedValue(report as any)

nomisMappingService.getDpsLocationDetailsHavingCorrespondingNomisLocationId.mockResolvedValue({
dpsLocationId: 'some-uuid',
Expand Down
9 changes: 9 additions & 0 deletions server/services/reportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export default class ReportService {
return report
}

async getReportUsingReportIdOnly(reportId: number): Promise<Report> {
const report = await this.incidentClient.getReportForReviewer(reportId)

if (!report) {
throw new Error(`Report does not exist: ${reportId}`)
}
return report
}

async getAnonReportSummary(token: string, statementId: number): Promise<AnonReportSummaryWithPrison | undefined> {
const report = await this.incidentClient.getAnonReportSummary(statementId)
if (!report) {
Expand Down

0 comments on commit acea4e5

Please sign in to comment.