map item create request objects

This commit is contained in:
Kyle Spearrin 2018-05-14 22:15:25 -04:00
parent b5507813ab
commit 55ebf3ac64
7 changed files with 100 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import { CardView } from 'jslib/models/view';
export class CardRequest {
static template(): CardRequest {
var req = new CardRequest();
@ -10,6 +12,17 @@ export class CardRequest {
return req;
}
static toView(req: CardRequest) {
const view = new CardView();
view.cardholderName = req.cardholderName;
view.brand = req.brand;
view.number = req.number;
view.expMonth = req.expMonth;
view.expYear = req.expYear;
view.code = req.code;
return view;
}
cardholderName: string;
brand: string;
number: string;

View File

@ -27,7 +27,32 @@ export class CipherRequest {
static toView(req: CipherRequest) {
const view = new CipherView();
view.type = req.type;
view.folderId = req.folderId;
view.organizationId = req.organizationId;
view.name = req.name;
view.notes = req.notes;
view.favorite = req.favorite;
if (req.fields != null) {
view.fields = req.fields.map((f) => FieldRequest.toView(f));
}
switch (req.type) {
case CipherType.Login:
view.login = LoginRequest.toView(req.login);
break;
case CipherType.SecureNote:
view.secureNote = SecureNoteRequest.toView(req.secureNote);
break;
case CipherType.Card:
view.card = CardRequest.toView(req.card);
break;
case CipherType.Identity:
view.identity = IdentityRequest.toView(req.identity);
break;
}
return view;
}

View File

@ -1,4 +1,5 @@
import { FieldType } from 'jslib/enums/fieldType';
import { FieldView } from 'jslib/models/view';
export class FieldRequest {
static template(): FieldRequest {
@ -9,6 +10,14 @@ export class FieldRequest {
return req;
}
static toView(req: FieldRequest) {
const view = new FieldView();
view.type = req.type;
view.value = req.value;
view.name = req.name;
return view;
}
name: string;
value: string;
type: FieldType;

View File

@ -1,3 +1,5 @@
import { IdentityView } from 'jslib/models/view';
export class IdentityRequest {
static template(): IdentityRequest {
var req = new IdentityRequest();
@ -22,6 +24,29 @@ export class IdentityRequest {
return req;
}
static toView(req: IdentityRequest) {
const view = new IdentityView();
view.title = req.title;
view.firstName = req.firstName;
view.middleName = req.middleName;
view.lastName = req.lastName;
view.address1 = req.address1;
view.address2 = req.address2;
view.address3 = req.address3;
view.city = req.city;
view.state = req.state;
view.postalCode = req.postalCode;
view.country = req.country;
view.company = req.company;
view.email = req.email;
view.phone = req.phone;
view.ssn = req.ssn;
view.username = req.username;
view.passportNumber = req.passportNumber;
view.licenseNumber = req.licenseNumber;
return view;
}
title: string;
firstName: string;
middleName: string;

View File

@ -1,5 +1,7 @@
import { LoginUriRequest } from './loginUriRequest';
import { LoginView } from 'jslib/models/view';
export class LoginRequest {
static template(): LoginRequest {
var req = new LoginRequest();
@ -10,6 +12,17 @@ export class LoginRequest {
return req;
}
static toView(req: LoginRequest) {
const view = new LoginView();
if (req.uris != null) {
view.uris = req.uris.map((u) => LoginUriRequest.toView(u));
}
view.username = req.username;
view.password = req.password;
view.totp = req.totp;
return view;
}
uris: LoginUriRequest[];
username: string;
password: string;

View File

@ -1,4 +1,5 @@
import { UriMatchType } from 'jslib/enums/uriMatchType';
import { LoginUriView } from 'jslib/models/view/loginUriView';
export class LoginUriRequest {
static template(): LoginUriRequest {
@ -8,6 +9,13 @@ export class LoginUriRequest {
return req;
}
static toView(req: LoginUriRequest) {
const view = new LoginUriView();
view.uri = req.uri;
view.match = req.match
return view;
}
uri: string;
match: UriMatchType = null;
}

View File

@ -1,4 +1,5 @@
import { SecureNoteType } from 'jslib/enums/secureNoteType';
import { SecureNoteView } from 'jslib/models/view/secureNoteView';
export class SecureNoteRequest {
static template(): SecureNoteRequest {
@ -7,5 +8,11 @@ export class SecureNoteRequest {
return req;
}
static toView(req: SecureNoteRequest) {
const view = new SecureNoteView();
view.type = req.type;
return view;
}
type: SecureNoteType;
}