// dispute-docs-data.service.ts - Сервис, который используется для загрузки formData моего документа в бэкэнд
add(formData): Observable<DisputeDocument> {
const {document: documentUrl} = environment.backend.endpoints;
return this.http.post(`${this.rootUrl}${documentUrl}`, formData,
{reportProgress: true, observe: 'events'})
.pipe(
map((event: HttpEvent<any>) => {
if (event.type === HttpEventType.Response) {
const dispute = {
core: formData.get('core'),
dispute_docs: [event.body]
};
// You can think that this fn formats the data in a required format and returns an array of objects; we need to return the first one
const formattedDisputeDocs = formatDisputesDocs(dispute);
return formattedDisputeDocs[0];
}
})
);
}
// component.ts - компонент документа подписывается выше method
private uploadFile(formData) {
const postDocSubs = this.disputeDocsEntityService.add(formData)
.subscribe(res => {
this.dialogRef.close();
},
((err) => {
if (err.status === 415) {
this.toastrService
.error('Please verify the format of the file; .txt/.doc/.pdf/.png/.jpeg are only accepted',
`Error! - ${err.statusText.toLowerCase()}`);
} else {
this.toastrService.error('Failed to upload the file...', 'Error!');
}
this.trackFileUploadProgress({type: null});
}));
this.subscriptionArr.add(postDocSubs);
}
the backend response structure is : {
"msg": "successful",
"document": {blob_id: 123, "mime_type": "pdf", file_name: "test", received_dt: ""}
}
Ниже приведена ошибка, которую я вижу в консоли браузера:
data. js: 6513 Ошибка: DisputeDocs EntityAction guard for "[DisputeDocs] @ ngrx / data / save / add-one / success ": полезная нагрузка должна иметь одну сущность.
at EntityActionGuard.throwError (data.js:301)
at EntityActionGuard.mustBeEntity (data.js:108)
at EntityCollectionReducerMethods.saveAddOneSuccess (data.js:5173)
at entityCollectionReducer (data.js:6010)
at EntityCacheReducerFactory.applyCollectionReducer (data.js:6442)
at EntityCacheReducerFactory.entityCacheReducer (data.js:6166)
at store.js:412
at combination (store.js:300)
at store.js:1171
at store.js:1117
error @ data. js: 6513
applyCollectionReducer @ data. js: 6446
entityCacheReducer @ data. js: 6166
(аноним) @ store. js: 412
комбинация @ store. js: 300
(анонимный) @ store. js: 1171
(анонимный) @ store. js: 1117
(анонимный) @ store. js: 380
computeNextEntry @ store-devtools. js: 686
RecomputeStates @ store-devtools. js: 739
(анонимный) @ store-devtools. js: 1087
StoreDevtools .liftedAction $ .pipe.Object.state @ store-devtools. js: 1139