mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
[SM-288] Rename models to follow naming convention (#3795)
This commit is contained in:
46
libs/common/src/models/export/collection.export.ts
Normal file
46
libs/common/src/models/export/collection.export.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Collection as CollectionDomain } from "../domain/collection";
|
||||
import { EncString } from "../domain/enc-string";
|
||||
import { CollectionView } from "../view/collection.view";
|
||||
|
||||
export class CollectionExport {
|
||||
static template(): CollectionExport {
|
||||
const req = new CollectionExport();
|
||||
req.organizationId = "00000000-0000-0000-0000-000000000000";
|
||||
req.name = "Collection name";
|
||||
req.externalId = null;
|
||||
return req;
|
||||
}
|
||||
|
||||
static toView(req: CollectionExport, view = new CollectionView()) {
|
||||
view.name = req.name;
|
||||
view.externalId = req.externalId;
|
||||
if (view.organizationId == null) {
|
||||
view.organizationId = req.organizationId;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
organizationId: string;
|
||||
name: string;
|
||||
externalId: string;
|
||||
|
||||
// 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.externalId = o.externalId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user