bitwarden-estensione-browser/libs/common/src/models/export/collection.export.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
TypeScript
Raw Normal View History

import { Collection as CollectionDomain } from "../domain/collection";
import { EncString } from "../domain/enc-string";
import { CollectionView } from "../view/collection.view";
2022-04-19 13:03:04 +02:00
export class CollectionExport {
static template(): CollectionExport {
const req = new CollectionExport();
2018-12-17 16:29:37 +01:00
req.organizationId = "00000000-0000-0000-0000-000000000000";
req.name = "Collection name";
2019-03-07 21:17:58 +01:00
req.externalId = null;
2018-12-17 16:29:37 +01:00
return req;
}
2022-04-19 13:03:04 +02:00
static toView(req: CollectionExport, view = new CollectionView()) {
2018-12-17 16:29:37 +01:00
view.name = req.name;
2019-03-07 21:17:58 +01:00
view.externalId = req.externalId;
2018-12-17 16:29:37 +01:00
if (view.organizationId == null) {
view.organizationId = req.organizationId;
}
return view;
2021-12-16 13:36:21 +01:00
}
2018-12-17 16:29:37 +01:00
2022-04-19 13:03:04 +02:00
static toDomain(req: CollectionExport, domain = new CollectionDomain()) {
domain.name = req.name != null ? new EncString(req.name) : null;
domain.externalId = req.externalId;
if (domain.organizationId == null) {
domain.organizationId = req.organizationId;
}
return domain;
2021-12-16 13:36:21 +01:00
}
2018-12-17 16:29:37 +01:00
organizationId: string;
name: string;
2019-03-07 21:17:58 +01:00
externalId: string;
2018-12-17 16:29:37 +01:00
// Use build method instead of ctor so that we can control order of JSON stringify for pretty print
build(o: CollectionView | CollectionDomain) {
2018-12-17 16:29:37 +01:00
this.organizationId = o.organizationId;
if (o instanceof CollectionView) {
this.name = o.name;
} else {
this.name = o.name?.encryptedString;
2018-12-17 16:29:37 +01:00
}
2019-03-07 21:17:58 +01:00
this.externalId = o.externalId;
2021-12-16 13:36:21 +01:00
}
2018-12-17 16:29:37 +01:00
}