From 07cc64c0b8c05accee56131099be39570f98b9b8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 15 May 2018 12:18:47 -0400 Subject: [PATCH] refactor req/res models --- src/commands/create.command.ts | 12 +- src/commands/edit.command.ts | 12 +- src/commands/get.command.ts | 28 ++--- .../{request/cardRequest.ts => card.ts} | 23 +++- src/models/cipher.ts | 104 ++++++++++++++++++ src/models/collection.ts | 23 ++++ src/models/field.ts | 34 ++++++ src/models/folder.ts | 18 +++ .../identityRequest.ts => identity.ts} | 35 +++++- src/models/login.ts | 43 ++++++++ .../loginUriRequest.ts => loginUri.ts} | 18 ++- src/models/request/cipherRequest.ts | 69 ------------ src/models/request/collectionRequest.ts | 3 - src/models/request/fieldRequest.ts | 23 ---- src/models/request/folderRequest.ts | 10 -- src/models/request/loginRequest.ts | 29 ----- src/models/request/secureNoteRequest.ts | 17 --- src/models/response/baseResponse.ts | 8 +- src/models/response/cipherResponse.ts | 16 +-- src/models/response/collectionResponse.ts | 12 +- src/models/response/folderResponse.ts | 10 +- src/models/response/listResponse.ts | 5 +- src/models/response/stringResponse.ts | 9 +- src/models/response/templateResponse.ts | 5 +- src/models/secureNote.ts | 26 +++++ 25 files changed, 363 insertions(+), 229 deletions(-) rename src/models/{request/cardRequest.ts => card.ts} (54%) create mode 100644 src/models/cipher.ts create mode 100644 src/models/collection.ts create mode 100644 src/models/field.ts create mode 100644 src/models/folder.ts rename src/models/{request/identityRequest.ts => identity.ts} (64%) create mode 100644 src/models/login.ts rename src/models/{request/loginUriRequest.ts => loginUri.ts} (53%) delete mode 100644 src/models/request/cipherRequest.ts delete mode 100644 src/models/request/collectionRequest.ts delete mode 100644 src/models/request/fieldRequest.ts delete mode 100644 src/models/request/folderRequest.ts delete mode 100644 src/models/request/loginRequest.ts delete mode 100644 src/models/request/secureNoteRequest.ts create mode 100644 src/models/secureNote.ts diff --git a/src/commands/create.command.ts b/src/commands/create.command.ts index 41a216d871..e53d6fffe9 100644 --- a/src/commands/create.command.ts +++ b/src/commands/create.command.ts @@ -5,8 +5,8 @@ import { FolderService } from 'jslib/services/folder.service'; import { Response } from '../models/response'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { FolderRequest } from '../models/request/folderRequest'; +import { Cipher } from '../models/cipher'; +import { Folder } from '../models/folder'; export class CreateCommand { constructor(private cipherService: CipherService, private folderService: FolderService) { } @@ -30,8 +30,8 @@ export class CreateCommand { } } - private async createCipher(req: CipherRequest) { - const cipher = await this.cipherService.encrypt(CipherRequest.toView(req)); + private async createCipher(req: Cipher) { + const cipher = await this.cipherService.encrypt(Cipher.toView(req)); try { await this.cipherService.saveWithServer(cipher); return Response.success(); @@ -40,8 +40,8 @@ export class CreateCommand { } } - private async createFolder(req: FolderRequest) { - const folder = await this.folderService.encrypt(FolderRequest.toView(req)); + private async createFolder(req: Folder) { + const folder = await this.folderService.encrypt(Folder.toView(req)); try { await this.folderService.saveWithServer(folder); return Response.success(); diff --git a/src/commands/edit.command.ts b/src/commands/edit.command.ts index 3647b34ac0..796761fc27 100644 --- a/src/commands/edit.command.ts +++ b/src/commands/edit.command.ts @@ -5,8 +5,8 @@ import { FolderService } from 'jslib/services/folder.service'; import { Response } from '../models/response'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { FolderRequest } from '../models/request/folderRequest'; +import { Cipher } from '../models/cipher'; +import { Folder } from '../models/folder'; export class EditCommand { constructor(private cipherService: CipherService, private folderService: FolderService) { } @@ -30,14 +30,14 @@ export class EditCommand { } } - private async editCipher(id: string, req: CipherRequest) { + private async editCipher(id: string, req: Cipher) { const cipher = await this.cipherService.get(id); if (cipher == null) { return Response.notFound(); } let cipherView = await cipher.decrypt(); - cipherView = CipherRequest.toView(req, cipherView); + cipherView = Cipher.toView(req, cipherView); const encCipher = await this.cipherService.encrypt(cipherView); try { await this.cipherService.saveWithServer(encCipher); @@ -47,14 +47,14 @@ export class EditCommand { } } - private async editFolder(id: string, req: FolderRequest) { + private async editFolder(id: string, req: Folder) { const folder = await this.folderService.get(id); if (folder == null) { return Response.notFound(); } let folderView = await folder.decrypt(); - folderView = FolderRequest.toView(req, folderView); + folderView = Folder.toView(req, folderView); const encFolder = await this.folderService.encrypt(folderView); try { await this.folderService.saveWithServer(encFolder); diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index 02ad430494..f6eba68d09 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -14,13 +14,13 @@ import { FolderResponse } from '../models/response/folderResponse'; import { StringResponse } from '../models/response/stringResponse'; import { TemplateResponse } from '../models/response/templateResponse'; -import { CardRequest } from '../models/request/cardRequest'; -import { CipherRequest } from '../models/request/cipherRequest'; -import { FieldRequest } from '../models/request/fieldRequest'; -import { IdentityRequest } from '../models/request/identityRequest'; -import { LoginRequest } from '../models/request/loginRequest'; -import { LoginUriRequest } from '../models/request/loginUriRequest'; -import { SecureNoteRequest } from '../models/request/secureNoteRequest'; +import { Card } from '../models/card'; +import { Cipher } from '../models/cipher'; +import { Field } from '../models/field'; +import { Identity } from '../models/identity'; +import { Login } from '../models/login'; +import { LoginUri } from '../models/loginUri'; +import { SecureNote } from '../models/secureNote'; export class GetCommand { constructor(private cipherService: CipherService, private folderService: FolderService, @@ -104,25 +104,25 @@ export class GetCommand { let template: any = null; switch (id.toLowerCase()) { case 'item': - template = CipherRequest.template(); + template = Cipher.template(); break; case 'field': - template = FieldRequest.template(); + template = Field.template(); break; case 'login': - template = LoginRequest.template(); + template = Login.template(); break; case 'loginuri': - template = LoginUriRequest.template(); + template = LoginUri.template(); break; case 'card': - template = CardRequest.template(); + template = Card.template(); break; case 'identity': - template = IdentityRequest.template(); + template = Identity.template(); break; case 'securenote': - template = SecureNoteRequest.template(); + template = SecureNote.template(); break; default: return Response.badRequest('Unknown template object.'); diff --git a/src/models/request/cardRequest.ts b/src/models/card.ts similarity index 54% rename from src/models/request/cardRequest.ts rename to src/models/card.ts index f1359af61e..0e73c763e7 100644 --- a/src/models/request/cardRequest.ts +++ b/src/models/card.ts @@ -1,8 +1,8 @@ -import { CardView } from 'jslib/models/view'; +import { CardView } from 'jslib/models/view/cardView'; -export class CardRequest { - static template(): CardRequest { - const req = new CardRequest(); +export class Card { + static template(): Card { + const req = new Card(); req.cardholderName = 'John Doe'; req.brand = 'visa'; req.number = '4242424242424242'; @@ -12,7 +12,7 @@ export class CardRequest { return req; } - static toView(req: CardRequest, view = new CardView()) { + static toView(req: Card, view = new CardView()) { view.cardholderName = req.cardholderName; view.brand = req.brand; view.number = req.number; @@ -28,4 +28,17 @@ export class CardRequest { expMonth: string; expYear: string; code: string; + + constructor(o?: CardView) { + if (o == null) { + return; + } + + this.cardholderName = o.cardholderName; + this.brand = o.brand; + this.number = o.number; + this.expMonth = o.expMonth; + this.expYear = o.expYear; + this.code = o.code; + } } diff --git a/src/models/cipher.ts b/src/models/cipher.ts new file mode 100644 index 0000000000..930c62ca3f --- /dev/null +++ b/src/models/cipher.ts @@ -0,0 +1,104 @@ +import { CipherType } from 'jslib/enums/cipherType'; + +import { CipherRequest } from 'jslib/models/request/cipherRequest'; +import { CipherView } from 'jslib/models/view/cipherView'; + +import { Card } from './card'; +import { Field } from './field'; +import { Identity } from './identity'; +import { Login } from './login'; +import { SecureNote } from './secureNote'; + +export class Cipher { + static template(): Cipher { + const req = new Cipher(); + req.type = CipherType.Login; + req.folderId = null; + req.organizationId = null; + req.name = 'Item name'; + req.notes = 'Some notes about this item.'; + req.favorite = false; + req.fields = []; + req.login = null; + req.secureNote = null; + req.card = null; + req.identity = null; + return req; + } + + static toView(req: CipherRequest, view = new CipherView()) { + view.type = req.type; + view.folderId = req.folderId; + if (view.organizationId == null) { + 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) => Field.toView(f)); + } + + switch (req.type) { + case CipherType.Login: + view.login = Login.toView(req.login); + break; + case CipherType.SecureNote: + view.secureNote = SecureNote.toView(req.secureNote); + break; + case CipherType.Card: + view.card = Card.toView(req.card); + break; + case CipherType.Identity: + view.identity = Identity.toView(req.identity); + break; + } + + return view; + } + + type: CipherType; + folderId: string; + organizationId: string; + name: string; + notes: string; + favorite: boolean; + fields: Field[]; + login: Login; + secureNote: SecureNote; + card: Card; + identity: Identity; + + constructor(o?: CipherView) { + if (o == null) { + return; + } + + this.organizationId = o.organizationId; + this.folderId = o.folderId; + this.type = o.type; + this.name = o.name; + this.notes = o.notes; + this.favorite = o.favorite; + + if (o.fields != null) { + this.fields = o.fields.map((f) => new Field(f)); + } + + switch (o.type) { + case CipherType.Login: + this.login = new Login(o.login); + break; + case CipherType.SecureNote: + this.secureNote = new SecureNote(o.secureNote); + break; + case CipherType.Card: + this.card = new Card(o.card); + break; + case CipherType.Identity: + this.identity = new Identity(o.identity); + break; + } + } +} diff --git a/src/models/collection.ts b/src/models/collection.ts new file mode 100644 index 0000000000..20e707f399 --- /dev/null +++ b/src/models/collection.ts @@ -0,0 +1,23 @@ +import { CollectionView } from 'jslib/models/view/collectionView'; + +export class Collection { + static toView(req: Collection, view = new CollectionView()) { + view.name = req.name; + if (view.organizationId == null) { + view.organizationId = req.organizationId; + } + return view; + } + + name: string; + organizationId: string; + + constructor(o?: CollectionView) { + if (o == null) { + return; + } + + this.name = o.name; + this.organizationId = o.organizationId; + } +} diff --git a/src/models/field.ts b/src/models/field.ts new file mode 100644 index 0000000000..686ebddac6 --- /dev/null +++ b/src/models/field.ts @@ -0,0 +1,34 @@ +import { FieldType } from 'jslib/enums/fieldType'; + +import { FieldView } from 'jslib/models/view/fieldView'; + +export class Field { + static template(): Field { + const req = new Field(); + req.name = 'Field name'; + req.value = 'Some value'; + req.type = FieldType.Text; + return req; + } + + static toView(req: Field, view = new FieldView()) { + view.type = req.type; + view.value = req.value; + view.name = req.name; + return view; + } + + name: string; + value: string; + type: FieldType; + + constructor(o?: FieldView) { + if (o == null) { + return; + } + + this.name = o.name; + this.value = o.value; + this.type = o.type; + } +} diff --git a/src/models/folder.ts b/src/models/folder.ts new file mode 100644 index 0000000000..010b5fa88c --- /dev/null +++ b/src/models/folder.ts @@ -0,0 +1,18 @@ +import { FolderView } from 'jslib/models/view/folderView'; + +export class Folder { + static toView(req: Folder, view = new FolderView()) { + view.name = req.name; + return view; + } + + name: string; + + constructor(o?: FolderView) { + if (o == null) { + return; + } + + this.name = o.name; + } +} diff --git a/src/models/request/identityRequest.ts b/src/models/identity.ts similarity index 64% rename from src/models/request/identityRequest.ts rename to src/models/identity.ts index bc62ede189..be0a18897d 100644 --- a/src/models/request/identityRequest.ts +++ b/src/models/identity.ts @@ -1,8 +1,8 @@ -import { IdentityView } from 'jslib/models/view'; +import { IdentityView } from 'jslib/models/view/identityView'; -export class IdentityRequest { - static template(): IdentityRequest { - const req = new IdentityRequest(); +export class Identity { + static template(): Identity { + const req = new Identity(); req.title = 'Mr'; req.firstName = 'John'; req.middleName = 'William'; @@ -24,7 +24,7 @@ export class IdentityRequest { return req; } - static toView(req: IdentityRequest, view = new IdentityView()) { + static toView(req: Identity, view = new IdentityView()) { view.title = req.title; view.firstName = req.firstName; view.middleName = req.middleName; @@ -64,4 +64,29 @@ export class IdentityRequest { username: string; passportNumber: string; licenseNumber: string; + + constructor(o?: IdentityView) { + if (o == null) { + return; + } + + this.title = o.title; + this.firstName = o.firstName; + this.middleName = o.middleName; + this.lastName = o.lastName; + this.address1 = o.address1; + this.address2 = o.address2; + this.address3 = o.address3; + this.city = o.city; + this.state = o.state; + this.postalCode = o.postalCode; + this.country = o.country; + this.company = o.company; + this.email = o.email; + this.phone = o.phone; + this.ssn = o.ssn; + this.username = o.username; + this.passportNumber = o.passportNumber; + this.licenseNumber = o.licenseNumber; + } } diff --git a/src/models/login.ts b/src/models/login.ts new file mode 100644 index 0000000000..91eef24213 --- /dev/null +++ b/src/models/login.ts @@ -0,0 +1,43 @@ +import { LoginUri } from './loginUri'; + +import { LoginView } from 'jslib/models/view/loginView'; + +export class Login { + static template(): Login { + const req = new Login(); + req.uris = []; + req.username = 'jdoe'; + req.password = 'myp@ssword123'; + req.totp = 'JBSWY3DPEHPK3PXP'; + return req; + } + + static toView(req: Login, view = new LoginView()) { + if (req.uris != null) { + view.uris = req.uris.map((u) => LoginUri.toView(u)); + } + view.username = req.username; + view.password = req.password; + view.totp = req.totp; + return view; + } + + uris: LoginUri[]; + username: string; + password: string; + totp: string; + + constructor(o?: LoginView) { + if (o == null) { + return; + } + + if (o.uris != null) { + this.uris = o.uris.map((u) => new LoginUri(u)); + } + + this.username = o.username; + this.password = o.password; + this.totp = o.totp; + } +} diff --git a/src/models/request/loginUriRequest.ts b/src/models/loginUri.ts similarity index 53% rename from src/models/request/loginUriRequest.ts rename to src/models/loginUri.ts index d645090b7f..ac4059e333 100644 --- a/src/models/request/loginUriRequest.ts +++ b/src/models/loginUri.ts @@ -1,15 +1,16 @@ import { UriMatchType } from 'jslib/enums/uriMatchType'; + import { LoginUriView } from 'jslib/models/view/loginUriView'; -export class LoginUriRequest { - static template(): LoginUriRequest { - const req = new LoginUriRequest(); +export class LoginUri { + static template(): LoginUri { + const req = new LoginUri(); req.uri = 'https://google.com'; req.match = null; return req; } - static toView(req: LoginUriRequest, view = new LoginUriView()) { + static toView(req: LoginUri, view = new LoginUriView()) { view.uri = req.uri; view.match = req.match; return view; @@ -17,4 +18,13 @@ export class LoginUriRequest { uri: string; match: UriMatchType = null; + + constructor(o?: LoginUriView) { + if (o == null) { + return; + } + + this.uri = o.uri; + this.match = o.match; + } } diff --git a/src/models/request/cipherRequest.ts b/src/models/request/cipherRequest.ts deleted file mode 100644 index 1fb9b31a06..0000000000 --- a/src/models/request/cipherRequest.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { CipherType } from 'jslib/enums/cipherType'; - -import { CardRequest } from './cardRequest'; -import { FieldRequest } from './fieldRequest'; -import { IdentityRequest } from './identityRequest'; -import { LoginRequest } from './loginRequest'; -import { SecureNoteRequest } from './secureNoteRequest'; - -import { CipherView } from 'jslib/models/view/cipherView'; - -export class CipherRequest { - static template(): CipherRequest { - const req = new CipherRequest(); - req.type = CipherType.Login; - req.folderId = null; - req.organizationId = null; - req.name = 'Item name'; - req.notes = 'Some notes about this item.'; - req.favorite = false; - req.fields = []; - req.login = null; - req.secureNote = null; - req.card = null; - req.identity = null; - return req; - } - - static toView(req: CipherRequest, 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; - } - - type: CipherType; - folderId: string; - organizationId: string; - name: string; - notes: string; - favorite: boolean; - fields: FieldRequest[]; - login: LoginRequest; - secureNote: SecureNoteRequest; - card: CardRequest; - identity: IdentityRequest; -} diff --git a/src/models/request/collectionRequest.ts b/src/models/request/collectionRequest.ts deleted file mode 100644 index be8ea257c0..0000000000 --- a/src/models/request/collectionRequest.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class CollectionRequest { - name: string; -} diff --git a/src/models/request/fieldRequest.ts b/src/models/request/fieldRequest.ts deleted file mode 100644 index 3747ac378e..0000000000 --- a/src/models/request/fieldRequest.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { FieldType } from 'jslib/enums/fieldType'; -import { FieldView } from 'jslib/models/view'; - -export class FieldRequest { - static template(): FieldRequest { - const req = new FieldRequest(); - req.name = 'Field name'; - req.value = 'Some value'; - req.type = FieldType.Text; - return req; - } - - static toView(req: FieldRequest, view = new FieldView()) { - view.type = req.type; - view.value = req.value; - view.name = req.name; - return view; - } - - name: string; - value: string; - type: FieldType; -} diff --git a/src/models/request/folderRequest.ts b/src/models/request/folderRequest.ts deleted file mode 100644 index 93d6511caa..0000000000 --- a/src/models/request/folderRequest.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { FolderView } from 'jslib/models/view/folderView'; - -export class FolderRequest { - static toView(req: FolderRequest, view = new FolderView()) { - view.name = req.name; - return view; - } - - name: string; -} diff --git a/src/models/request/loginRequest.ts b/src/models/request/loginRequest.ts deleted file mode 100644 index 1917f21727..0000000000 --- a/src/models/request/loginRequest.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { LoginUriRequest } from './loginUriRequest'; - -import { LoginView } from 'jslib/models/view'; - -export class LoginRequest { - static template(): LoginRequest { - const req = new LoginRequest(); - req.uris = []; - req.username = 'jdoe'; - req.password = 'myp@ssword123'; - req.totp = 'JBSWY3DPEHPK3PXP'; - return req; - } - - static toView(req: LoginRequest, 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; - totp: string; -} diff --git a/src/models/request/secureNoteRequest.ts b/src/models/request/secureNoteRequest.ts deleted file mode 100644 index 790488cca1..0000000000 --- a/src/models/request/secureNoteRequest.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { SecureNoteType } from 'jslib/enums/secureNoteType'; -import { SecureNoteView } from 'jslib/models/view/secureNoteView'; - -export class SecureNoteRequest { - static template(): SecureNoteRequest { - const req = new SecureNoteRequest(); - req.type = SecureNoteType.Generic; - return req; - } - - static toView(req: SecureNoteRequest, view = new SecureNoteView()) { - view.type = req.type; - return view; - } - - type: SecureNoteType; -} diff --git a/src/models/response/baseResponse.ts b/src/models/response/baseResponse.ts index 51263967f6..9d8beca059 100644 --- a/src/models/response/baseResponse.ts +++ b/src/models/response/baseResponse.ts @@ -1,9 +1,3 @@ -export abstract class BaseResponse { +export interface BaseResponse { object: string; - - constructor(object?: string) { - if (object != null) { - this.object = object; - } - } } diff --git a/src/models/response/cipherResponse.ts b/src/models/response/cipherResponse.ts index ead00ce687..683e0aa77d 100644 --- a/src/models/response/cipherResponse.ts +++ b/src/models/response/cipherResponse.ts @@ -2,21 +2,15 @@ import { CipherView } from 'jslib/models/view/cipherView'; import { BaseResponse } from './baseResponse'; -import { CipherType } from 'jslib/enums'; +import { Cipher } from '../cipher'; -export class CipherResponse extends BaseResponse { +export class CipherResponse extends Cipher implements BaseResponse { + object: string; id: string; - organizationId: string; - type: CipherType; - name: string; - notes: string; constructor(o: CipherView) { - super('item'); + super(o); + this.object = 'item'; this.id = o.id; - this.organizationId = o.organizationId; - this.type = o.type; - this.name = o.name; - this.notes = o.notes; } } diff --git a/src/models/response/collectionResponse.ts b/src/models/response/collectionResponse.ts index 03627a11e2..627c10c3fc 100644 --- a/src/models/response/collectionResponse.ts +++ b/src/models/response/collectionResponse.ts @@ -2,15 +2,15 @@ import { CollectionView } from 'jslib/models/view/collectionView'; import { BaseResponse } from './baseResponse'; -export class CollectionResponse extends BaseResponse { +import { Collection } from '../collection'; + +export class CollectionResponse extends Collection implements BaseResponse { + object: string; id: string; - organizationId: string; - name: string; constructor(o: CollectionView) { - super('collection'); + super(o); + this.object = 'collection'; this.id = o.id; - this.organizationId = o.organizationId; - this.name = o.name; } } diff --git a/src/models/response/folderResponse.ts b/src/models/response/folderResponse.ts index 6184c53fe2..66875abe19 100644 --- a/src/models/response/folderResponse.ts +++ b/src/models/response/folderResponse.ts @@ -2,13 +2,15 @@ import { FolderView } from 'jslib/models/view/folderView'; import { BaseResponse } from './baseResponse'; -export class FolderResponse extends BaseResponse { +import { Folder } from '../folder'; + +export class FolderResponse extends Folder implements BaseResponse { + object: string; id: string; - name: string; constructor(o: FolderView) { - super('folder'); + super(o); + this.object = 'folder'; this.id = o.id; - this.name = o.name; } } diff --git a/src/models/response/listResponse.ts b/src/models/response/listResponse.ts index 970f58fe07..7995bd4fe8 100644 --- a/src/models/response/listResponse.ts +++ b/src/models/response/listResponse.ts @@ -1,10 +1,11 @@ import { BaseResponse } from './baseResponse'; -export class ListResponse extends BaseResponse { +export class ListResponse implements BaseResponse { + object: string; data: BaseResponse[]; constructor(data: BaseResponse[]) { - super('list'); + this.object = 'list'; this.data = data; } } diff --git a/src/models/response/stringResponse.ts b/src/models/response/stringResponse.ts index 4087359574..b9a0f04412 100644 --- a/src/models/response/stringResponse.ts +++ b/src/models/response/stringResponse.ts @@ -1,14 +1,11 @@ -import { CipherView } from 'jslib/models/view/cipherView'; - import { BaseResponse } from './baseResponse'; -import { CipherType } from 'jslib/enums'; - -export class StringResponse extends BaseResponse { +export class StringResponse implements BaseResponse { + object: string; data: string; constructor(data: string) { - super('string'); + this.object = 'string'; this.data = data; } } diff --git a/src/models/response/templateResponse.ts b/src/models/response/templateResponse.ts index feed2fbf44..1876f0a04a 100644 --- a/src/models/response/templateResponse.ts +++ b/src/models/response/templateResponse.ts @@ -1,10 +1,11 @@ import { BaseResponse } from './baseResponse'; -export class TemplateResponse extends BaseResponse { +export class TemplateResponse implements BaseResponse { + object: string; template: any; constructor(template: any) { - super('template'); + this.object = 'template'; this.template = template; } } diff --git a/src/models/secureNote.ts b/src/models/secureNote.ts new file mode 100644 index 0000000000..880691f6da --- /dev/null +++ b/src/models/secureNote.ts @@ -0,0 +1,26 @@ +import { SecureNoteType } from 'jslib/enums/secureNoteType'; + +import { SecureNoteView } from 'jslib/models/view/secureNoteView'; + +export class SecureNote { + static template(): SecureNote { + const req = new SecureNote(); + req.type = SecureNoteType.Generic; + return req; + } + + static toView(req: SecureNote, view = new SecureNoteView()) { + view.type = req.type; + return view; + } + + type: SecureNoteType; + + constructor(o?: SecureNoteView) { + if (o == null) { + return; + } + + this.type = o.type; + } +}