In my code, I am fetching Requisition
data from an external system using the following approach:
init() {
const requisitionData = this.loginMb().pipe(
map(response => response.data.token),
switchMap(loginData => this.getRequisitions(loginData)),
map(response => response.data),
);
requisitionData.subscribe(this.processData);
}
This is the processData()
function:
processData(response: any) {
const requisitions = response.content.data;
for (const p of requisitions) {
const req = new Requisition(); // Requisition is the TypeORM entity
req.title = p.title;
req.reference = p.reference;
// other fields
this.repo.save(requisition);
}
Below is the constructor:
@Injectable()
export class RequisitionSync {
constructor(
@InjectRepository(Requisition) private readonly repo: Repository<Requisition>,
private readonly httpService: HttpService,
) {}
The issue I am encountering is that within the processData()
function, this.repo
is becoming undefined
. Interestingly, if I output console.log(this.repo)
within the init()
function, it is not undefined
.