@jerryquickly/api-plugin-shops
Advanced tools
Comparing version 0.0.0-development to 0.0.1-development
{ | ||
"name": "@jerryquickly/api-plugin-shops", | ||
"description": "Shops plugin for the Reaction API", | ||
"version": "0.0.0-development", | ||
"version": "0.0.1-development", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -7,6 +7,6 @@ import shops from "./shops.js"; | ||
shops, | ||
primaryShop: (context) => { | ||
primaryShop: (context) => | ||
// return context.collections.Shops.findOne({ shopType: "primary" }) | ||
return this.shopByUser(context, true); | ||
}, | ||
this.shopByUser(context, true), | ||
async primaryShopId(context) { | ||
@@ -17,4 +17,14 @@ const shop = await this.shopByUser(context); | ||
shopByUser: (context, bDefaultPrimary) => { | ||
const userId = context.userId; | ||
joinedShops: async (context) => { | ||
const { userId } = context; | ||
const accounts = userId ? await context.collections.Accounts.find({ userId }) : []; | ||
const shopIds = accounts.map((shop) => shop.shopId); | ||
if (shopIds.length > 0) { | ||
return context.collections.Shops.find({ _id: { $in: shopIds } }); | ||
} | ||
return []; | ||
}, | ||
shopByUser: async (context, bDefaultPrimary) => { | ||
const { userId } = context; | ||
const account = userId ? await context.collections.Accounts.findOne({ userId }) : undefined; | ||
@@ -26,4 +36,4 @@ if (account && account.shopId) { | ||
} | ||
return undefined; | ||
return null; | ||
} | ||
}; |
import primaryShopId from "./primaryShopId.js"; | ||
import primaryShop from "./primaryShop.js"; | ||
import joinedShops from "./joinedShops.js"; | ||
import shop from "./shop.js"; | ||
@@ -10,2 +11,3 @@ import shopBySlug from "./shopBySlug.js"; | ||
primaryShop, | ||
joinedShops, | ||
shop, | ||
@@ -12,0 +14,0 @@ shopBySlug, |
Sorry, the diff of this file is not supported yet
183390
108
3467