2018-12-17 16:29:37 +01:00
|
|
|
import { CollectionView } from '../view/collectionView';
|
|
|
|
|
2020-12-05 03:05:11 +01:00
|
|
|
import { CipherString } from '../domain/cipherString';
|
2020-12-03 21:20:38 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-05 03:05:11 +01:00
|
|
|
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
|
2020-12-03 21:20:38 +01:00
|
|
|
build(o: CollectionView | CollectionDomain) {
|
2018-12-17 16:29:37 +01:00
|
|
|
this.organizationId = o.organizationId;
|
2020-12-03 21:20:38 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|