-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Feat #63 accounts language email #5171
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 from all commits
84ec3e7
1542e76
e37c469
82562cf
0157736
0f6b0b5
62a4ae5
766f321
7d1abbc
47a38af
45010d1
9140167
43b9c75
3706674
30ba9c7
e56e3f3
5e322e8
e285900
1a845f6
5fb7bea
1635406
3dd2e46
9faa6b3
75c1977
cd04f12
6230e58
db7c60b
5ec0d7d
916d7b2
2fdf126
cca2c5b
10bf8a6
9cddfb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { check, Match } from "meteor/check"; | ||
| import R from "ramda"; | ||
| import { Accounts, Shops } from "/lib/collections"; | ||
| import appEvents from "/imports/node-app/core/util/appEvents"; | ||
| import Reaction from "/imports/plugins/core/core/server/Reaction"; | ||
| import ReactionError from "@reactioncommerce/reaction-error"; | ||
|
|
||
| /** | ||
| * @name accounts/setProfileLanguage | ||
| * @memberof Accounts/Methods | ||
| * @method | ||
| * @param {String} languageCode - i18n language code | ||
| * @param {String} [accountId] - accountId of user to set language of. Defaults to current user ID | ||
| * @summary Sets users profile language | ||
| * @returns {Object} Account document | ||
| */ | ||
| export default function setProfileLanguage(languageCode, accountId) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to a non-Meteor mutation function in |
||
| check(languageCode, String); | ||
| check(accountId, Match.Maybe(String)); | ||
|
|
||
| const currentUserId = this.userId; | ||
| const userId = accountId || currentUserId; | ||
| if (!userId) throw new ReactionError("access-denied", "You must be logged in to set profile language"); | ||
|
|
||
| const account = Accounts.findOne({ userId }, { fields: { shopId: 1 } }); | ||
| if (!account) throw new ReactionError("not-found", "Account not found"); | ||
|
|
||
| if (userId !== currentUserId && !Reaction.hasPermission("reaction-accounts", currentUserId, account.shopId)) { | ||
| throw new ReactionError("access-denied", "Access denied"); | ||
| } | ||
|
|
||
| // first search for shop based on account id | ||
| let shop = Shops.findOne({ _id: account.shopId }, { languages: 1 }); | ||
|
|
||
| if (!shop || !shop.languages || shop.languages.length === 0) { | ||
| // if non-primary shop does not have any languages use primary shop | ||
| shop = Shops.findOne({ shopType: "primary" }, { languages: 1 }); | ||
| } | ||
|
|
||
| const shopLanguages = (shop && shop.languages) || []; | ||
| const shopLanguage = R.find(R.whereEq({ enabled: true, i18n: languageCode }))(shopLanguages); | ||
|
|
||
| if (!shopLanguage) { | ||
| throw new ReactionError("invalid-argument", `Shop does not define any enabled language with code "${languageCode}"`); | ||
| } | ||
|
|
||
| Accounts.update({ userId }, { $set: { "profile.language": languageCode } }); | ||
|
|
||
| const updatedAccount = Accounts.findOne({ userId }); | ||
| Promise.await(appEvents.emit("afterAccountUpdate", { | ||
| account: updatedAccount, | ||
| updatedBy: currentUserId, | ||
| updatedFields: ["profile.language"] | ||
| })); | ||
|
|
||
| return updatedAccount; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { decodeAccountOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/account"; | ||
|
|
||
| /** | ||
| * @name "Mutation.setAccountProfileLanguage" | ||
| * @method | ||
| * @memberof Accounts/GraphQL | ||
| * @summary resolver for the setAccountProfileLanguage GraphQL mutation | ||
| * @param {Object} _ - unused | ||
| * @param {Object} args.input - an object of all mutation arguments that were sent by the client | ||
| * @param {String} [args.input.accoundId] - The account ID, which defaults to the viewer account | ||
| * @param {String} args.input.languageCode - The languageCode to add to user profile | ||
| * @param {String} [args.input.clientMutationId] - An optional string identifying the mutation call | ||
| * @param {Object} context - an object containing the per-request state | ||
| * @return {Object} setAccountProfileLanguage | ||
| */ | ||
| export default function setAccountProfileLanguage(_, { input }, context) { | ||
| const { accountId, languageCode, clientMutationId = null } = input; | ||
| const dbAccountId = decodeAccountOpaqueId(accountId); | ||
| const updatedAccount = context.callMeteorMethod("accounts/setProfileLanguage", languageCode, dbAccountId); | ||
|
|
||
| return { | ||
| account: updatedAccount, | ||
| clientMutationId | ||
| }; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be more specifically named, maybe
ordererPreferredLanguage?