Currently, I am attempting to establish a function within Cloud Firestore that will activate whenever a new document is inserted into a specific collection. My intention is to achieve this using TypeScript because it supposedly simplifies working with asynchronous code. The provided JavaScript code functions as anticipated and triggers whenever a new document is added at the designated location:
//The JavaScript snippet below successfully activates
import * as functions from 'firebase-functions';
exports.waitReportCreatedJS = functions.firestore
.document('merchant_locations/{merchantId}/wait_period/{waitId}')
.onCreate((snapshot, context) => {
console.log('WaitReportCreated has been triggered');
const merchantId = context.params.merchantId;
const waitId = context.params.waitId;
console.log(`New wait recorded: ${waitId} at ${merchantId}`);
return snapshot.ref.update({ waitId: waitId });
});
However, when I attempt to replicate the same behavior using TypeScript, it fails to trigger - no action occurs when adding the document:
//On the other hand, this TypeScript code does not appear to trigger at all
import * as functions from 'firebase-functions';
export const waitReportCreatedTS = functions.database
.ref('merchant_locations/{merchantId}/wait_period/{waitId}')
.onCreate((snapshot, context) => {
console.log('WaitReportCreated has been triggered');
const merchantId = context.params.merchantId;
const waitId = context.params.waitId;
console.log(`New wait recorded: ${waitId} at ${merchantId}`);
return snapshot.ref.update({ waitId: waitId });
})
Given my lack of experience in Firestore functions, I am completely clueless as to what I might be doing incorrectly. Any assistance or guidance you could provide would be greatly appreciated. Thank you.