2020-12-03 21:20:38 +01:00
|
|
|
import { Collection as CollectionDomain } from "../domain/collection";
|
2022-10-14 18:25:50 +02:00
|
|
|
import { EncString } from "../domain/enc-string";
|
|
|
|
import { CollectionView } from "../view/collection.view";
|
2020-12-03 21:20:38 +01:00
|
|
|
|
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()) {
|
2021-04-21 02:16:19 +02:00
|
|
|
domain.name = req.name != null ? new EncString(req.name) : null;
|
2020-12-05 03:05:11 +01:00
|
|
|
domain.externalId = req.externalId;
|
|
|
|
if (domain.organizationId == null) {
|
|
|
|
domain.organizationId = req.organizationId;
|
|
|
|
}
|
|
|
|
return domain;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2020-12-05 03:05:11 +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
|
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;
|
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
|
|
|
}
|