improved some syntax and a few fixes

This commit is contained in:
Kyle Spearrin 2019-04-13 21:20:04 -04:00
parent 42771c1a2d
commit b7a736294b
7 changed files with 17 additions and 53 deletions

View File

@ -5,7 +5,7 @@ export class AttachmentData {
url: string; url: string;
fileName: string; fileName: string;
key: string; key: string;
size: number; size: string;
sizeName: string; sizeName: string;
constructor(response?: AttachmentResponse) { constructor(response?: AttachmentResponse) {

View File

@ -48,12 +48,7 @@ export class CipherData {
this.type = response.type; this.type = response.type;
this.name = response.name; this.name = response.name;
this.notes = response.notes; this.notes = response.notes;
this.collectionIds = collectionIds != null ? collectionIds : response.collectionIds;
if (collectionIds != null) {
this.collectionIds = collectionIds;
} else {
this.collectionIds = response.collectionIds;
}
switch (this.type) { switch (this.type) {
case CipherType.Login: case CipherType.Login:
@ -73,24 +68,13 @@ export class CipherData {
} }
if (response.fields != null) { if (response.fields != null) {
this.fields = []; this.fields = response.fields.map((f) => new FieldData(f));
response.fields.forEach((field) => {
this.fields.push(new FieldData(field));
});
} }
if (response.attachments != null) { if (response.attachments != null) {
this.attachments = []; this.attachments = response.attachments.map((a) => new AttachmentData(a));
response.attachments.forEach((attachment) => {
this.attachments.push(new AttachmentData(attachment));
});
} }
if (response.passwordHistory != null) { if (response.passwordHistory != null) {
this.passwordHistory = []; this.passwordHistory = response.passwordHistory.map((ph) => new PasswordHistoryData(ph));
response.passwordHistory.forEach((ph) => {
this.passwordHistory.push(new PasswordHistoryData(ph));
});
} }
} }
} }

View File

@ -13,7 +13,7 @@ import { Utils } from '../../misc/utils';
export class Attachment extends Domain { export class Attachment extends Domain {
id: string; id: string;
url: string; url: string;
size: number; size: string;
sizeName: string; sizeName: string;
key: CipherString; key: CipherString;
fileName: CipherString; fileName: CipherString;
@ -62,6 +62,7 @@ export class Attachment extends Domain {
toAttachmentData(): AttachmentData { toAttachmentData(): AttachmentData {
const a = new AttachmentData(); const a = new AttachmentData();
a.size = this.size;
this.buildDataModel(this, a, { this.buildDataModel(this, a, {
id: null, id: null,
url: null, url: null,

View File

@ -76,28 +76,19 @@ export class Cipher extends Domain {
} }
if (obj.attachments != null) { if (obj.attachments != null) {
this.attachments = []; this.attachments = obj.attachments.map((a) => new Attachment(a, alreadyEncrypted));
obj.attachments.forEach((attachment) => {
this.attachments.push(new Attachment(attachment, alreadyEncrypted));
});
} else { } else {
this.attachments = null; this.attachments = null;
} }
if (obj.fields != null) { if (obj.fields != null) {
this.fields = []; this.fields = obj.fields.map((f) => new Field(f, alreadyEncrypted));
obj.fields.forEach((field) => {
this.fields.push(new Field(field, alreadyEncrypted));
});
} else { } else {
this.fields = null; this.fields = null;
} }
if (obj.passwordHistory != null) { if (obj.passwordHistory != null) {
this.passwordHistory = []; this.passwordHistory = obj.passwordHistory.map((ph) => new Password(ph, alreadyEncrypted));
obj.passwordHistory.forEach((ph) => {
this.passwordHistory.push(new Password(ph, alreadyEncrypted));
});
} else { } else {
this.passwordHistory = null; this.passwordHistory = null;
} }
@ -205,24 +196,13 @@ export class Cipher extends Domain {
} }
if (this.fields != null) { if (this.fields != null) {
c.fields = []; c.fields = this.fields.map((f) => f.toFieldData());
this.fields.forEach((field) => {
c.fields.push(field.toFieldData());
});
} }
if (this.attachments != null) { if (this.attachments != null) {
c.attachments = []; c.attachments = this.attachments.map((a) => a.toAttachmentData());
this.attachments.forEach((attachment) => {
c.attachments.push(attachment.toAttachmentData());
});
} }
if (this.passwordHistory != null) { if (this.passwordHistory != null) {
c.passwordHistory = []; c.passwordHistory = this.passwordHistory.map((ph) => ph.toPasswordHistoryData());
this.passwordHistory.forEach((ph) => {
c.passwordHistory.push(ph.toPasswordHistoryData());
});
} }
return c; return c;
} }

View File

@ -21,11 +21,10 @@ export class Password extends Domain {
this.lastUsedDate = new Date(obj.lastUsedDate); this.lastUsedDate = new Date(obj.lastUsedDate);
} }
async decrypt(orgId: string): Promise<PasswordHistoryView> { decrypt(orgId: string): Promise<PasswordHistoryView> {
const view = await this.decryptObj(new PasswordHistoryView(this), { return this.decryptObj(new PasswordHistoryView(this), {
password: null, password: null,
}, orgId); }, orgId);
return view;
} }
toPasswordHistoryData(): PasswordHistoryData { toPasswordHistoryData(): PasswordHistoryData {

View File

@ -5,7 +5,7 @@ export class AttachmentResponse extends BaseResponse {
url: string; url: string;
fileName: string; fileName: string;
key: string; key: string;
size: number; size: string;
sizeName: string; sizeName: string;
constructor(response: any) { constructor(response: any) {

View File

@ -6,7 +6,7 @@ import { SymmetricCryptoKey } from '../domain/symmetricCryptoKey';
export class AttachmentView implements View { export class AttachmentView implements View {
id: string = null; id: string = null;
url: string = null; url: string = null;
size: number = null; size: string = null;
sizeName: string = null; sizeName: string = null;
fileName: string = null; fileName: string = null;
key: SymmetricCryptoKey = null; key: SymmetricCryptoKey = null;