@edgedev/firebase 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/functions.js +35 -0
package/package.json
CHANGED
package/src/functions.js
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
1
|
// START @edge/firebase functions
|
|
2
|
+
|
|
3
|
+
exports.initFirestore = functions.https.onCall(async (data, context) => {
|
|
4
|
+
// checks to see of the collections 'collection-data' and 'staged-users' exist if not will seed them with data
|
|
5
|
+
const collectionData = await db.collection('collection-data').get()
|
|
6
|
+
const stagedUsers = await db.collection('staged-users').get()
|
|
7
|
+
if (collectionData.empty) {
|
|
8
|
+
// create a document with the id of '-' and one called '-default-':
|
|
9
|
+
const admin = { assign: true, delete: true, read: true, write: true }
|
|
10
|
+
const editor = { assign: false, delete: true, read: true, write: true }
|
|
11
|
+
const writer = { assign: false, delete: false, read: true, write: true }
|
|
12
|
+
const user = { assign: false, delete: false, read: true, write: false }
|
|
13
|
+
await db.collection('collection-data').doc('-').set({ admin, editor, writer, user })
|
|
14
|
+
await db.collection('collection-data').doc('-default-').set({ admin, editor, writer, user })
|
|
15
|
+
}
|
|
16
|
+
if (stagedUsers.empty) {
|
|
17
|
+
const templateUser = {
|
|
18
|
+
docId: 'organization-registration-template',
|
|
19
|
+
isTemplate: true,
|
|
20
|
+
meta: {
|
|
21
|
+
name: 'Organization Registration Template',
|
|
22
|
+
},
|
|
23
|
+
subCreate: {
|
|
24
|
+
documentStructure: {
|
|
25
|
+
name: '',
|
|
26
|
+
},
|
|
27
|
+
dynamicDocumentField: 'name',
|
|
28
|
+
role: 'admin',
|
|
29
|
+
rootPath: 'organizations',
|
|
30
|
+
},
|
|
31
|
+
userId: '',
|
|
32
|
+
}
|
|
33
|
+
await db.collection('staged-users').doc('organization-registration-template').set(templateUser)
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
2
37
|
exports.removeNonRegisteredUser = functions.https.onCall(async (data, context) => {
|
|
3
38
|
if (data.uid === context.auth.uid) {
|
|
4
39
|
const stagedUser = await db.collection('staged-users').doc(data.docId).get()
|