Skip to content

Commit

Permalink
feat: remove useless CSV resource.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Sep 5, 2022
1 parent 37a7ef5 commit 9735bdc
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 169 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"body-parser": "^1.19.1",
"bson": "^4.6.5",
"cors": "^2.8.5",
"csv-writer": "^1.6.0",
"dinoloop": "^2.4.0",
"express": "^4.17.2",
"express-fileupload": "^1.2.1",
Expand Down
91 changes: 0 additions & 91 deletions src/logion/controllers/locrequest.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { UUID } from "@logion/node-api/dist/UUID";
import { badRequest } from "./errors";
import { CollectionRepository } from "../model/collection.model";
import { getUploadedFile } from "./fileupload";
import { CsvCreator } from "../lib/CsvCreator";

const { logger } = Log;

Expand All @@ -52,7 +51,6 @@ export function fillInSpec(spec: OpenAPIV3.Document): void {
LocRequestController.createLocRequest(spec);
LocRequestController.fetchRequests(spec);
LocRequestController.getLocRequest(spec);
LocRequestController.getCsvLocRequest(spec);
LocRequestController.getPublicLoc(spec);
LocRequestController.rejectLocRequest(spec);
LocRequestController.acceptLocRequest(spec);
Expand Down Expand Up @@ -305,95 +303,6 @@ export class LocRequestController extends ApiController {
}
}

static getCsvLocRequest(spec: OpenAPIV3.Document) {
const operationObject = spec.paths["/api/loc-request/{requestId}"].get!;
operationObject.summary = "Gets a single LOC Request CSV file";
operationObject.description = "The authenticated user must be either expected requester or expected owner.";
operationObject.responses = {
"200": {
description: "OK",
content: {
"text/csv": {
example: "loc.id,loc.ownerAddress\n3e67427a-d80f-41d7-9c86-75a63b8563a1,5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
}
}
}
};
setPathParameters(operationObject, { 'requestId': "The ID of the LOC request" })
}

@HttpGet('/:requestId/csv')
@Async()
@SendsResponse()
async getCsvLocRequest(_body: any, requestId: string): Promise<void> {

type Prefix = "loc" | "userIdentity" | "voidInfo" | "file" | "link" | "metadata";

const csvCreator = new CsvCreator<Prefix>({
"loc": [
"id",
"ownerAddress",
"requesterAddress",
"requesterIdentityLoc",
"description",
"createdOn",
"decisionOn",
"closedOn",
"status",
"rejectReason",
"locType",
],
"userIdentity": [
"firstName",
"lastName",
"email",
"phoneNumber"
],
"voidInfo": [
"reason",
"voidedOn"
],
"file": [
"name",
"hash",
"nature",
"addedOn",
"submitter"
],
"link": [
"target",
"addedOn",
"nature"
],
"metadata": [
"name",
"value",
"addedOn",
"submitter"
],
});
const request = requireDefined(await this.locRequestRepository.findById(requestId));
await this.authenticationService.authenticatedUserIsOneOf(this.request,
request.requesterAddress, request.ownerAddress);
const ui = await this.findUserIdentity(request);
const locRequestView = this.toView(request, ui);
this.response.type('text/csv')
const csv =
csvCreator.getHeaderString() +
csvCreator.stringifyRecords(
{
"loc": locRequestView,
"userIdentity": locRequestView.userIdentity,
"voidInfo": locRequestView.voidInfo
},
{
"file": locRequestView.files,
"link": locRequestView.links,
"metadata": locRequestView.metadata
})
this.response.send(csv)
}

static getPublicLoc(spec: OpenAPIV3.Document) {
const operationObject = spec.paths["/api/loc-request/{requestId}/public"].get!;
operationObject.summary = "Gets the published attributes of a single LOC";
Expand Down
52 changes: 0 additions & 52 deletions src/logion/lib/CsvCreator.ts

This file was deleted.

17 changes: 0 additions & 17 deletions test/unit/controllers/locrequest.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,23 +450,6 @@ describe('LocRequestController', () => {
});
});

it('succeeds to get CSV-formatted loc request', async () => {
const app = setupApp(LocRequestController, mockModelForGetSingle)
await request(app)
.get(`/api/loc-request/${REQUEST_ID}/csv`)
.expect(200)
.expect('Content-Type', /text\/csv/)
.then(response => {
console.log(response.text)
const csv = response.text.split("\n")
expect(csv[0]).toEqual("loc.id,loc.ownerAddress,loc.requesterAddress,loc.requesterIdentityLoc,loc.description,loc.createdOn,loc.decisionOn,loc.closedOn,loc.status,loc.rejectReason,loc.locType,userIdentity.firstName,userIdentity.lastName,userIdentity.email,userIdentity.phoneNumber,voidInfo.reason,voidInfo.voidedOn,file.name,file.hash,file.nature,file.addedOn,file.submitter,link.target,link.addedOn,link.nature,metadata.name,metadata.value,metadata.addedOn,metadata.submitter")
expect(csv[1]).toEqual("3e67427a-d80f-41d7-9c86-75a63b8563a1,5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY,5CXLTF2PFBE89tTYsrofGPkSfGTdmW4ciw4vAfgcKhjggRgZ,,I want to open a case,2022-08-31T16:01:15.651Z,,,OPEN,,Transaction,,,,,,,,,,,,,,,,,,");
expect(csv[2]).toEqual(",,,,,,,,,,,,,,,,,test-file,0x9383cd5dfeb5870027088289c665c3bae2d339281840473f35311954e984dea9,file-nature,2022-08-31T15:53:12.741Z,5DDGQertEH5qvKVXUmpT3KNGViCX582Qa2WWb8nGbkmkRHvw,,,,,,,");
expect(csv[3]).toEqual(",,,,,,,,,,,,,,,,,,,,,,507a00a1-7387-44b8-ac4d-fa57ccbf6da5,,link-nature,,,,");
expect(csv[4]).toEqual(",,,,,,,,,,,,,,,,,,,,,,,,,test-data,test-data-value,,5DDGQertEH5qvKVXUmpT3KNGViCX582Qa2WWb8nGbkmkRHvw");
});
});

it('deletes a file', async () => {
const app = setupApp(LocRequestController, mockModelForDeleteFile)
await request(app)
Expand Down
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2377,13 +2377,6 @@ __metadata:
languageName: node
linkType: hard

"csv-writer@npm:^1.6.0":
version: 1.6.0
resolution: "csv-writer@npm:1.6.0"
checksum: 2e62cb46f00b674f0710eb90586000601f3a467aabe529464dcb402d453a1322a716d7522ef3282dd6551f1059305c7dd3db49def1201caaf340597dcf7b4c7e
languageName: node
linkType: hard

"d@npm:1, d@npm:^1.0.1":
version: 1.0.1
resolution: "d@npm:1.0.1"
Expand Down Expand Up @@ -4151,7 +4144,6 @@ __metadata:
body-parser: ^1.19.1
bson: ^4.6.5
cors: ^2.8.5
csv-writer: ^1.6.0
dinoloop: ^2.4.0
dotenv: ^16.0.1
express: ^4.17.2
Expand Down

0 comments on commit 9735bdc

Please sign in to comment.