diff --git a/src/models/data/attachmentData.ts b/src/models/data/attachmentData.ts index 004376a8dd..dc0f222065 100644 --- a/src/models/data/attachmentData.ts +++ b/src/models/data/attachmentData.ts @@ -5,7 +5,7 @@ export class AttachmentData { url: string; fileName: string; key: string; - size: number; + size: string; sizeName: string; constructor(response?: AttachmentResponse) { diff --git a/src/models/data/cipherData.ts b/src/models/data/cipherData.ts index 84dece2e81..19478debad 100644 --- a/src/models/data/cipherData.ts +++ b/src/models/data/cipherData.ts @@ -48,12 +48,7 @@ export class CipherData { this.type = response.type; this.name = response.name; this.notes = response.notes; - - if (collectionIds != null) { - this.collectionIds = collectionIds; - } else { - this.collectionIds = response.collectionIds; - } + this.collectionIds = collectionIds != null ? collectionIds : response.collectionIds; switch (this.type) { case CipherType.Login: @@ -73,24 +68,13 @@ export class CipherData { } if (response.fields != null) { - this.fields = []; - response.fields.forEach((field) => { - this.fields.push(new FieldData(field)); - }); + this.fields = response.fields.map((f) => new FieldData(f)); } - if (response.attachments != null) { - this.attachments = []; - response.attachments.forEach((attachment) => { - this.attachments.push(new AttachmentData(attachment)); - }); + this.attachments = response.attachments.map((a) => new AttachmentData(a)); } - if (response.passwordHistory != null) { - this.passwordHistory = []; - response.passwordHistory.forEach((ph) => { - this.passwordHistory.push(new PasswordHistoryData(ph)); - }); + this.passwordHistory = response.passwordHistory.map((ph) => new PasswordHistoryData(ph)); } } } diff --git a/src/models/domain/attachment.ts b/src/models/domain/attachment.ts index 6db86bebdd..838b83b9e6 100644 --- a/src/models/domain/attachment.ts +++ b/src/models/domain/attachment.ts @@ -13,7 +13,7 @@ import { Utils } from '../../misc/utils'; export class Attachment extends Domain { id: string; url: string; - size: number; + size: string; sizeName: string; key: CipherString; fileName: CipherString; @@ -62,6 +62,7 @@ export class Attachment extends Domain { toAttachmentData(): AttachmentData { const a = new AttachmentData(); + a.size = this.size; this.buildDataModel(this, a, { id: null, url: null, diff --git a/src/models/domain/cipher.ts b/src/models/domain/cipher.ts index 708774456c..85a961dd8f 100644 --- a/src/models/domain/cipher.ts +++ b/src/models/domain/cipher.ts @@ -76,28 +76,19 @@ export class Cipher extends Domain { } if (obj.attachments != null) { - this.attachments = []; - obj.attachments.forEach((attachment) => { - this.attachments.push(new Attachment(attachment, alreadyEncrypted)); - }); + this.attachments = obj.attachments.map((a) => new Attachment(a, alreadyEncrypted)); } else { this.attachments = null; } if (obj.fields != null) { - this.fields = []; - obj.fields.forEach((field) => { - this.fields.push(new Field(field, alreadyEncrypted)); - }); + this.fields = obj.fields.map((f) => new Field(f, alreadyEncrypted)); } else { this.fields = null; } if (obj.passwordHistory != null) { - this.passwordHistory = []; - obj.passwordHistory.forEach((ph) => { - this.passwordHistory.push(new Password(ph, alreadyEncrypted)); - }); + this.passwordHistory = obj.passwordHistory.map((ph) => new Password(ph, alreadyEncrypted)); } else { this.passwordHistory = null; } @@ -205,24 +196,13 @@ export class Cipher extends Domain { } if (this.fields != null) { - c.fields = []; - this.fields.forEach((field) => { - c.fields.push(field.toFieldData()); - }); + c.fields = this.fields.map((f) => f.toFieldData()); } - if (this.attachments != null) { - c.attachments = []; - this.attachments.forEach((attachment) => { - c.attachments.push(attachment.toAttachmentData()); - }); + c.attachments = this.attachments.map((a) => a.toAttachmentData()); } - if (this.passwordHistory != null) { - c.passwordHistory = []; - this.passwordHistory.forEach((ph) => { - c.passwordHistory.push(ph.toPasswordHistoryData()); - }); + c.passwordHistory = this.passwordHistory.map((ph) => ph.toPasswordHistoryData()); } return c; } diff --git a/src/models/domain/password.ts b/src/models/domain/password.ts index 5ef38a2010..72c374b6f8 100644 --- a/src/models/domain/password.ts +++ b/src/models/domain/password.ts @@ -21,11 +21,10 @@ export class Password extends Domain { this.lastUsedDate = new Date(obj.lastUsedDate); } - async decrypt(orgId: string): Promise { - const view = await this.decryptObj(new PasswordHistoryView(this), { + decrypt(orgId: string): Promise { + return this.decryptObj(new PasswordHistoryView(this), { password: null, }, orgId); - return view; } toPasswordHistoryData(): PasswordHistoryData { diff --git a/src/models/response/attachmentResponse.ts b/src/models/response/attachmentResponse.ts index 241fba02c2..47c01cadd1 100644 --- a/src/models/response/attachmentResponse.ts +++ b/src/models/response/attachmentResponse.ts @@ -5,7 +5,7 @@ export class AttachmentResponse extends BaseResponse { url: string; fileName: string; key: string; - size: number; + size: string; sizeName: string; constructor(response: any) { diff --git a/src/models/view/attachmentView.ts b/src/models/view/attachmentView.ts index 43f0716763..96bd42a7e1 100644 --- a/src/models/view/attachmentView.ts +++ b/src/models/view/attachmentView.ts @@ -6,7 +6,7 @@ import { SymmetricCryptoKey } from '../domain/symmetricCryptoKey'; export class AttachmentView implements View { id: string = null; url: string = null; - size: number = null; + size: string = null; sizeName: string = null; fileName: string = null; key: SymmetricCryptoKey = null;