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

Username only updated on first address and when there is 1 address #2932

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions server/methods/accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ export function addressBookAdd(address, accountUserId) {
this.unblock();

const userId = accountUserId || Meteor.userId();
const account = Accounts.findOne({
userId: userId
});
// required default id
if (!address._id) {
address._id = Random.id();
Expand Down Expand Up @@ -356,24 +359,30 @@ export function addressBookAdd(address, accountUserId) {
}
}

Meteor.users.update(Meteor.userId(), {
const userUpdateQuery = {
$set: {
"name": address.fullName,
"profile.addressBook": address
}
});

return Accounts.upsert({
userId: userId
}, {
};
const accountsUpdateQuery = {
$set: {
name: address.fullName,
userId: userId
},
$addToSet: {
"profile.addressBook": address
}
});
};

if (!account.name || _.get(account, 'profile.addressBook.length', 0) === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Double quotes on strings.

userUpdateQuery.$set.name = address.fullName;
accountsUpdateQuery.$set.name = address.fullName;
}

Meteor.users.update(Meteor.userId(), userUpdateQuery);

return Accounts.upsert({
userId: userId
}, accountsUpdateQuery);
}

/**
Expand Down Expand Up @@ -469,22 +478,29 @@ export function addressBookUpdate(address, accountUserId, type) {
}
}

Meteor.users.update(Meteor.userId(), {
const userUpdateQuery = {
$set: {
"name": address.fullName,
"profile.addressBook": address
}
});
};

return Accounts.update({
"userId": userId,
"profile.addressBook._id": address._id
}, {
const accountsUpdateQuery = {
$set: {
"name": address.fullName,
"profile.addressBook.$": address
}
});
};
// update the name when there is no name or the user updated his only shipping address
if (!account.name || _.get(account, 'profile.addressBook.length', 0) <= 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Double quotes.

userUpdateQuery.$set.name = address.fullName;
accountsUpdateQuery.$set.name = address.fullName;
}

Meteor.users.update(Meteor.userId(), userUpdateQuery);

return Accounts.update({
"userId": userId,
"profile.addressBook._id": address._id
}, accountsUpdateQuery);
}

/**
Expand Down