-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
61 lines (52 loc) · 2.11 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
const admin = require('firebase-admin');
const environment = require('./environments/environment.json');
const functions = require('firebase-functions');
admin.initializeApp();
const {
NotesOnUpdate,
ThumbnailsOnFinalize,
ThumbnailsOnDelete,
UploadsOnFinalize,
UploadsOnDelete,
UserTokensOnCreate,
} = require('./src');
const context = { admin, environment };
/*
CHALLENGE Functions 06
- Read and understand the following code carefully.
We're using a dependency injection pattern, because our functions must be 100% testable.
Our dependencies are the `admin` and `environment` variables which are combined into `context`.
Each function is a higher-order function that returns the actual function that Cloud Functions
will run. The higher-order function takes all of the context that the inner function needs.
So UploadsOnFinalize needs a context object that looks like { admin, environment }.
It can then return uploadsOnFinalize, which is the fully-initialized function that we'll
pass to Cloud Functions with the .onFinalize method.
*/
// thumbnails-on-delete
const notesOnUpdate = NotesOnUpdate(context);
exports.notesOnUpdate = functions.firestore
.document('notes/{noteId}')
.onUpdate(notesOnUpdate);
// thumbnails-on-delete
const thumbnailsOnDelete = ThumbnailsOnDelete(context);
exports.thumbnailsOnDelete = functions.storage
.object()
.onDelete(thumbnailsOnDelete);
// thumbnails-on-finalize
const thumbnailsOnFinalize = ThumbnailsOnFinalize(context);
exports.thumbnailsOnFinalize = functions.storage
.object()
.onFinalize(thumbnailsOnFinalize);
// uploads-on-finalize
const uploadsOnFinalize = UploadsOnFinalize(context);
exports.uploadsOnFinalize = functions.storage
.object()
.onFinalize(uploadsOnFinalize);
// uploads-on-delete
const uploadsOnDelete = UploadsOnDelete(context);
exports.uploadsOnDelete = functions.storage.object().onDelete(uploadsOnDelete);
// user-tokens-on-create
const userTokensOnCreate = UserTokensOnCreate(context);
exports.userTokensOnCreate = functions.database
.ref('{environment}/userWriteable/userTokens/{uid}')
.onCreate(userTokensOnCreate);