1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

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 { export class CardRequest {
static template(): CardRequest { static template(): CardRequest {
var req = new CardRequest(); var req = new CardRequest();
@ -10,6 +12,17 @@ export class CardRequest {
return req; 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; cardholderName: string;
brand: string; brand: string;
number: string; number: string;

View File

@ -27,7 +27,32 @@ export class CipherRequest {
static toView(req: CipherRequest) { static toView(req: CipherRequest) {
const view = new CipherView(); const view = new CipherView();
view.type = req.type;
view.folderId = req.folderId;
view.organizationId = req.organizationId;
view.name = req.name; 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; return view;
} }

View File

@ -1,4 +1,5 @@
import { FieldType } from 'jslib/enums/fieldType'; import { FieldType } from 'jslib/enums/fieldType';
import { FieldView } from 'jslib/models/view';
export class FieldRequest { export class FieldRequest {
static template(): FieldRequest { static template(): FieldRequest {
@ -9,6 +10,14 @@ export class FieldRequest {
return req; 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; name: string;
value: string; value: string;
type: FieldType; type: FieldType;

View File

@ -1,3 +1,5 @@
import { IdentityView } from 'jslib/models/view';
export class IdentityRequest { export class IdentityRequest {
static template(): IdentityRequest { static template(): IdentityRequest {
var req = new IdentityRequest(); var req = new IdentityRequest();
@ -22,6 +24,29 @@ export class IdentityRequest {
return req; 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; title: string;
firstName: string; firstName: string;
middleName: string; middleName: string;

View File

@ -1,5 +1,7 @@
import { LoginUriRequest } from './loginUriRequest'; import { LoginUriRequest } from './loginUriRequest';
import { LoginView } from 'jslib/models/view';
export class LoginRequest { export class LoginRequest {
static template(): LoginRequest { static template(): LoginRequest {
var req = new LoginRequest(); var req = new LoginRequest();
@ -10,6 +12,17 @@ export class LoginRequest {
return req; 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[]; uris: LoginUriRequest[];
username: string; username: string;
password: string; password: string;

View File

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

View File

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