-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudFunctions.js
48 lines (43 loc) · 1.1 KB
/
cloudFunctions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.surveyComplete = functions.https.onCall(async (data, context) => {
// uuid of user who completed survey
const uuid = context.auth.uid;
await admin
.firestore()
.collection("users")
.doc(uuid)
.collection("coupons")
.add({
code: "SURVEY",
title: "Get 20% off",
description: "Thanks for completing a survey",
});
});
exports.redeemReferral = functions.https.onCall(async (data, context) => {
// uuid of user
const uuid = context.auth.uid;
// uuid as coupon code
const referrer = data.code;
await admin
.firestore()
.collection("users")
.doc(uuid)
.collection("coupons")
.add({
code: "NEWUSER",
title: "Get 30% off",
description: "Welcome to Cube Stop",
});
await admin
.firestore()
.collection("users")
.doc(referrer)
.collection("coupons")
.add({
code: "REFERRER",
title: "Get 10% off",
description: "Thanks for bringing new users to Cube Stop",
});
});