1import * as functions from 'firebase-functions';
2import * as admin from 'firebase-admin';
3
4admin.initializeApp();
5
6export const resetCounter = functions.https.onRequest((req, res) => {
7 const resetRef = admin.firestore()
8 .collection('collectionName')
9 .doc('documentName')
10 resetRef.get().then((doc) => {
11 if(doc.exists){
12 resetRef.update({counter: 0})
13 .catch(err => {
14 console.log("Error",err)
15 res.send("500");
16 })
17 }
18 }).catch(err=>{
19 //Internal server error
20 console.log("Error",err)
21 res.send("500");
22 });
23 //Successful operation
24 res.send("200");
25});
1import * as functions from 'firebase-functions';
2import * as admin from 'firebase-admin';
3
4admin.initializeApp();
5
6export const setProductsToExpired = functions.https.onRequest(async(request, response) => {
7 const expiredProducts = await admin.firestore()
8 .collection('products')
9 .where('timestamp','<=', admin.firestore.Timestamp.now())
10 .get();
11
12 const batch = admin.firestore().batch();
13
14 expiredProducts.forEach(doc => {
15 batch.update(doc.ref,'expired',true);
16 });
17
18 await batch.commit();
19 //Successful operation
20 response.send("200");
21 });