mirror of
https://github.com/bitwarden/cli
synced 2025-12-24 12:13:13 +00:00
cli response objects
This commit is contained in:
30
src/models/response.ts
Normal file
30
src/models/response.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { BaseResponse } from './response/baseResponse';
|
||||
|
||||
export class Response {
|
||||
static error(message: string): Response {
|
||||
var res = new Response();
|
||||
res.success = false;
|
||||
res.message = message;
|
||||
return res;
|
||||
}
|
||||
|
||||
static notFound(): Response {
|
||||
return Response.error('Not found.');
|
||||
}
|
||||
|
||||
static badRequest(message: string): Response {
|
||||
return Response.error(message);
|
||||
}
|
||||
|
||||
static success(data?: BaseResponse): Response {
|
||||
var res = new Response();
|
||||
res.success = true;
|
||||
res.data = data;
|
||||
return res;
|
||||
}
|
||||
|
||||
success: boolean;
|
||||
message: string;
|
||||
errorCode: number;
|
||||
data: BaseResponse;
|
||||
}
|
||||
9
src/models/response/baseResponse.ts
Normal file
9
src/models/response/baseResponse.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export abstract class BaseResponse {
|
||||
object: string;
|
||||
|
||||
constructor(object?: string) {
|
||||
if (object != null) {
|
||||
this.object = object;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/models/response/cipherResponse.ts
Normal file
22
src/models/response/cipherResponse.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { CipherView } from 'jslib/models/view/cipherView';
|
||||
|
||||
import { BaseResponse } from './baseResponse';
|
||||
|
||||
import { CipherType } from 'jslib/enums';
|
||||
|
||||
export class CipherResponse extends BaseResponse {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
type: CipherType;
|
||||
name: string;
|
||||
notes: string;
|
||||
|
||||
constructor(o: CipherView) {
|
||||
super('item');
|
||||
this.id = o.id;
|
||||
this.organizationId = o.organizationId;
|
||||
this.type = o.type;
|
||||
this.name = o.name;
|
||||
this.notes = o.notes;
|
||||
}
|
||||
}
|
||||
16
src/models/response/collectionResponse.ts
Normal file
16
src/models/response/collectionResponse.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { CollectionView } from 'jslib/models/view/collectionView';
|
||||
|
||||
import { BaseResponse } from './baseResponse';
|
||||
|
||||
export class CollectionResponse extends BaseResponse {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
|
||||
constructor(o: CollectionView) {
|
||||
super('collection');
|
||||
this.id = o.id;
|
||||
this.organizationId = o.organizationId;
|
||||
this.name = o.name;
|
||||
}
|
||||
}
|
||||
14
src/models/response/folderResponse.ts
Normal file
14
src/models/response/folderResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { FolderView } from 'jslib/models/view/folderView';
|
||||
|
||||
import { BaseResponse } from './baseResponse';
|
||||
|
||||
export class FolderResponse extends BaseResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
constructor(o: FolderView) {
|
||||
super('folder');
|
||||
this.id = o.id;
|
||||
this.name = o.name;
|
||||
}
|
||||
}
|
||||
10
src/models/response/listResponse.ts
Normal file
10
src/models/response/listResponse.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { BaseResponse } from './baseResponse';
|
||||
|
||||
export class ListResponse extends BaseResponse {
|
||||
data: BaseResponse[];
|
||||
|
||||
constructor(data: BaseResponse[]) {
|
||||
super('list');
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
14
src/models/response/stringResponse.ts
Normal file
14
src/models/response/stringResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { CipherView } from 'jslib/models/view/cipherView';
|
||||
|
||||
import { BaseResponse } from './baseResponse';
|
||||
|
||||
import { CipherType } from 'jslib/enums';
|
||||
|
||||
export class StringResponse extends BaseResponse {
|
||||
data: string;
|
||||
|
||||
constructor(data: string) {
|
||||
super('string');
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user