public submit(data: StopGroupWithStopPoint): void {
console.log('Service submit data', data);
const stopGroup = this.createStopGroupFromSGWSP(data);
// await this.$updateStopGroup(stopGroup).toPromise(); // Flavien Stuff
this.$updateStopGroup(stopGroup).pipe(first()).subscribe();
zip(...this.$bindStopPointsToStopGroup(data.id, data.stop_points)).pipe(first()).subscribe();
}
private $bindStopPointsToStopGroup(stopGroupId: string, stopPoints: StopPoint[]): Observable<CustomResponse>[] {
return (stopPoints.map((stopPoint) => this.$bindStopPointToStopGroup(stopGroupId, stopPoint)));
}
private $bindStopPointToStopGroup(stopGroupId: string, stopPoint: StopPoint): Observable<CustomResponse> {
const params = {
stop_point: stopPoint.id,
stop_group: stopGroupId
};
return this.getWithSid<CustomResponse>(this.baseUrl + this.setStopGroupsEndpoint, {...params});
}