This file contains hidden or 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
| // models/User.js | |
| class User extends Base { | |
| // Expected schema of the User record | |
| get schema() { | |
| return { | |
| id: Joi.string(), | |
| createdAt: Joi.string().isoDate(), | |
| displayName: Joi.string().allow('').allow(null).default(''), | |
| email: Joi.string().email({ minDomainSegments: 2 }).default(''), | |
| isAdmin: Joi.bool().default(false), |
This file contains hidden or 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
| /** | |
| * Fetches the session user from cache if it exists, or sets it if it does not | |
| */ | |
| const getOrSetUserFromCache = async headers => { | |
| const User = require('../models/User'); | |
| const userUid = headers['x-userid']; | |
| try { | |
| const firebaseUserUid = await User.getUserIdFromToken(headers.authorization); | |
| if (!userUid || firebaseUserUid !== userUid) { |
This file contains hidden or 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
| // Create a new User model instance | |
| const harryPotter = new User({ | |
| id: 'abc123', | |
| email: 'harry@hogwarts.com', | |
| displayName: 'The Boy Who Lived', | |
| ... | |
| }); | |
| // Add it as a document in the `users` collection in Firestore | |
| harryPotter.create(); |
This file contains hidden or 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
| // Deletes a user by ID in firestore user collection & firebase auth | |
| static async deleteUserById(id) { | |
| const userRef = firestore | |
| .collection(this.collectionName()) | |
| .doc(id); | |
| const batch = firestore.batch(); | |
| batch.delete(userRef); | |
| const completedTasksToDelete = await firestore |
This file contains hidden or 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
| const User = require('../models/User.js'); | |
| await User.deleteUserById(id); |
This file contains hidden or 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
| // Example document in `completedTasks` collection | |
| { | |
| "completedAt": "2019-10-17T20:14:24.132Z", | |
| "expirationTimestamp": "2019-10-31T08:25:00.000Z", | |
| "userId": "xyz890", | |
| "taskId": "abc123", | |
| } |
This file contains hidden or 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
| #!/bin/bash | |
| bold=$(tput bold) | |
| normal=$(tput sgr0) | |
| set -e | |
| echo "-----------------------------------------------" | |
| echo " ๐ Creating a new release ๐" | |
| echo "-----------------------------------------------" |
This file contains hidden or 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
| // Inspired by Vue: https://alligator.io/vuejs/global-event-bus/ | |
| // Sending events: EventBus.emit('clicky', clickArg); | |
| // Receiving events: EventBus.on('clicky', clickArg => console.log(clickArg)); | |
| const EventBus = { | |
| events: {}, | |
| emit(event, data) { | |
| if (!this.events[event]) { | |
| return; | |
| } |
This file contains hidden or 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
| <?php | |
| if (! (defined('WP_CLI') && WP_CLI)) { | |
| return; | |
| } | |
| class Algolia_Command { | |
| public function reindex($args, $assoc_args) { | |
| ... | |
| } | |
This file contains hidden or 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
| <?php | |
| public function reindex($args, $assoc_args) { | |
| // Init global index | |
| $index = $algolia->initIndex('global_search'); | |
| // Clear all objects in the index | |
| $index->clearObjects()->wait(); | |
| // Get all blog IDs in multisite network |