📅  最后修改于: 2022-03-11 14:48:24.993000             🧑  作者: Mango
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
export const setProductsToExpired = functions.https.onRequest(async(request, response) => {
const expiredProducts = await admin.firestore()
.collection('products')
.where('timestamp','<=', admin.firestore.Timestamp.now())
.get();
const batch = admin.firestore().batch();
expiredProducts.forEach(doc => {
batch.update(doc.ref,'expired',true);
});
await batch.commit();
//Successful operation
response.send("200");
});