Quiero modificar esta función para enviar estos dos identificadores de archivo en solicitudes separadas:
return this.upload(myForm).pipe( take(1), switchMap(res => { body.user.profilePic = res.data.profilePic; body.user.coverPic = res.data.coverPic; return this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body); }) );
¿Debo usar mapa plano?
Puede hacer solicitudes separadas de una tubería como esa:
return this.upload(myForm).pipe( take(1), switchMap(res => { body.user.profilePic = res.data.profilePic; body.user.coverPic = res.data.coverPic; return [ this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), ] }), mergeAll(), );
El operador correcto depende de si desea enviar las dos solicitudes en paralelo o consecutivamente.
Si ya tiene take(1)
, puede usar switchMap
o mergeMap
porque siempre se emitirá solo una vez y, por lo tanto, no importa en este caso.
Envío de solicitudes en paralelo:
return this.upload(myForm).pipe( take(1), switchMap(res => { ... return forkJoin([ this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), ]); }), );
Envío de solicitudes en secuencia:
return this.upload(myForm).pipe( take(1), switchMap(res => { ... return concat( this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), this.http.post<IRresponse<object>>(environment.api + EndPoint.CreateUser, body), ); }), );