addNewDevice(deviceId: string, fireId: string){
let Token: string;
let UserId: string;
let newlyAddedDevice: Device;
return this.authSrv.userId.pipe(take(1),
switchMap(
userId => {
UserId = userId;
return this.authSrv.token;
}
),take(1),
switchMap(
token => {
if(!UserId){
throw new Error('No user id found');
}
Token = token;
return this.http.get<DeviceData>(`https://....firebaseio.com/device/${fireId}.json?
auth=${token}`)
}
),
switchMap(
deviceData => {
if(!deviceData){
throw new Error('No Device Id found or Pass Id incorrect');
}
newlyAddedDevice = new Device(
fireId,
deviceData.deviceId,
deviceData.ver,
deviceData.slot,
UserId
);
this.http.put(`https://....firebaseio.com/device/${fireId}.json?auth=${Token}`,
{...newlyAddedDevice, id:null}
);
return this.devices;
}
)
);
}
Upon receiving data from the "get()" method, I noticed that the "put()" method is not updating my Firebase database, and no errors are being displayed. I attempted to debug using "console.log" to view the input data.
I utilized the following code as a reference point:
places => {
const upPlaceIndex = places.findIndex(pl => pl.id == placeId);
upPlace = [...places];
const oldPlace = upPlace[upPlaceIndex];
upPlace[upPlaceIndex] = new Place(.....);
return this.http.put(`https://....firebaseio.com/offers-places/${placeId}.json?
auth=${fetchToken}`,
{...upPlace[upPlaceIndex], id: null}
}
This code successfully worked in another project of mine.