diff --git a/libs/common/src/abstractions/api.service.ts b/libs/common/src/abstractions/api.service.ts index afca5b63703..8a87d33a589 100644 --- a/libs/common/src/abstractions/api.service.ts +++ b/libs/common/src/abstractions/api.service.ts @@ -92,6 +92,7 @@ import { CipherRequest } from "../vault/models/request/cipher.request"; import { AttachmentUploadDataResponse } from "../vault/models/response/attachment-upload-data.response"; import { AttachmentResponse } from "../vault/models/response/attachment.response"; import { CipherMiniResponse, CipherResponse } from "../vault/models/response/cipher.response"; +import { DeleteAttachmentResponse } from "../vault/models/response/delete-attachment.response"; import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response"; /** @@ -243,8 +244,14 @@ export abstract class ApiService { id: string, request: AttachmentRequest, ): Promise; - abstract deleteCipherAttachment(id: string, attachmentId: string): Promise; - abstract deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise; + abstract deleteCipherAttachment( + id: string, + attachmentId: string, + ): Promise; + abstract deleteCipherAttachmentAdmin( + id: string, + attachmentId: string, + ): Promise; abstract postShareCipherAttachment( id: string, attachmentId: string, diff --git a/libs/common/src/services/api.service.ts b/libs/common/src/services/api.service.ts index 33e251f6411..8b50f14004d 100644 --- a/libs/common/src/services/api.service.ts +++ b/libs/common/src/services/api.service.ts @@ -115,6 +115,7 @@ import { CipherRequest } from "../vault/models/request/cipher.request"; import { AttachmentUploadDataResponse } from "../vault/models/response/attachment-upload-data.response"; import { AttachmentResponse } from "../vault/models/response/attachment.response"; import { CipherResponse } from "../vault/models/response/cipher.response"; +import { DeleteAttachmentResponse } from "../vault/models/response/delete-attachment.response"; import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response"; import { InsecureUrlNotAllowedError } from "./api-errors"; @@ -590,18 +591,32 @@ export class ApiService implements ApiServiceAbstraction { return new AttachmentUploadDataResponse(r); } - deleteCipherAttachment(id: string, attachmentId: string): Promise { - return this.send("DELETE", "/ciphers/" + id + "/attachment/" + attachmentId, null, true, true); + async deleteCipherAttachment( + id: string, + attachmentId: string, + ): Promise { + const r = await this.send( + "DELETE", + "/ciphers/" + id + "/attachment/" + attachmentId, + null, + true, + true, + ); + return new DeleteAttachmentResponse(r); } - deleteCipherAttachmentAdmin(id: string, attachmentId: string): Promise { - return this.send( + async deleteCipherAttachmentAdmin( + id: string, + attachmentId: string, + ): Promise { + const r = await this.send( "DELETE", "/ciphers/" + id + "/attachment/" + attachmentId + "/admin", null, true, true, ); + return new DeleteAttachmentResponse(r); } postShareCipherAttachment( diff --git a/libs/common/src/vault/models/response/delete-attachment.response.ts b/libs/common/src/vault/models/response/delete-attachment.response.ts new file mode 100644 index 00000000000..ae645fdf315 --- /dev/null +++ b/libs/common/src/vault/models/response/delete-attachment.response.ts @@ -0,0 +1,12 @@ +import { BaseResponse } from "../../../models/response/base.response"; + +import { CipherResponse } from "./cipher.response"; + +export class DeleteAttachmentResponse extends BaseResponse { + cipher: CipherResponse; + + constructor(response: any) { + super(response); + this.cipher = new CipherResponse(this.getResponseProperty("Cipher")); + } +} diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index e4c4f892b4a..70d2458cff2 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -77,6 +77,7 @@ import { CipherShareRequest } from "../models/request/cipher-share.request"; import { CipherWithIdRequest } from "../models/request/cipher-with-id.request"; import { CipherRequest } from "../models/request/cipher.request"; import { CipherResponse } from "../models/response/cipher.response"; +import { DeleteAttachmentResponse } from "../models/response/delete-attachment.response"; import { AttachmentView } from "../models/view/attachment.view"; import { CipherView } from "../models/view/cipher.view"; import { FieldView } from "../models/view/field.view"; @@ -1482,16 +1483,16 @@ export class CipherService implements CipherServiceAbstraction { userId: UserId, admin: boolean = false, ): Promise { - let cipherResponse = null; + let response: DeleteAttachmentResponse; try { - cipherResponse = admin + response = admin ? await this.apiService.deleteCipherAttachmentAdmin(id, attachmentId) : await this.apiService.deleteCipherAttachment(id, attachmentId); } catch (e) { return Promise.reject((e as ErrorResponse).getSingleMessage()); } - const cipherData = CipherData.fromJSON(cipherResponse?.cipher); + const cipherData = new CipherData(response.cipher); return await this.deleteAttachment(id, cipherData.revisionDate, attachmentId, userId); } diff --git a/libs/common/src/vault/services/file-upload/cipher-file-upload.service.ts b/libs/common/src/vault/services/file-upload/cipher-file-upload.service.ts index 8d97a921748..48b51f50178 100644 --- a/libs/common/src/vault/services/file-upload/cipher-file-upload.service.ts +++ b/libs/common/src/vault/services/file-upload/cipher-file-upload.service.ts @@ -93,12 +93,12 @@ export class CipherFileUploadService implements CipherFileUploadServiceAbstracti response: CipherResponse, uploadData: AttachmentUploadDataResponse, isAdmin: boolean, - ) { - return () => { + ): () => Promise { + return async () => { if (isAdmin) { - return this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId); + await this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId); } else { - return this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId); + await this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId); } }; }