Skip to content

Instantly share code, notes, and snippets.

@bchiang7
Last active November 12, 2019 18:26
Show Gist options
  • Save bchiang7/f8b135e58f6e87d96c624f8e696c73a8 to your computer and use it in GitHub Desktop.
Save bchiang7/f8b135e58f6e87d96c624f8e696c73a8 to your computer and use it in GitHub Desktop.
// 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),
...
};
}
// Collection name found in firestore
static collectionName() { return 'users'; }
// Saves new user to Firestore with the same ID used with Firebase auth
async create() {
if (!this.id) {
throw new Error('Users must have an id assigned by firebase');
}
const fields = this.fields;
return firestore.collection(this.collectionName).doc(this.id).set(fields);
}
static async register(userParams) {
...
}
static async deleteUserById(id) {
...
}
...
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment