Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes required for signup flow #62

Merged
merged 8 commits into from Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/services/user/hooks/index.js
Expand Up @@ -81,11 +81,19 @@ const _resolvePermissions = (owner, {roleService, processedRoles = []}) => {
};


const getDisplayName = (user = {}) => {
// TODO: implement fallback to username and protect teacher
return user.lastName ? user.lastName : user._id;
};


exports.after = {
all: [hooks.remove('password')],
find: [(hook) => {
hook.result = hook.result.constructor.name === 'model' ? hook.result.toObject() : hook.result;

hook.result.displayName = getDisplayName(hook.result);

return resolvePermissions(hook.result, hook.app).then((permissions) => {
hook.result.permissions = permissions;
return hook;
Expand All @@ -95,6 +103,8 @@ exports.after = {
(hook) => {
hook.result = hook.result.constructor.name === 'model' ? hook.result.toObject() : hook.result;

hook.result.displayName = getDisplayName(hook.result);

return resolvePermissions(hook.result, hook.app).then((permissions) => {
hook.result.permissions = permissions;
return hook;
Expand Down
10 changes: 5 additions & 5 deletions src/services/user/model.js
Expand Up @@ -6,14 +6,14 @@ const Schema = mongoose.Schema;
const userSchema = new Schema({
roles: [{type: Schema.Types.ObjectId, ref: 'role'}],
accounts: [{type: Schema.Types.ObjectId, ref: 'account'}],
email: {type: String, required: true},

schoolId: {type: Schema.Types.ObjectId, ref: 'school'},
schoolId: {type: Schema.Types.ObjectId, ref: 'school', required: true},

firstName: {type: String},
lastName: {type: String},
userName: {type: String},
firstName: {type: String, required: true},
lastName: {type: String, required: true},

birthday: {type: Date}
system: {type: Object} // blackbox for frontend stuff like "cookies accepted"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the reason for this, let's talk about it

},{
timestamps: true
});
Expand Down