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

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-12-17 16:29:37 +01:00
import { CollectionView } from '../view/collectionView';
import { CipherString } from '../domain/cipherString';
import { Collection as CollectionDomain } from '../domain/collection';
2018-12-17 16:29:37 +01:00
export class Collection {
static template(): Collection {
const req = new Collection();
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;
}
static toView(req: Collection, view = new CollectionView()) {
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;
}
static toDomain(req: Collection, domain = new CollectionDomain()) {
domain.name = req.name != null ? new CipherString(req.name) : null;
domain.externalId = req.externalId;
if (domain.organizationId == null) {
domain.organizationId = req.organizationId;
}
return domain;
}
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;
}
2019-03-07 21:17:58 +01:00
this.externalId = o.externalId;
2018-12-17 16:29:37 +01:00
}
}