From ce5fc9c278b67df3ca2afc28e181d94f22fbc667 Mon Sep 17 00:00:00 2001 From: gbubemismith Date: Fri, 13 Oct 2023 18:10:23 -0400 Subject: [PATCH] added fromNullable to reduces repetitive logic --- .../models/export/fido2-credential.export.ts | 23 +++++++++---------- .../src/platform/models/domain/enc-string.ts | 4 ++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libs/common/src/models/export/fido2-credential.export.ts b/libs/common/src/models/export/fido2-credential.export.ts index 67f7b7b440..24d08dc94a 100644 --- a/libs/common/src/models/export/fido2-credential.export.ts +++ b/libs/common/src/models/export/fido2-credential.export.ts @@ -37,18 +37,17 @@ export class Fido2CredentialExport { } static toDomain(req: Fido2CredentialExport, domain = new Fido2Credential()) { - domain.credentialId = req.credentialId != null ? new EncString(req.credentialId) : null; - domain.keyType = req.keyType != null ? new EncString(req.keyType) : null; - domain.keyAlgorithm = req.keyAlgorithm != null ? new EncString(req.keyAlgorithm) : null; - domain.keyCurve = req.keyCurve != null ? new EncString(req.keyCurve) : null; - domain.keyValue = req.keyValue != null ? new EncString(req.keyValue) : null; - domain.rpId = req.rpId != null ? new EncString(req.rpId) : null; - domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : null; - domain.counter = req.counter != null ? new EncString(req.counter) : null; - domain.rpName = req.rpName != null ? new EncString(req.rpName) : null; - domain.userDisplayName = - req.userDisplayName != null ? new EncString(req.userDisplayName) : null; - domain.discoverable = req.discoverable != null ? new EncString(req.discoverable) : null; + domain.credentialId = EncString.fromNullable(req.credentialId); + domain.keyType = EncString.fromNullable(req.keyType); + domain.keyAlgorithm = EncString.fromNullable(req.keyAlgorithm); + domain.keyCurve = EncString.fromNullable(req.keyCurve); + domain.keyValue = EncString.fromNullable(req.keyValue); + domain.rpId = EncString.fromNullable(req.rpId); + domain.userHandle = EncString.fromNullable(req.userHandle); + domain.counter = EncString.fromNullable(req.counter); + domain.rpName = EncString.fromNullable(req.rpName); + domain.userDisplayName = EncString.fromNullable(req.userDisplayName); + domain.discoverable = EncString.fromNullable(req.discoverable); domain.creationDate = req.creationDate; return domain; } diff --git a/libs/common/src/platform/models/domain/enc-string.ts b/libs/common/src/platform/models/domain/enc-string.ts index 60b59fa4d8..65313e94d8 100644 --- a/libs/common/src/platform/models/domain/enc-string.ts +++ b/libs/common/src/platform/models/domain/enc-string.ts @@ -43,6 +43,10 @@ export class EncString implements Encrypted { return this.encryptedString; } + static fromNullable(val: string | null) { + return val ? new EncString(val) : null; + } + static fromJSON(obj: Jsonify): EncString { if (obj == null) { return null;