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:
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user