Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions imports/plugins/core/accounts/server/no-meteor/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function startup(context) {
});

appEvents.on("afterShopCreate", async (payload) => {
const { shop } = payload;
const { shop, shopAdminUserId } = payload;
let { createdBy: userId } = payload;
const { _id: newShopId, shopType } = shop;

Expand Down Expand Up @@ -64,10 +64,10 @@ export default async function startup(context) {
}

// If a user created the shop, give the user owner access to it
if (userId) {
if (shopAdminUserId) {
// Add users to roles
await users.updateOne({
_id: userId
_id: shopAdminUserId
}, {
$addToSet: {
[`roles.${newShopId}`]: {
Expand All @@ -77,7 +77,7 @@ export default async function startup(context) {
});

// Set the active shopId for this user
await Accounts.updateOne({ userId }, {
await Accounts.updateOne({ shopAdminUserId }, {
$set: {
"profile.preferences.reaction.activeShopId": newShopId,
"shopId": newShopId
Expand All @@ -87,7 +87,7 @@ export default async function startup(context) {
}
});

const updatedAccount = await Accounts.findOne({ userId });
const updatedAccount = await Accounts.findOne({ shopAdminUserId });
Promise.await(appEvents.emit("afterAccountUpdate", {
account: updatedAccount,
updatedBy: userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function createShop(shopAdminUserId, partialShopData) {
// we should have created new shop, or erred
Logger.info("Created shop: ", newShopId);

Promise.await(appEvents.emit("afterShopCreate", { createdBy: userId, shop: newShop }));
Promise.await(appEvents.emit("afterShopCreate", { createdBy: userId, shop: newShop, shopAdminUserId: shopAdminUserId || userId }));

// Add this shop to the merchant
Shops.update({ _id: primaryShopId }, {
Expand Down