I have an axios post call that seems to be working find. The data is showing in console log fine and there are no errors in our Firebase functions log. However, we aren't returning the response object. The pubsub function finishes and moves onto the next doc. Any ideas on what I'm doing wrong? Code posted below.
exports.updateAllPayrollIds = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
return admin.firestore().collection('PS').orderBy("userId", "asc").startAt(1000)
.get()
.then(snapshot => {
snapshot.forEach(doc => {
let EncryptedSSN = doc.data().ssn
let decryptSSN = CryptoJS.AES.decrypt(EncryptedSSN, '###########')
var ssn = decryptSSN.toString(CryptoJS.enc.Utf8)
var clientId = "###"
let docId = doc.data().id
axiosInstance.request({
url: 'https://apihost/getEmployeeBySSN',
method: 'post',
data: {ssn, clientId},
})
.then(response => {
const data = response.data.employee.id;
console.log('data', data);
return admin.firestore().collection('PS').doc(docId).update({
payrollId: data
})
}).catch(error => {
console.log('getEmployeeBySSN error', error)
})
})
})
.catch(err => {
console.log(err);
})
})