Skip to content

Instantly share code, notes, and snippets.

@evliu
Created October 10, 2014 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evliu/2345c9cfd18e476c8851 to your computer and use it in GitHub Desktop.
Save evliu/2345c9cfd18e476c8851 to your computer and use it in GitHub Desktop.
reaction-core collections.js
var AddressSchema, Cart, CartItemSchema, Customers, MetafieldSchema, Orders, PackageConfigSchema, ProductVariantSchema, Products, ShopMemberSchema, Shops, Tags, VariantMediaSchema;
share.ReactionPalette = this.ReactionPalette = new Meteor.Collection(null);
share.Product = this.Product = new Meteor.Collection("Product");
share.Variant = this.Variant = new Meteor.Collection("Variant");
ReactionCore.Collections.ConfigData = new Meteor.Collection("ConfigData");
ReactionCore.Collections.Translations = new Meteor.Collection("Translations");
/*
* Packages
*/
ReactionCore.Schemas.PackageConfig = PackageConfigSchema = new SimpleSchema({
shopId: {
type: String,
index: 1,
autoValue: function() {
if (this.isInsert) {
if (Meteor.isClient) {
return ReactionCore.getShopId() || "1";
}
return ReactionCore.getShopId();
} else {
return this.unset();
}
}
},
name: {
type: String,
index: 1
},
enabled: {
type: Boolean,
defaultValue: true
},
property: {
type: String,
optional: true
},
settings: {
type: Object,
optional: true,
blackbox: true
}
});
ReactionCore.Collections.Packages = new Meteor.Collection("Packages");
ReactionCore.Collections.Packages.attachSchema(PackageConfigSchema);
/*
* Shops
*/
ReactionCore.Schemas.ShopMember = ShopMemberSchema = new SimpleSchema({
userId: {
type: String
},
isAdmin: {
type: Boolean,
optional: true
},
permissions: {
type: [String],
optional: true
}
});
ReactionCore.Schemas.CustomEmailSettings = new SimpleSchema({
username: {
type: String,
optional: true
},
password: {
type: String,
optional: true
},
host: {
type: String,
optional: true
},
port: {
type: Number,
allowedValues: [25, 587, 465, 475, 2525],
optional: true
}
});
ReactionCore.Schemas.Metafield = MetafieldSchema = new SimpleSchema({
key: {
type: String,
max: 30,
optional: true
},
namespace: {
type: String,
max: 20,
optional: true
},
scope: {
type: String,
optional: true
},
value: {
type: String,
optional: true
},
valueType: {
type: String,
optional: true
},
description: {
type: String,
optional: true
}
});
ReactionCore.Schemas.VariantMedia = VariantMediaSchema = new SimpleSchema({
mediaId: {
type: String,
optional: true
},
priority: {
type: Number,
optional: true
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
},
updatedAt: {
type: Date,
optional: true
},
createdAt: {
type: Date
}
});
ReactionCore.Schemas.ProductPosition = new SimpleSchema({
tag: {
type: String,
optional: true
},
position: {
type: Number,
optional: true
},
weight: {
type: String,
optional: true
},
updatedAt: {
type: Date
}
});
ReactionCore.Schemas.Address = AddressSchema = new SimpleSchema({
_id: {
type: String,
optional: true
},
fullName: {
type: String
},
address1: {
label: "Address 1",
type: String
},
address2: {
label: "Address 2",
type: String,
optional: true
},
city: {
type: String
},
company: {
type: String,
optional: true
},
phone: {
type: String,
label: "Phone",
min: 7,
max: 22,
regEx: /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
},
region: {
label: "State/Province/Region",
type: String
},
postal: {
label: "ZIP/Postal Code",
type: String
},
country: {
type: String
},
isCommercial: {
label: "This is a commercial address",
type: Boolean,
defaultValue: false
},
isDefault: {
label: "This is my default address",
type: Boolean,
defaultValue: true
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
}
});
ReactionCore.Schemas.Country = new SimpleSchema({
name: {
type: String
},
code: {
type: String
}
});
ReactionCore.Schemas.Tax = new SimpleSchema({
taxShipping: {
type: String,
optional: true
},
taxesIncluded: {
type: Boolean,
optional: true
},
countyTaxes: {
type: Boolean,
optional: true
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
}
});
ReactionCore.Schemas.Shop = new SimpleSchema({
_id: {
type: String,
optional: true
},
name: {
type: String,
index: 1
},
addressBook: {
type: [ReactionCore.Schemas.Address]
},
domains: {
type: [String],
defaultValue: ["localhost"]
},
currency: {
type: String
},
email: {
type: String
},
moneyFormat: {
type: String
},
moneyWithCurrencyFormat: {
type: String
},
moneyInEmailsFormat: {
type: String
},
moneyWithCurrencyInEmailsFormat: {
type: String
},
taxes: {
type: [ReactionCore.Schemas.Tax],
optional: true
},
"public": {
type: String,
optional: true
},
timezone: {
type: String
},
ownerId: {
type: String
},
members: {
type: [ReactionCore.Schemas.ShopMember],
index: 1
},
useCustomEmailSettings: {
type: Boolean,
optional: true
},
customEmailSettings: {
type: ReactionCore.Schemas.CustomEmailSettings
},
createdAt: {
type: Date
},
updatedAt: {
type: Date,
autoValue: function() {
if (this.isUpdate) {
return new Date();
}
},
optional: true
}
});
ReactionCore.Collections.Shops = Shops = this.Shops = new Meteor.Collection("Shops", {
transform: function(shop) {
var index, member, _ref;
_ref = shop.members;
for (index in _ref) {
member = _ref[index];
member.index = index;
member.user = Meteor.users.findOne(member.userId);
}
return shop;
}
});
ReactionCore.Collections.Shops.attachSchema(ReactionCore.Schemas.Shop);
ReactionCore.Schemas.Social = new SimpleSchema({
service: {
type: String
},
handle: {
type: String
}
});
/*
* Products
*/
ReactionCore.Schemas.ProductVariant = ProductVariantSchema = new SimpleSchema({
_id: {
type: String
},
parentId: {
type: String,
optional: true
},
cloneId: {
type: String,
optional: true
},
index: {
type: String,
optional: true
},
barcode: {
label: "Barcode",
type: String,
optional: true
},
compareAtPrice: {
label: "MSRP",
type: Number,
optional: true,
decimal: true,
min: 0
},
fulfillmentService: {
label: "Fulfillment service",
type: String,
optional: true
},
weight: {
label: "Weight (.oz)",
type: Number,
min: 0
},
inventoryManagement: {
type: Boolean,
label: "Inventory Tracking"
},
inventoryPolicy: {
type: Boolean,
label: "Deny when out of stock"
},
lowInventoryWarningThreshold: {
type: Number,
label: "Warn @",
min: 0,
optional: true
},
inventoryQuantity: {
type: Number,
label: "Quantity",
optional: true
},
price: {
label: "Price",
type: Number,
decimal: true,
min: 0
},
requiresShipping: {
label: "Require a shipping address",
type: Boolean,
optional: true
},
sku: {
label: "SKU",
type: String,
optional: true
},
taxable: {
label: "Taxable",
type: Boolean,
optional: true
},
title: {
label: "Label",
type: String
},
optionTitle: {
label: "Option",
type: String,
optional: true
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
},
positions: {
type: [ReactionCore.Schemas.ProductPosition],
optional: true
},
createdAt: {
label: "Created at",
type: Date,
optional: true
},
updatedAt: {
label: "Updated at",
type: Date,
optional: true
}
});
ReactionCore.Schemas.Product = new SimpleSchema({
_id: {
type: String,
optional: true
},
cloneId: {
type: String,
optional: true
},
shopId: {
type: String
},
title: {
type: String
},
pageTitle: {
type: String,
optional: true
},
description: {
type: String,
optional: true
},
productType: {
type: String
},
vendor: {
type: String,
optional: true
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
},
variants: {
type: [ReactionCore.Schemas.ProductVariant]
},
hashtags: {
type: [String],
optional: true,
index: 1
},
twitterMsg: {
type: String,
optional: true,
max: 140
},
facebookMsg: {
type: String,
optional: true,
max: 255
},
instagramMsg: {
type: String,
optional: true,
max: 255
},
pinterestMsg: {
type: String,
optional: true,
max: 255
},
metaDescription: {
type: String,
optional: true
},
handle: {
type: String,
optional: true,
index: 1
},
isVisible: {
type: Boolean,
index: 1
},
publishedAt: {
type: Date,
optional: true
},
publishedScope: {
type: String,
optional: true
},
templateSuffix: {
type: String,
optional: true
},
createdAt: {
type: Date
},
updatedAt: {
type: Date,
autoValue: function() {
if (this.isUpdate) {
return new Date();
}
},
optional: true
}
});
ReactionCore.Collections.Products = Products = this.Products = new Meteor.Collection("Products");
ReactionCore.Collections.Products.attachSchema(ReactionCore.Schemas.Product);
/*
* Customers
*/
ReactionCore.Schemas.Customer = new SimpleSchema({
shopId: {
type: String
},
email: {
type: String
},
fullName: {
type: String
},
imageUrl: {
type: String
},
acceptsMarketing: {
type: Boolean
},
ordersCount: {
type: Number
},
totalSpent: {
type: Number,
decimal: true
},
state: {
type: String
},
lastOrderId: {
type: String,
optional: true
},
lastOrderName: {
type: String,
optional: true
},
note: {
type: String,
optional: true
},
hashtags: {
type: [String],
optional: true
},
multipassIdentifier: {
type: String,
optional: true
},
verifiedEmail: {
type: Boolean
},
metafields: {
type: [ReactionCore.Schemas.Metafield],
optional: true
},
createdAt: {
type: Date
},
updatedAt: {
type: Date
}
});
ReactionCore.Collections.Customers = Customers = this.Customers = new Meteor.Collection("Customers");
ReactionCore.Collections.Customers.attachSchema(ReactionCore.Schemas.Customer);
/*
* Carts
*/
ReactionCore.Schemas.CartItem = CartItemSchema = new SimpleSchema({
_id: {
type: String
},
productId: {
type: String
},
quantity: {
label: "Quantity",
type: Number,
min: 0
},
variants: {
type: ReactionCore.Schemas.ProductVariant
}
});
ReactionCore.Schemas.ShipmentQuote = new SimpleSchema({
carrier: {
type: Number
},
method: {
type: Number
},
tracking: {
type: String,
optional: true
},
label: {
type: String,
optional: true
},
value: {
type: String,
optional: true
}
});
ReactionCore.Schemas.Shipment = new SimpleSchema({
address: {
type: ReactionCore.Schemas.Address,
optional: true
},
shipmentMethod: {
type: ReactionCore.Schemas.ShipmentQuote,
optional: true
}
});
ReactionCore.Schemas.PaymentMethod = new SimpleSchema({
processor: {
type: String
},
storedCard: {
type: String,
optional: true
},
method: {
type: String,
optional: true
},
transactionId: {
type: String
},
status: {
type: String
},
mode: {
type: String
},
createdAt: {
type: Date,
optional: true
},
updatedAt: {
type: Date,
optional: true
},
authorization: {
type: String,
optional: true
},
amount: {
type: Number,
decimal: true
}
});
ReactionCore.Schemas.Payment = new SimpleSchema({
address: {
type: ReactionCore.Schemas.Address,
optional: true
},
paymentMethod: {
type: [ReactionCore.Schemas.PaymentMethod],
optional: true
}
});
ReactionCore.Schemas.Cart = new SimpleSchema({
shopId: {
type: String,
index: 1
},
sessionId: {
type: String,
optional: true,
custom: function() {
var userIdField;
userIdField = this.siblingField("userId");
if (this.isInsert && !this.value && !userIdField.value) {
return "required";
}
},
index: 1
},
userId: {
type: String,
optional: true,
index: 1
},
items: {
type: [ReactionCore.Schemas.CartItem],
optional: true
},
requiresShipping: {
label: "Require a shipping address",
type: Boolean,
optional: true
},
shipping: {
type: ReactionCore.Schemas.Shipment,
optional: true,
blackbox: true
},
payment: {
type: ReactionCore.Schemas.Payment,
optional: true,
blackbox: true
},
totalPrice: {
label: "Total Price",
type: Number,
optional: true,
decimal: true,
min: 0
},
state: {
type: String,
defaultValue: "new",
optional: true
},
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {
$setOnInsert: new Date
};
}
},
denyUpdate: true
},
updatedAt: {
type: Date,
autoValue: function() {
if (this.isUpdate) {
return {
$set: new Date
};
} else if (this.isUpsert) {
return {
$setOnInsert: new Date
};
}
},
denyInsert: true,
optional: true
}
});
ReactionCore.Collections.Cart = Cart = this.Cart = new Meteor.Collection("Cart");
ReactionCore.Collections.Cart.attachSchema(ReactionCore.Schemas.Cart);
/*
* Orders
*/
ReactionCore.Schemas.Document = new SimpleSchema({
docId: {
type: String
},
docType: {
type: String,
optional: true
}
});
ReactionCore.Schemas.History = new SimpleSchema({
event: {
type: String
},
userId: {
type: String
},
updatedAt: {
type: Date
}
});
ReactionCore.Schemas.OrderItems = new SimpleSchema({
additionalField: {
type: String,
optional: true
},
status: {
type: String
},
history: {
type: [ReactionCore.Schemas.History],
optional: true
},
documents: {
type: [ReactionCore.Schemas.Document],
optional: true
}
});
ReactionCore.Collections.Orders = Orders = this.Orders = new Meteor.Collection("Orders");
ReactionCore.Collections.Orders.attachSchema([ReactionCore.Schemas.Cart, ReactionCore.Schemas.OrderItems]);
/*
* Tags
*/
ReactionCore.Schemas.Tag = new SimpleSchema({
name: {
type: String,
index: 1
},
slug: {
type: String
},
position: {
type: Number,
optional: true
},
relatedTagIds: {
type: [String],
optional: true,
index: 1
},
isTopLevel: {
type: Boolean
},
shopId: {
type: String,
index: 1
},
createdAt: {
type: Date
},
updatedAt: {
type: Date
}
});
ReactionCore.Collections.Tags = Tags = this.Tags = new Meteor.Collection("Tags");
ReactionCore.Collections.Tags.attachSchema(ReactionCore.Schemas.Tag);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment