Last active
November 12, 2019 18:26
-
-
Save bchiang7/f8b135e58f6e87d96c624f8e696c73a8 to your computer and use it in GitHub Desktop.
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), | |
... | |
}; | |
} | |
// 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