-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mrf): backend validation for field locking (#7143)
* feat(mrf): backend validation for field locking * refactor: move BE typeguards to its own file mimicking FE structure * refactor: rename logic* to shared* * refactor: use break instead of continue, clean up type assertions * refactor: remove redundant existence check, clean up comments in validator * refactor: use lodash isEqual instead of writing custom comparators, renaming of variables --------- Co-authored-by: Ken <ken@open.gov.sg>
- Loading branch information
Showing
14 changed files
with
567 additions
and
95 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import _ from 'lodash' | ||
import { BasicField, FieldResponseV3 } from '../types' | ||
|
||
export const isFieldResponseV3Equal = ( | ||
l: FieldResponseV3, | ||
r: FieldResponseV3, | ||
): boolean => { | ||
if (l.fieldType !== r.fieldType) return false | ||
|
||
switch (l.fieldType) { | ||
case BasicField.Number: | ||
case BasicField.Decimal: | ||
case BasicField.ShortText: | ||
case BasicField.LongText: | ||
case BasicField.HomeNo: | ||
case BasicField.Dropdown: | ||
case BasicField.Rating: | ||
case BasicField.Nric: | ||
case BasicField.Uen: | ||
case BasicField.Date: | ||
case BasicField.CountryRegion: | ||
case BasicField.YesNo: | ||
case BasicField.Email: | ||
case BasicField.Mobile: | ||
case BasicField.Table: | ||
case BasicField.Radio: | ||
case BasicField.Checkbox: | ||
case BasicField.Children: | ||
return _.isEqual(l.answer, r.answer) | ||
case BasicField.Attachment: { | ||
const rAnswer = r.answer as typeof l.answer | ||
return ( | ||
l.answer.answer === rAnswer.answer && | ||
l.answer.hasBeenScanned === rAnswer.hasBeenScanned | ||
) | ||
} | ||
case BasicField.Section: | ||
return true | ||
default: { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _: never = l | ||
return false | ||
} | ||
} | ||
} |
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
Oops, something went wrong.