I am trying to perform a series of chained operations on a database where the starting point is a set of entities that I loop through and for each one I have to execute 3 calls to a service that accesses the database
estudiarConcursos() {
of(...this.data.data.filter(d => d.estudiar == 'Sí'))
.pipe(
concatMap(
concurso=>this.dataServiceConcursos.ConcursoEstudiar(concurso)
),
concatMap(
data => this.dataServiceOfertas.postOferta(this.ConvertirConcursoEnOferta(data))
),
concatMap(
data =>
this.dataServiceConcursos.asociarOferta({
concurso: this.concursoTratado,
oferta: data
})
)
)
.subscribe(console.log)
}
For each iterated concurso I have to do 3 things
- Update your field Estudiar
- Create an associated oferta
- Update your ofertaId field with the ID of the newly created oferta
And my problem is that in the third concatMap I need to access the concurso that is iterating but in data I receive the result of the previous concatMap, that is, the recently created oferta and I don't know how to access the value of the contest with which everything starts
Any idea, please?
Thanks