1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-29 07:59:42 +01:00

return new/edited object for create/edit

This commit is contained in:
Kyle Spearrin 2018-05-19 14:53:28 -04:00
parent 79ef15c48f
commit 2ff868aeb3
2 changed files with 24 additions and 6 deletions

View File

@ -8,7 +8,8 @@ import { FolderService } from 'jslib/abstractions/folder.service';
import { TokenService } from 'jslib/abstractions/token.service'; import { TokenService } from 'jslib/abstractions/token.service';
import { Response } from '../models/response'; import { Response } from '../models/response';
import { StringResponse } from '../models/response/stringResponse'; import { CipherResponse } from '../models/response/cipherResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { Cipher } from '../models/cipher'; import { Cipher } from '../models/cipher';
import { Folder } from '../models/folder'; import { Folder } from '../models/folder';
@ -54,7 +55,10 @@ export class CreateCommand {
const cipher = await this.cipherService.encrypt(Cipher.toView(req)); const cipher = await this.cipherService.encrypt(Cipher.toView(req));
try { try {
await this.cipherService.saveWithServer(cipher); await this.cipherService.saveWithServer(cipher);
return Response.success(new StringResponse(cipher.id)); const newCipher = await this.cipherService.get(cipher.id);
const decCipher = await newCipher.decrypt();
const res = new CipherResponse(decCipher);
return Response.success(res);
} catch (e) { } catch (e) {
return Response.error(e); return Response.error(e);
} }
@ -92,7 +96,10 @@ export class CreateCommand {
const fileBuf = fs.readFileSync(filePath); const fileBuf = fs.readFileSync(filePath);
await this.cipherService.saveAttachmentRawWithServer(cipher, path.basename(filePath), await this.cipherService.saveAttachmentRawWithServer(cipher, path.basename(filePath),
new Uint8Array(fileBuf).buffer); new Uint8Array(fileBuf).buffer);
return Response.success(); const updatedCipher = await this.cipherService.get(cipher.id);
const decCipher = await updatedCipher.decrypt();
const res = new CipherResponse(decCipher);
return Response.success(res);
} catch (e) { } catch (e) {
return Response.error(e); return Response.error(e);
} }
@ -102,7 +109,10 @@ export class CreateCommand {
const folder = await this.folderService.encrypt(Folder.toView(req)); const folder = await this.folderService.encrypt(Folder.toView(req));
try { try {
await this.folderService.saveWithServer(folder); await this.folderService.saveWithServer(folder);
return Response.success(new StringResponse(folder.id)); const newFolder = await this.folderService.get(folder.id);
const decFolder = await newFolder.decrypt();
const res = new FolderResponse(decFolder);
return Response.success(res);
} catch (e) { } catch (e) {
return Response.error(e); return Response.error(e);
} }

View File

@ -4,6 +4,8 @@ import { CipherService } from 'jslib/abstractions/cipher.service';
import { FolderService } from 'jslib/services/folder.service'; import { FolderService } from 'jslib/services/folder.service';
import { Response } from '../models/response'; import { Response } from '../models/response';
import { CipherResponse } from '../models/response/cipherResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { Cipher } from '../models/cipher'; import { Cipher } from '../models/cipher';
import { Folder } from '../models/folder'; import { Folder } from '../models/folder';
@ -55,7 +57,10 @@ export class EditCommand {
const encCipher = await this.cipherService.encrypt(cipherView); const encCipher = await this.cipherService.encrypt(cipherView);
try { try {
await this.cipherService.saveWithServer(encCipher); await this.cipherService.saveWithServer(encCipher);
return Response.success(); const updatedCipher = await this.cipherService.get(cipher.id);
const decCipher = await updatedCipher.decrypt();
const res = new CipherResponse(decCipher);
return Response.success(res);
} catch (e) { } catch (e) {
return Response.error(e); return Response.error(e);
} }
@ -72,7 +77,10 @@ export class EditCommand {
const encFolder = await this.folderService.encrypt(folderView); const encFolder = await this.folderService.encrypt(folderView);
try { try {
await this.folderService.saveWithServer(encFolder); await this.folderService.saveWithServer(encFolder);
return Response.success(); const updatedFolder = await this.folderService.get(folder.id);
const decFolder = await updatedFolder.decrypt();
const res = new FolderResponse(decFolder);
return Response.success(res);
} catch (e) { } catch (e) {
return Response.error(e); return Response.error(e);
} }