Skip to content

Commit

Permalink
changing from using companyId/guid
Browse files Browse the repository at this point in the history
  • Loading branch information
goemen committed May 27, 2024
1 parent ae56a25 commit c21d20c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('pay-transparency-routes', () => {
});
return request(app)
.delete('/')
.query({ companyId: '1234567890' })
.query({ companyName: '1234567890' })
.set('x-api-key', 'api-delete-reports-key')
.expect(200)
.expect(({ body }) => {
Expand All @@ -83,16 +83,15 @@ describe('pay-transparency-routes', () => {
});
return request(app)
.delete('/')
.query({ companyId: '1234567890' })
.set('x-api-key', 'api-delete-reports-key')
.query({ companyId: '' })
.query({ companyName: '' })
.expect(400);
});
it('should fail if request fails to get reports', () => {
mockDeleteReports.mockRejectedValue({ message: 'Error happened' });
return request(app)
.delete('/')
.query({ companyId: '1234567890' })
.query({ companyName: '1234567890' })
.set('x-api-key', 'api-delete-reports-key')
.expect(500);
});
Expand Down
2 changes: 1 addition & 1 deletion backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ router.get(
* - ApiKeyAuth: []
* parameters:
* - in: query
* name: companyId
* name: companyName
* required: true
* schema:
* type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ describe('pay-transparency-service', () => {
it('should delete reports', async () => {
mockDelete.mockReturnValue({});
await payTransparencyService.deleteReports({
params: { companyId: '1234567890' },
params: { companyName: '1234567890' },
} as any);

expect(mockDelete).toHaveBeenCalledWith(
'/external-consumer-api/v1/reports',
{
params: { companyId: '1234567890' },
params: { companyName: '1234567890' },
headers: {
'x-api-key': 'api-key',
},
Expand Down
3 changes: 2 additions & 1 deletion backend/src/v1/routes/external-consumer-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ router.get(

router.delete('/', async (req, res) => {
try {
await reportService.deleteReports(req.query.companyId as string);
const { companyName } = req.query;
await reportService.deleteReports(companyName as string);
res.status(200).json({ error: false, message: 'Reports deleted' });
} catch (error) {
res.json({ error: true, message: error.message });
Expand Down
1 change: 0 additions & 1 deletion backend/src/v1/services/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const auth = {
}
const userInfoFrontend = {
displayName: userInfo._json.display_name,
businessId: userInfo._json.bceid_business_guid,
...session.companyDetails,
};
return res.status(HttpStatus.OK).json(userInfoFrontend);
Expand Down
12 changes: 6 additions & 6 deletions backend/src/v1/services/report-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,13 @@ describe('shouldPreventReportOverride', () => {

describe('deleteReports', () => {
it('should delete reports', async () => {
const bceid_business_guid = '1234567890';
await reportService.deleteReports(bceid_business_guid);
const company_name = '1234567890';
await reportService.deleteReports(company_name);
expect(mockCalculatedDataDeleteMany).toHaveBeenCalledWith({
where: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
Expand All @@ -1104,7 +1104,7 @@ describe('deleteReports', () => {
report_history: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
Expand All @@ -1114,15 +1114,15 @@ describe('deleteReports', () => {
where: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
});
expect(mockReportsDeleteMany).toHaveBeenCalledWith({
where: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
});
Expand Down
12 changes: 6 additions & 6 deletions backend/src/v1/services/report-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1311,15 +1311,15 @@ const reportService = {

/**
* Delete all reports for the given company
* @param bceid_business_guid - the business guid
* @param company_name - the name of the company
*/
async deleteReports(bceid_business_guid: string) {
async deleteReports(company_name: string) {
await prisma.$transaction(async (tx) => {
await tx.pay_transparency_calculated_data.deleteMany({
where: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
Expand All @@ -1330,7 +1330,7 @@ const reportService = {
report_history: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
Expand All @@ -1341,7 +1341,7 @@ const reportService = {
where: {
pay_transparency_report: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
},
Expand All @@ -1350,7 +1350,7 @@ const reportService = {
await tx.pay_transparency_report.deleteMany({
where: {
pay_transparency_company: {
bceid_business_guid,
company_name,
},
},
});
Expand Down

0 comments on commit c21d20c

Please sign in to comment.