From 94ade6f6fefe4231cfe078d1117b4e7e7af221f9 Mon Sep 17 00:00:00 2001 From: gaba Date: Wed, 2 Nov 2016 13:44:05 -0700 Subject: [PATCH] Renames to userProfile, change name to displayname. Changes objectid for uuid. --- models/action.js | 35 +++++++++++++++++++++++++++++++++++ models/user.js | 39 ++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 models/action.js diff --git a/models/action.js b/models/action.js new file mode 100644 index 000000000..139ec2cff --- /dev/null +++ b/models/action.js @@ -0,0 +1,35 @@ +'use strict'; + +const mongoose = require('../mongoose'); +const uuid = require('uuid'); +const Schema = mongoose.Schema; + +const ActionSchema = new Schema({ + id: { + type: String, + default: uuid.v4, + unique: true + }, + action_type: String, + item_type: String, + item_id: String, + user_id: String +},{ + _id: false, + timestamps: { + createdAt: 'created_at', + updatedAt: 'updated_at' + } +}); + +/** + * Finds an action by the id. + * @param {String} id identifier of the action (uuid) +*/ +ActionSchema.methods.findById = function(id) { + return Action.findOne({id}); +}; + +const Action = mongoose.model('Action', ActionSchema); + +module.exports = Action; diff --git a/models/user.js b/models/user.js index 56cc476d0..d6b174075 100644 --- a/models/user.js +++ b/models/user.js @@ -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;