Issue:
core.mjs:10132 ERROR TypeError: block.getDepartment is not a function
at FirebaseService.mapDatabaseToBlock (firebase.service.ts:54:30)
at firebase.service.ts:45:60
at Array.map (<anonymous>)
at firebase.service.ts:45:42
at map.js:7:37
at OperatorSubscriber._next (OperatorSubscriber.js:13:21)
at OperatorSubscriber.next (Subscriber.js:31:18)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:16)
at SafeSubscriber.next (Subscriber.js:122:22)
at Subscriber._next (Subscriber.js:72:26)
Code snippet in firebase-service.ts:
retrieveAllBlocks() {
const blocksRef: AngularFireList<any> = this.db.list('blocks');
this.blocksData = blocksRef.valueChanges().pipe(
map((blocks: any[]) => {
const transformedBlocks = blocks.map(block => this.mapDatabaseToBlock(block)); //<-----
this._blocks = transformedBlocks;
return transformedBlocks;
})
);
}
mapDatabaseToBlock(block: Block): Block {
const department = block.getDepartment(); //<------ ERROR
const reorderedData = {
department: block.department,
description: department.description,
hash: block.hash,
id: department.id,
message: block.message,
};
Code snippet in block.ts:
getDepartment(): Department {
return this.department;
}
I am attempting to save an object in the firebase real-time database. Due to reordering of fields there, I need to make these adjustments. However, I am encountering the mentioned error.