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
4 changes: 2 additions & 2 deletions imports/node-app/core-services/cart/mutations/addCartItems.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken";
import hashToken from "@reactioncommerce/api-utils/hashToken";
import addCartItemsUtil from "../util/addCartItems.js";

/**
Expand Down Expand Up @@ -30,7 +30,7 @@ export default async function addCartItems(context, input, options = {}) {
throw new ReactionError("not-found", "Cart not found");
}

selector = { _id: cartId, anonymousAccessToken: hashLoginToken(token) };
selector = { _id: cartId, anonymousAccessToken: hashToken(token) };
}

const cart = await Cart.findOne(selector);
Expand Down
4 changes: 2 additions & 2 deletions imports/node-app/core-services/cart/mutations/createCart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Random from "@reactioncommerce/random";
import ReactionError from "@reactioncommerce/reaction-error";
import Logger from "@reactioncommerce/logger";
import hashLoginToken from "../../../core/util/hashLoginToken";
import hashToken from "@reactioncommerce/api-utils/hashToken";
import addCartItems from "../util/addCartItems.js";

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ export default async function createCart(context, input) {
const newCart = {
_id: Random.id(),
accountId,
anonymousAccessToken: anonymousAccessToken && hashLoginToken(anonymousAccessToken),
anonymousAccessToken: anonymousAccessToken && hashToken(anonymousAccessToken),
currencyCode: cartCurrencyCode,
createdAt,
items: updatedItemList,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Logger from "@reactioncommerce/logger";
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken";
import hashToken from "@reactioncommerce/api-utils/hashToken";
import convertAnonymousCartToNewAccountCart from "./convertAnonymousCartToNewAccountCart.js";
import reconcileCartsKeepAccountCart from "./reconcileCartsKeepAccountCart.js";
import reconcileCartsKeepAnonymousCart from "./reconcileCartsKeepAnonymousCart.js";
Expand Down Expand Up @@ -30,7 +30,7 @@ export default async function reconcileCarts(context, input) {
if (!anonymousCartToken) throw new ReactionError("invalid-param", "anonymousCartToken is required");

const accountCartSelector = { accountId };
const anonymousCartSelector = { _id: anonymousCartId, anonymousAccessToken: hashLoginToken(anonymousCartToken) };
const anonymousCartSelector = { _id: anonymousCartId, anonymousAccessToken: hashToken(anonymousCartToken) };

const carts = await Cart.find({
$or: [accountCartSelector, anonymousCartSelector]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken";
import hashToken from "@reactioncommerce/api-utils/hashToken";

const inputSchema = new SimpleSchema({
"cartId": String,
Expand Down Expand Up @@ -34,7 +34,7 @@ export default async function removeCartItems(context, input) {

const selector = { _id: cartId };
if (token) {
selector.anonymousAccessToken = hashLoginToken(token);
selector.anonymousAccessToken = hashToken(token);
} else if (accountId) {
selector.accountId = accountId;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleSchema from "simpl-schema";
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken";
import hashToken from "@reactioncommerce/api-utils/hashToken";

const inputSchema = new SimpleSchema({
cartId: String,
Expand Down Expand Up @@ -29,7 +29,7 @@ export default async function setEmailOnAnonymousCart(context, input) {

const cart = await Cart.findOne({
_id: cartId,
anonymousAccessToken: hashLoginToken(token)
anonymousAccessToken: hashToken(token)
});
if (!cart) throw new ReactionError("not-found", "Cart not found");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleSchema from "simpl-schema";
import Random from "@reactioncommerce/random";
import { Address as AddressSchema } from "../simpleSchemas.js";
import { CartAddress as AddressSchema } from "../simpleSchemas.js";
import getCartById from "../util/getCartById.js";

const inputSchema = new SimpleSchema({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jest.mock("../util/getCartById", () => jest.fn().mockImplementation(() => Promis
}]
})));

const address = Factory.Address.makeOne({ _id: undefined });
const address = Factory.CartAddress.makeOne({ _id: undefined });

beforeAll(() => {
if (!mockContext.mutations.saveCart) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken.js";
import hashToken from "@reactioncommerce/api-utils/hashToken";

/**
* @name anonymousCartByCartId
Expand All @@ -22,6 +22,6 @@ export default async function anonymousCartByCartId(context, { cartId, token } =

return Cart.findOne({
_id: cartId,
anonymousAccessToken: hashLoginToken(token)
anonymousAccessToken: hashToken(token)
});
}
16 changes: 8 additions & 8 deletions imports/node-app/core-services/cart/simpleSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Metafield = new SimpleSchema({
});

/**
* @name Address
* @name CartAddress
* @memberof Schemas
* @type {SimpleSchema}
* @property {String} _id
Expand All @@ -70,7 +70,7 @@ const Metafield = new SimpleSchema({
* @property {Boolean} failedValidation
* @property {Metafield[]} metafields
*/
export const Address = new SimpleSchema({
export const CartAddress = new SimpleSchema({
"_id": {
type: String,
optional: true
Expand Down Expand Up @@ -323,7 +323,7 @@ const ShippingMethod = new SimpleSchema({
* @property {ShippingMethod} method ShippingMethod
* @property {Number} rate default value: `0.00`
*/
const ShipmentQuote = new SimpleSchema({
export const ShipmentQuote = new SimpleSchema({
carrier: {
type: String
},
Expand Down Expand Up @@ -460,7 +460,7 @@ const Workflow = new SimpleSchema({
});

/**
* @name Invoice
* @name CartInvoice
* @type {SimpleSchema}
* @memberof Schemas
* @property {Number} discounts Total of all discounts (a positive number, but subtracted from the grand total)
Expand All @@ -472,7 +472,7 @@ const Workflow = new SimpleSchema({
* @property {Number} taxes Total tax
* @property {Number} total Grand total
*/
const Invoice = new SimpleSchema({
export const CartInvoice = new SimpleSchema({
currencyCode: String,
discounts: {
type: Number,
Expand Down Expand Up @@ -546,7 +546,7 @@ const Shipment = new SimpleSchema({
optional: true
},
"address": {
type: Address,
type: CartAddress,
optional: true
},
"shipmentMethod": {
Expand Down Expand Up @@ -585,7 +585,7 @@ const Shipment = new SimpleSchema({
defaultValue: {}
},
"invoice": {
type: Invoice,
type: CartInvoice,
optional: true
},
"itemIds": {
Expand Down Expand Up @@ -826,7 +826,7 @@ export const Cart = new SimpleSchema({
},
"currencyCode": String,
"billingAddress": {
type: Address,
type: CartAddress,
optional: true
},
"sessionId": {
Expand Down
4 changes: 2 additions & 2 deletions imports/node-app/core-services/cart/util/getCartById.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactionError from "@reactioncommerce/reaction-error";
import hashLoginToken from "../../../core/util/hashLoginToken.js";
import hashToken from "@reactioncommerce/api-utils/hashToken";

/**
* @summary Gets a cart from the db by ID. If there is an account for the request, verifies that the
Expand All @@ -18,7 +18,7 @@ export default async function getCartById(context, cartId, { cartToken, throwIfN
const selector = { _id: cartId };

if (cartToken) {
selector.anonymousAccessToken = hashLoginToken(cartToken);
selector.anonymousAccessToken = hashToken(cartToken);
}

const cart = await Cart.findOne(selector);
Expand Down
14 changes: 7 additions & 7 deletions imports/node-app/core-services/catalog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import resolvers from "./resolvers/index.js";
import schemas from "./schemas/index.js";
import startup from "./startup.js";
import {
Catalog,
CatalogProduct,
CatalogProductOption,
CatalogProductVariant,
ImageInfo,
ImageSizes,
ShippingParcel,
SocialMetadata,
VariantBaseSchema,
CatalogVariantSchema,
CatalogProduct,
Catalog
SocialMetadata
} from "./simpleSchemas.js";

/**
Expand Down Expand Up @@ -61,8 +61,8 @@ export default async function register(app) {
ImageSizes,
ShippingParcel,
SocialMetadata,
CatalogProductOption: VariantBaseSchema,
CatalogProductVariant: CatalogVariantSchema,
CatalogProductOption,
CatalogProductVariant,
CatalogProduct,
Catalog
}
Expand Down
18 changes: 9 additions & 9 deletions imports/node-app/core-services/catalog/simpleSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SimpleSchema from "simpl-schema";
* @property {String} valueType optional
* @property {String} description optional
*/
export const Metafield = new SimpleSchema({
const Metafield = new SimpleSchema({
key: {
type: String,
max: 30,
Expand Down Expand Up @@ -160,7 +160,7 @@ export const SocialMetadata = new SimpleSchema({
});

/**
* @name VariantBaseSchema
* @name CatalogProductOption
* @memberof Schemas
* @type {SimpleSchema}
* @property {String} _id required
Expand All @@ -184,7 +184,7 @@ export const SocialMetadata = new SimpleSchema({
* @property {Number} weight optional, default value: `0`
* @property {Number} width optional, default value: `0`
*/
export const VariantBaseSchema = new SimpleSchema({
export const CatalogProductOption = new SimpleSchema({
"_id": {
type: String,
label: "Catalog product variant Id"
Expand Down Expand Up @@ -294,20 +294,20 @@ export const VariantBaseSchema = new SimpleSchema({
});

/**
* @name CatalogVariantSchema
* @name CatalogProductVariant
* @memberof Schemas
* @type {SimpleSchema}
* @extends VariantBaseSchema
* @property {VariantBaseSchema[]} options optional
* @extends CatalogProductOption
* @property {CatalogProductOption[]} options optional
*/
export const CatalogVariantSchema = VariantBaseSchema.clone().extend({
export const CatalogProductVariant = CatalogProductOption.clone().extend({
"options": {
type: Array,
label: "Variant Options",
optional: true
},
"options.$": {
type: VariantBaseSchema
type: CatalogProductOption
}
});

Expand Down Expand Up @@ -501,7 +501,7 @@ export const CatalogProduct = new SimpleSchema({
optional: true
},
"variants.$": {
type: CatalogVariantSchema
type: CatalogProductVariant
},
"vendor": {
type: String,
Expand Down
25 changes: 25 additions & 0 deletions imports/node-app/core-services/inventory/simpleSchemas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @summary Extend SimpleSchemas with inventory fields
* @param {Object} schemas Simple schemas
* @returns {undefined}
*/
export function extendInventorySchemas(schemas) {
/**
* @property {Boolean} isBackorder required, Indicates when a product is currently backordered
* @property {Boolean} isLowQuantity required, Indicates that the product quantity is too low
* @property {Boolean} isSoldOut required, Indicates when the product quantity is zero
*/
schemas.CatalogProduct.extend({
isBackorder: Boolean,
isLowQuantity: Boolean,
isSoldOut: Boolean
});

// Extend variants by adding a isSoldOut prop
const variantSchemaExtension = {
isSoldOut: Boolean
};

schemas.CatalogProductOption.extend(variantSchemaExtension);
schemas.CatalogProductVariant.extend(variantSchemaExtension);
}
21 changes: 3 additions & 18 deletions imports/node-app/core-services/inventory/utils/preStartup.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import { extendInventorySchemas } from "../simpleSchemas.js";

/**
* @summary Called pre startup
* @param {Object} context Startup context
* @param {Object} context.simpleSchemas Simple schemas
* @returns {undefined}
*/
export default async function preStartup(context) {
/**
* @property {Boolean} isBackorder required, Indicates when a product is currently backordered
* @property {Boolean} isLowQuantity required, Indicates that the product quantity is too low
* @property {Boolean} isSoldOut required, Indicates when the product quantity is zero
*/
context.simpleSchemas.CatalogProduct.extend({
isBackorder: Boolean,
isLowQuantity: Boolean,
isSoldOut: Boolean
});

// Extend variants by adding a isSoldOut prop
const variantSchemaExtension = {
isSoldOut: Boolean
};

context.simpleSchemas.CatalogProductOption.extend(variantSchemaExtension);
context.simpleSchemas.CatalogProductVariant.extend(variantSchemaExtension);
extendInventorySchemas(context.simpleSchemas);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ function getCatalogProduct() {
isBackorder: undefined,
isLowQuantity: undefined,
isSoldOut: undefined,
variants: Factory.CatalogVariantSchema.makeMany(1, {
variants: Factory.CatalogProductVariant.makeMany(1, {
isDeleted: false,
isSoldOut: undefined,
isVisible: true,
variantId: "TOP_VARIANT_1",
options: Factory.VariantBaseSchema.makeMany(2, {
options: Factory.CatalogProductOption.makeMany(2, {
isDeleted: false,
isSoldOut: undefined,
isVisible: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { OrderFulfillmentGroup, OrderItem } from "/imports/collections/schemas";
import i18n from "./i18n";
import mutations from "./mutations";
import i18n from "./i18n/index.js";
import mutations from "./mutations/index.js";
import preStartup from "./preStartup.js";
import queries from "./queries";
import resolvers from "./resolvers";
import schemas from "./schemas";
import startup from "./startup";
import getDataForOrderEmail from "./util/getDataForOrderEmail";
import queries from "./queries/index.js";
import resolvers from "./resolvers/index.js";
import schemas from "./schemas/index.js";
import { Order, OrderFulfillmentGroup, OrderItem } from "./simpleSchemas";
import startup from "./startup.js";
import getDataForOrderEmail from "./util/getDataForOrderEmail.js";

/**
* @summary Import and call this function to add this plugin to your API.
Expand Down Expand Up @@ -51,6 +51,7 @@ export default async function register(app) {
mutations,
queries,
simpleSchemas: {
Order,
OrderFulfillmentGroup,
OrderItem
},
Expand Down
Loading