Remove unneeded toJSON methods, tidy up
This commit is contained in:
parent
be7ce7b04b
commit
540bd5d5ca
|
@ -57,6 +57,7 @@ export class SymmetricCryptoKey {
|
|||
}
|
||||
|
||||
toJSON() {
|
||||
// The whole object is constructed from the initial key, so just store the B64 key
|
||||
return { keyB64: this.keyB64 };
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,6 @@ import { SymmetricCryptoKey } from "../domain/symmetricCryptoKey";
|
|||
|
||||
import { View } from "./view";
|
||||
|
||||
const propertyMap: any = {
|
||||
id: null,
|
||||
url: null,
|
||||
size: null,
|
||||
sizeName: null,
|
||||
filename: null,
|
||||
};
|
||||
|
||||
export class AttachmentView implements View {
|
||||
id: string = null;
|
||||
url: string = null;
|
||||
|
@ -43,12 +35,18 @@ export class AttachmentView implements View {
|
|||
return 0;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): AttachmentView {
|
||||
const view = Utils.copyToNewObject(obj, propertyMap, AttachmentView);
|
||||
const view = Utils.copyToNewObject(
|
||||
obj,
|
||||
{
|
||||
id: null,
|
||||
url: null,
|
||||
size: null,
|
||||
sizeName: null,
|
||||
filename: null,
|
||||
},
|
||||
AttachmentView
|
||||
);
|
||||
|
||||
view.key = obj.key == null ? null : SymmetricCryptoKey.fromJSON(obj.key);
|
||||
return view;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { linkedFieldOption } from "../../misc/linkedFieldOption.decorator";
|
|||
|
||||
import { ItemView } from "./itemView";
|
||||
|
||||
const propertyMap: any = {
|
||||
const serializedProperties: any = {
|
||||
cardholderName: null,
|
||||
brand: null,
|
||||
number: null,
|
||||
|
@ -13,6 +13,7 @@ const propertyMap: any = {
|
|||
expYear: null,
|
||||
code: null,
|
||||
};
|
||||
|
||||
export class CardView extends ItemView {
|
||||
@linkedFieldOption(LinkedId.CardholderName)
|
||||
cardholderName: string = null;
|
||||
|
@ -91,10 +92,11 @@ export class CardView extends ItemView {
|
|||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
// Needed to serialize getters which are not included by JSON.stringify
|
||||
return Utils.copyToNewObject(this, serializedProperties);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): CardView {
|
||||
return Utils.copyToNewObject(obj, propertyMap, CardView);
|
||||
return Utils.copyToNewObject(obj, serializedProperties, CardView);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import { PasswordHistoryView } from "./passwordHistoryView";
|
|||
import { SecureNoteView } from "./secureNoteView";
|
||||
import { View } from "./view";
|
||||
|
||||
const propertyMap: any = {
|
||||
const serializedProperties: any = {
|
||||
id: null,
|
||||
corganizationId: null,
|
||||
folderId: null,
|
||||
|
@ -158,7 +158,7 @@ export class CipherView implements View {
|
|||
}
|
||||
|
||||
toJSON() {
|
||||
const obj = Utils.copyToNewObject(this, propertyMap);
|
||||
const obj = Utils.copyToNewObject(this, serializedProperties);
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Card:
|
||||
|
@ -181,11 +181,11 @@ export class CipherView implements View {
|
|||
}
|
||||
|
||||
static fromJSON(obj: any): CipherView {
|
||||
const view = Utils.copyToNewObject(obj, propertyMap, CipherView);
|
||||
const view = Utils.copyToNewObject(obj, serializedProperties, CipherView);
|
||||
|
||||
// Dates
|
||||
view.revisionDate = new Date(obj.revisionDate);
|
||||
view.deletedDate = new Date(obj.deletedDate);
|
||||
view.revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate);
|
||||
view.deletedDate = obj.deletedDate == null ? null : new Date(obj.deletedDate);
|
||||
|
||||
// Nested objects
|
||||
view.attachments = obj.attachments?.map((a: any) => AttachmentView.fromJSON(a));
|
||||
|
|
|
@ -6,16 +6,6 @@ import { Field } from "../domain/field";
|
|||
|
||||
import { View } from "./view";
|
||||
|
||||
const propertyMap: any = {
|
||||
name: null,
|
||||
value: null,
|
||||
type: null,
|
||||
newField: null,
|
||||
showValue: null,
|
||||
showCount: null,
|
||||
linkedId: null,
|
||||
};
|
||||
|
||||
export class FieldView implements View {
|
||||
name: string = null;
|
||||
value: string = null;
|
||||
|
@ -38,11 +28,19 @@ export class FieldView implements View {
|
|||
return this.value != null ? "••••••••" : null;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): FieldView {
|
||||
return Utils.copyToNewObject(obj, propertyMap, FieldView);
|
||||
return Utils.copyToNewObject(
|
||||
obj,
|
||||
{
|
||||
name: null,
|
||||
value: null,
|
||||
type: null,
|
||||
newField: null,
|
||||
showValue: null,
|
||||
showCount: null,
|
||||
linkedId: null,
|
||||
},
|
||||
FieldView
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Utils } from "../../misc/utils";
|
|||
|
||||
import { ItemView } from "./itemView";
|
||||
|
||||
const propertyMap: any = {
|
||||
const serializedProperties: any = {
|
||||
title: null,
|
||||
firstName: null,
|
||||
middleName: null,
|
||||
|
@ -162,10 +162,11 @@ export class IdentityView extends ItemView {
|
|||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
// Needed to serialize getters which are not included by JSON.stringify
|
||||
return Utils.copyToNewObject(this, serializedProperties);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): IdentityView {
|
||||
return Utils.copyToNewObject(obj, propertyMap, IdentityView);
|
||||
return Utils.copyToNewObject(obj, serializedProperties, IdentityView);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ const CanLaunchWhitelist = [
|
|||
"androidapp://",
|
||||
];
|
||||
|
||||
const propertyMap: any = {
|
||||
const serializedProperties: any = {
|
||||
match: null,
|
||||
uri: null,
|
||||
};
|
||||
|
@ -133,10 +133,11 @@ export class LoginUriView implements View {
|
|||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
// Needed to serialize getters which are not included by JSON.stringify
|
||||
return Utils.copyToNewObject(this, serializedProperties);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any) {
|
||||
return Utils.copyToNewObject(obj, propertyMap, LoginUriView);
|
||||
return Utils.copyToNewObject(obj, serializedProperties, LoginUriView);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Login } from "../domain/login";
|
|||
import { ItemView } from "./itemView";
|
||||
import { LoginUriView } from "./loginUriView";
|
||||
|
||||
const propertyMap: any = {
|
||||
const serializedProperties: any = {
|
||||
username: null,
|
||||
password: null,
|
||||
totp: null,
|
||||
|
@ -70,12 +70,8 @@ export class LoginView extends ItemView {
|
|||
return this.uris != null && this.uris.length > 0;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): LoginView {
|
||||
const view = Utils.copyToNewObject(obj, propertyMap, LoginView);
|
||||
const view = Utils.copyToNewObject(obj, serializedProperties, LoginView);
|
||||
view.passwordRevisionDate =
|
||||
obj.passwordRevisionDate == null ? null : new Date(obj.passwordRevisionDate);
|
||||
view.uris = obj.uris?.map((uri: any) => LoginUriView.fromJSON(uri));
|
||||
|
|
|
@ -4,10 +4,6 @@ import { Password } from "../domain/password";
|
|||
|
||||
import { View } from "./view";
|
||||
|
||||
const propertyMap: any = {
|
||||
password: null,
|
||||
lastUsedDate: null,
|
||||
};
|
||||
export class PasswordHistoryView implements View {
|
||||
password: string = null;
|
||||
lastUsedDate: Date = null;
|
||||
|
@ -20,11 +16,14 @@ export class PasswordHistoryView implements View {
|
|||
this.lastUsedDate = ph.lastUsedDate;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): PasswordHistoryView {
|
||||
return Utils.copyToNewObject(obj, propertyMap, PasswordHistoryView);
|
||||
return Utils.copyToNewObject(
|
||||
obj,
|
||||
{
|
||||
password: null,
|
||||
lastUsedDate: null,
|
||||
},
|
||||
PasswordHistoryView
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,6 @@ import { SecureNote } from "../domain/secureNote";
|
|||
|
||||
import { ItemView } from "./itemView";
|
||||
|
||||
const propertyMap: any = {
|
||||
type: null,
|
||||
};
|
||||
export class SecureNoteView extends ItemView {
|
||||
type: SecureNoteType = null;
|
||||
|
||||
|
@ -24,11 +21,13 @@ export class SecureNoteView extends ItemView {
|
|||
return null;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return Utils.copyToNewObject(this, propertyMap);
|
||||
}
|
||||
|
||||
static fromJSON(obj: any): SecureNoteView {
|
||||
return Utils.copyToNewObject(obj, propertyMap, SecureNoteView);
|
||||
return Utils.copyToNewObject(
|
||||
obj,
|
||||
{
|
||||
type: null,
|
||||
},
|
||||
SecureNoteView
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue