1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-24 04:04:38 +00:00

Proposed refactor of folder domain model

This commit is contained in:
Hinton
2022-04-19 11:31:49 +02:00
parent fee2f78aa8
commit f75e2c4175
14 changed files with 218 additions and 137 deletions

View File

@@ -1,15 +1,24 @@
import { FolderResponse } from "../response/folderResponse";
import { EncString } from "../domain/encString";
import { Folder } from "../domain/folder";
export class FolderData {
id: string;
userId: string;
name: string;
revisionDate: string;
constructor(response: FolderResponse, userId: string) {
this.userId = userId;
this.name = response.name;
this.id = response.id;
this.revisionDate = response.revisionDate;
constructor(f?: Folder) {
if (f) {
this.id = f.id;
this.name = f.name.encryptedString;
this.revisionDate = f.revisionDate.toISOString();
}
}
toFolder(): Folder {
return {
id: this.id,
name: new EncString(this.name),
revisionDate: new Date(this.revisionDate),
};
}
}

View File

@@ -1,40 +1,7 @@
import { FolderData } from "../data/folderData";
import { FolderView } from "../view/folderView";
import Domain from "./domainBase";
import { EncString } from "./encString";
export class Folder extends Domain {
export interface Folder {
id: string;
name: EncString;
revisionDate: Date;
constructor(obj?: FolderData) {
super();
if (obj == null) {
return;
}
this.buildDomainModel(
this,
obj,
{
id: null,
name: null,
},
["id"]
);
this.revisionDate = obj.revisionDate != null ? new Date(obj.revisionDate) : null;
}
decrypt(): Promise<FolderView> {
return this.decryptObj(
new FolderView(this),
{
name: null,
},
null
);
}
}

View File

@@ -14,7 +14,7 @@ export class Folder {
return view;
}
static toDomain(req: Folder, domain = new FolderDomain()) {
static toDomain(req: Folder, domain: FolderDomain = {} as FolderDomain) {
domain.name = req.name != null ? new EncString(req.name) : null;
return domain;
}

View File

@@ -1,3 +1,6 @@
import { EncString } from "../domain/encString";
import { Folder } from "../domain/folder";
import { BaseResponse } from "./baseResponse";
export class FolderResponse extends BaseResponse {
@@ -11,4 +14,12 @@ export class FolderResponse extends BaseResponse {
this.name = this.getResponseProperty("Name");
this.revisionDate = this.getResponseProperty("RevisionDate");
}
toFolder(): Folder {
return {
id: this.id,
name: new EncString(this.name),
revisionDate: new Date(this.revisionDate),
};
}
}

View File

@@ -1,4 +1,3 @@
import { Folder } from "../domain/folder";
import { ITreeNodeObject } from "../domain/treeNode";
import { View } from "./view";
@@ -7,13 +6,4 @@ export class FolderView implements View, ITreeNodeObject {
id: string = null;
name: string = null;
revisionDate: Date = null;
constructor(f?: Folder) {
if (!f) {
return;
}
this.id = f.id;
this.revisionDate = f.revisionDate;
}
}