-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert CsvMergedHeadersGenerator to typescript (#2080)
* refactor: convert response classes to typescript and change response to abstract class * refactor: rearrange types * refactor: convert CsvMergedHeadersGenerator to typescript * refactor: edit export and import statements for CsvMergedHeadersGenerator * fix: edit import statement of generator in submissions.client.factory * refactor: edit response types * refactor: remove typing in jsdocs and edit types * refactor: export response subclasses input types * refactor: add ErrorResponse as default for response types * refactor: shift hasProps to shared * refactor: athrow error instead of returning ErrorResponse and edited typeguards * refactor: change interface to type * fix: fix incorrect import statement * test: remove single header row test * fix: fix bug caused by fieldtype guard and if else condition * refactor: remove console.log * refactor: convert extractAnswer to private function * docs: add jsdocs for response factory * docs: edit jsdocs for addRecord * refactor: extract acheck for answer array * refactor: revert extractAnswer to non-private function * refactor: remove repeated check for type Array * refactor: create SubmissionRecord type * refactor: rename ccsv generator in submissions client factory * refactor: make _data field private * test: rrestore deleted test and edit expected unprocessed record * test: remove repeated test * refactor: use private modifier in typescript classes * test: add tests for error cases * refactor: add private modifier to date comparator * refactor: remove underscore from private field * refactor: extract type in csvmhgenerator * refactor: replace strings with basic field enums * fix: fix import statement
- Loading branch information
Showing
20 changed files
with
381 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/public/modules/forms/helpers/csv-response-classes/ArrayAnswerResponse.class.js
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/public/modules/forms/helpers/csv-response-classes/ArrayAnswerResponse.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ArrayResponse } from '../../../../../types/response' | ||
|
||
import { Response } from './Response.class' | ||
|
||
export class ArrayAnswerResponse extends Response { | ||
private response: ArrayResponse | ||
|
||
constructor(responseData: ArrayResponse) { | ||
super(responseData) | ||
this.response = responseData | ||
} | ||
|
||
getAnswer(): string { | ||
return this.response.answerArray.join(';') | ||
} | ||
|
||
get numCols(): number { | ||
return 1 | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/public/modules/forms/helpers/csv-response-classes/Response.class.js
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/public/modules/forms/helpers/csv-response-classes/Response.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { DisplayedResponseWithoutAnswer } from '../../../../../types/response' | ||
|
||
export abstract class Response { | ||
private data: DisplayedResponseWithoutAnswer | ||
|
||
constructor(responseData: DisplayedResponseWithoutAnswer) { | ||
this.data = responseData | ||
} | ||
|
||
get id(): string { | ||
return this.data._id | ||
} | ||
|
||
/** | ||
* Gets the CSV header. | ||
* @returns {string} | ||
*/ | ||
get question(): string { | ||
return this.data.question | ||
} | ||
|
||
get isHeader(): boolean { | ||
return this.data.isHeader ?? false | ||
} | ||
|
||
abstract get numCols(): number | ||
|
||
abstract getAnswer(colIndex?: number): string | ||
} |
11 changes: 0 additions & 11 deletions
11
src/public/modules/forms/helpers/csv-response-classes/SingleAnswerResponse.class.js
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/public/modules/forms/helpers/csv-response-classes/SingleAnswerResponse.class.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SingleResponse } from '../../../../../types/response' | ||
|
||
import { Response } from './Response.class' | ||
|
||
export class SingleAnswerResponse extends Response { | ||
private response: SingleResponse | ||
|
||
constructor(responseData: SingleResponse) { | ||
super(responseData) | ||
this.response = responseData | ||
} | ||
|
||
getAnswer(): string { | ||
return this.response.answer | ||
} | ||
|
||
get numCols(): number { | ||
return 1 | ||
} | ||
} |
Oops, something went wrong.