This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Haoran
committed
Apr 14, 2021
1 parent
37a63af
commit c94cc84
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const functions = require('firebase-functions') | ||
const admin = require('firebase-admin') | ||
|
||
exports.cleanInvitation = functions | ||
.region('europe-west1') | ||
.pubsub.schedule('0 15 * * *') | ||
.timeZone('Europe/Copenhagen') | ||
.onRun(() => { | ||
const last_8_dates = [...Array(8)].map((_, i) => { | ||
const day = new Date() | ||
day.setDate(day.getDate() - i) | ||
return day.toISOString().slice(0, 10) | ||
}) | ||
|
||
const query = admin | ||
.firestore() | ||
.collection('invitations') | ||
.where('date', 'not-in', last_8_dates) | ||
|
||
query.get().then((querySnapshot) => { | ||
querySnapshot.forEach((doc) => { | ||
doc.ref.delete() | ||
}) | ||
}) | ||
}) |