submit to this collection

This commit is contained in:
Ben Bosman
2020-01-08 17:41:29 +01:00
parent 4b67dbf10f
commit feced9f893
6 changed files with 49 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ErrorResponse, RestResponse, SubmissionSuccessResponse } from '../cache/response.models';
import { getResponseFromEntry } from '../shared/operators';
import {URLCombiner} from '../url-combiner/url-combiner';
/**
* The service handling all submission REST requests
@@ -65,9 +66,15 @@ export class SubmissionRestService {
* The base endpoint for the type of object
* @param resourceID
* The identifier for the object
* @param collectionId
* The owning collection for the object
*/
protected getEndpointByIDHref(endpoint, resourceID): string {
return isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
protected getEndpointByIDHref(endpoint, resourceID, collectionId?: string): string {
let url = isNotEmpty(resourceID) ? `${endpoint}/${resourceID}` : `${endpoint}`;
if (collectionId) {
url = new URLCombiner(url, '?owningCollection=' + collectionId).toString();
}
return url;
}
/**
@@ -130,12 +137,14 @@ export class SubmissionRestService {
* The [HttpOptions] object
* @return Observable<SubmitDataResponseDefinitionObject>
* server response
* @param collectionId
* The owning collection id
*/
public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions): Observable<SubmitDataResponseDefinitionObject> {
public postToEndpoint(linkName: string, body: any, scopeId?: string, options?: HttpOptions, collectionId?: string): Observable<SubmitDataResponseDefinitionObject> {
const requestId = this.requestService.generateRequestId();
return this.halService.getEndpoint(linkName).pipe(
filter((href: string) => isNotEmpty(href)),
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId)),
map((endpointURL: string) => this.getEndpointByIDHref(endpointURL, scopeId, collectionId)),
distinctUntilChanged(),
map((endpointURL: string) => new SubmissionPostRequest(requestId, endpointURL, body, options)),
tap((request: PostRequest) => this.requestService.configure(request)),