mirror of
https://github.com/wassname/talk.git
synced 2026-08-15 12:55:10 +08:00
Renames to userProfile, change name to displayname. Changes objectid for uuid.
This commit is contained in:
+16
-23
@@ -4,41 +4,34 @@ const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const UserSchema = new Schema({
|
||||
const UserProfileSchema = new Schema({
|
||||
id: {
|
||||
type: String,
|
||||
default: uuid.v4,
|
||||
unique: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
unique: true
|
||||
},
|
||||
created_at: { type: Date, default: Date.now },
|
||||
updated_at: { type: Date, default: Date.now }
|
||||
display_name: String,
|
||||
auth_user_id: String
|
||||
},{
|
||||
_id: false
|
||||
_id: false,
|
||||
timestamps: {
|
||||
createdAt: 'created_at',
|
||||
updatedAt: 'updated_at'
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Finds a user by the id.
|
||||
* @param {String} id identifier of the user (uuid)
|
||||
*/
|
||||
UserSchema.methods.findById = function(id, done) {
|
||||
User.findOne({
|
||||
id : id
|
||||
}, (err, user) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return done(null, false);
|
||||
}
|
||||
return done(null, user);
|
||||
});
|
||||
UserProfileSchema.statics.findById = function(id) {
|
||||
return UserProfile.findOne({id});
|
||||
};
|
||||
|
||||
const User = mongoose.model('User', UserSchema);
|
||||
// TO DO: methods
|
||||
// modifications to user as statics
|
||||
// find by auth user id
|
||||
|
||||
module.exports = User;
|
||||
const UserProfile = mongoose.model('UserProfile', UserProfileSchema);
|
||||
|
||||
module.exports = UserProfile;
|
||||
|
||||
Reference in New Issue
Block a user