1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

cli response objects

This commit is contained in:
Kyle Spearrin
2018-05-14 14:54:19 -04:00
parent 3dd38cbe12
commit 4f3f84539d
13 changed files with 203 additions and 58 deletions

View File

@@ -4,39 +4,44 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/services/collection.service';
import { FolderService } from 'jslib/services/folder.service';
import { Response } from '../models/response';
import { CipherResponse } from '../models/response/cipherResponse';
import { CollectionResponse } from '../models/response/collectionResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { ListResponse } from '../models/response/listResponse';
export class ListCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService) { }
async run(object: string, cmd: program.Command) {
async run(object: string, cmd: program.Command): Promise<Response> {
switch (object) {
case 'items':
await this.listCiphers();
break;
return await this.listCiphers();
case 'folders':
await this.listFolders();
break;
return await this.listFolders();
case 'collections':
await this.listCollections();
break;
return await this.listCollections();
default:
console.log('Unknown object: ' + object);
break;
return Response.badRequest('Unknown object.');
}
}
private async listCiphers() {
const ciphers = await this.cipherService.getAllDecrypted();
console.log(JSON.stringify(ciphers));
const res = new ListResponse(ciphers.map((o) => new CipherResponse(o)));
return Response.success(res);
}
private async listFolders() {
const folders = await this.folderService.getAllDecrypted();
console.log(JSON.stringify(folders));
const res = new ListResponse(folders.map((o) => new FolderResponse(o)));
return Response.success(res);
}
private async listCollections() {
const collections = await this.collectionService.getAllDecrypted();
console.log(JSON.stringify(collections));
const res = new ListResponse(collections.map((o) => new CollectionResponse(o)));
return Response.success(res);
}
}