1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00

Create and use safeGetString() instead of instanceof checks to determine type (#8906)

`safeGetString` takes a `string` or `EncString` and return the appropiate value based on it's type

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith
2024-04-24 23:41:35 +02:00
committed by GitHub
parent a6755f5f20
commit dba910d0b9
11 changed files with 82 additions and 137 deletions

View File

@@ -2,6 +2,8 @@ import { EncString } from "../../platform/models/domain/enc-string";
import { Collection as CollectionDomain } from "../../vault/models/domain/collection";
import { CollectionView } from "../../vault/models/view/collection.view";
import { safeGetString } from "./utils";
export class CollectionExport {
static template(): CollectionExport {
const req = new CollectionExport();
@@ -36,11 +38,7 @@ export class CollectionExport {
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CollectionView | CollectionDomain) {
this.organizationId = o.organizationId;
if (o instanceof CollectionView) {
this.name = o.name;
} else {
this.name = o.name?.encryptedString;
}
this.name = safeGetString(o.name);
this.externalId = o.externalId;
}
}