added fromNullable to reduces repetitive logic

This commit is contained in:
gbubemismith 2023-10-13 18:10:23 -04:00
parent 186eb392fc
commit ce5fc9c278
No known key found for this signature in database
2 changed files with 15 additions and 12 deletions

View File

@ -37,18 +37,17 @@ export class Fido2CredentialExport {
} }
static toDomain(req: Fido2CredentialExport, domain = new Fido2Credential()) { static toDomain(req: Fido2CredentialExport, domain = new Fido2Credential()) {
domain.credentialId = req.credentialId != null ? new EncString(req.credentialId) : null; domain.credentialId = EncString.fromNullable(req.credentialId);
domain.keyType = req.keyType != null ? new EncString(req.keyType) : null; domain.keyType = EncString.fromNullable(req.keyType);
domain.keyAlgorithm = req.keyAlgorithm != null ? new EncString(req.keyAlgorithm) : null; domain.keyAlgorithm = EncString.fromNullable(req.keyAlgorithm);
domain.keyCurve = req.keyCurve != null ? new EncString(req.keyCurve) : null; domain.keyCurve = EncString.fromNullable(req.keyCurve);
domain.keyValue = req.keyValue != null ? new EncString(req.keyValue) : null; domain.keyValue = EncString.fromNullable(req.keyValue);
domain.rpId = req.rpId != null ? new EncString(req.rpId) : null; domain.rpId = EncString.fromNullable(req.rpId);
domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : null; domain.userHandle = EncString.fromNullable(req.userHandle);
domain.counter = req.counter != null ? new EncString(req.counter) : null; domain.counter = EncString.fromNullable(req.counter);
domain.rpName = req.rpName != null ? new EncString(req.rpName) : null; domain.rpName = EncString.fromNullable(req.rpName);
domain.userDisplayName = domain.userDisplayName = EncString.fromNullable(req.userDisplayName);
req.userDisplayName != null ? new EncString(req.userDisplayName) : null; domain.discoverable = EncString.fromNullable(req.discoverable);
domain.discoverable = req.discoverable != null ? new EncString(req.discoverable) : null;
domain.creationDate = req.creationDate; domain.creationDate = req.creationDate;
return domain; return domain;
} }

View File

@ -43,6 +43,10 @@ export class EncString implements Encrypted {
return this.encryptedString; return this.encryptedString;
} }
static fromNullable(val: string | null) {
return val ? new EncString(val) : null;
}
static fromJSON(obj: Jsonify<EncString>): EncString { static fromJSON(obj: Jsonify<EncString>): EncString {
if (obj == null) { if (obj == null) {
return null; return null;