Skip to content

Instantly share code, notes, and snippets.

@jkdeveyra
Created November 18, 2015 07:36
Show Gist options
  • Save jkdeveyra/5eb1c68a0a5bcfef76e1 to your computer and use it in GitHub Desktop.
Save jkdeveyra/5eb1c68a0a5bcfef76e1 to your computer and use it in GitHub Desktop.
/**
* Campaign Templates collection.
*/
CampaignTemplates = new Meteor.Collection('campaign_templates');
var CategorySchema = new SimpleSchema({
"name": { type: String },
"code": { type: String },
"type": { type: String },
"values": { type: [String] }
});
var DriverSchema = new SimpleSchema({
"name": { type: String },
"code": { type: String },
"categories": { type: [CategorySchema] }
});
CampaignTemplatesSchema = new SimpleSchema({
user_id: {
type: String,
index: true,
autoValue: function() {
return Meteor.userId();
}
},
company_id: {
type: String,
index: true
},
campaign_id: {
type: String,
index: true
},
title: {
type: String,
label: "Campaign Template",
index: true,
custom: function () {
if (this.isSet) {
if (Meteor.isServer && this.userId) {
if (!Meteor.call('isCampaignTemplateNameAvailable', this.value)) {
return 'notUnique';
}
}
if (Meteor.isClient) {
Meteor.call('isCampaignTemplateNameAvailable', this.value, function (event, result) {
if (!result) {
CampaignTemplates.simpleSchema().namedContext().addInvalidKeys([{name: "title", type: "notUnique"}]);
}
});
}
}
}
},
overview: {
type: String,
label: "Overview",
optional: true
},
approved: {
type: Boolean,
defaultValue: false
},
startDate: {
type: Date,
label: "Start Date"
},
endDate: {
type: Date,
label: "End Date"
},
"values": { type: [DriverSchema] },
"benchmarkValues": { type: Array, optional: true },
"benchmarkValues.$": { type: Object },
"benchmarkValues.$.category_id": { type: String },
"benchmarkValues.$.benchmark_id": { type: String },
"benchmarkValues.$.tag_id": { type: String },
"benchmarkValues.$.value": { type: String },
"benchmarkValues.$.affix": { type: String },
"search_index": {
type: String,
index: true,
autoValue: function() { return ""; }
},
createdAt: {
type: Date,
autoValue: function() {
if (this.isInsert) {
return new Date;
} else if (this.isUpsert) {
return {$setOnInsert: new Date};
} else {
this.unset();
}
}
},
modifiedAt: {
type: Date,
autoValue: function() {
return new Date();
}
}
});
CampaignTemplates.attachSchema(CampaignTemplatesSchema);
@ddon15
Copy link

ddon15 commented Nov 18, 2015

Can we add tagName to benchmarkValues?. It will be use in campaign template preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment