Upgraded to Meteor 1.6.0.1 and NodeJS 8.9.3. Added weekly/daily property to venues to support graphing and tracking of actual income from farmers markets (they don't usually match with expected income). Added workers objects to help illustrate who did what work (who was at the market on a specific week for example, or who prep'd and who canned a batch of jam). Fixed some bugs in the venue page. Re-design of the menu to allow for more menu options.
This commit is contained in:
@@ -113,7 +113,7 @@ if(Meteor.isServer) {
|
||||
check(order, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Products.update(id, {$set: {name, postfix, order, updatedAt: new Date()}});
|
||||
Measures.update(id, {$set: {name, postfix, order, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
|
||||
|
||||
const TYPES = ['Retail', "Farmer's Market", "Restaurant", "Mail"];
|
||||
const FREQUENCIES = ['Daily', 'Weekly'];
|
||||
|
||||
Venues = new Mongo.Collection('Venues');
|
||||
let VenuesSchema = new SimpleSchema({
|
||||
name: {
|
||||
@@ -17,7 +20,15 @@ let VenuesSchema = new SimpleSchema({
|
||||
type: String,
|
||||
label: "Type",
|
||||
optional: false,
|
||||
trim: true
|
||||
trim: true,
|
||||
allowedValues: TYPES //If you change these values, also change Venues.js for the editor to include the new list when setting up the combo.
|
||||
},
|
||||
frequency: { // How often the market is run. The exact day or week is not important, just that it is daily, weekly, bi-weekly, monthly, etc... Currently only supporting Daily and Weekly since all markets fit into these categories.
|
||||
type: String,
|
||||
label: "Frequency",
|
||||
optional: false,
|
||||
defaultValue: 'Daily',
|
||||
allowedValues: FREQUENCIES //If you change these values, also change Venues.js for the editor to include the new list when setting up the combo.
|
||||
},
|
||||
createdAt: {
|
||||
type: Date,
|
||||
@@ -40,6 +51,7 @@ let VenuesSchema = new SimpleSchema({
|
||||
optional: true
|
||||
}
|
||||
});
|
||||
VenuesSchema.constants = {types: TYPES, frequencies: FREQUENCIES};
|
||||
Venues.attachSchema(VenuesSchema);
|
||||
|
||||
if(Meteor.isServer) Meteor.publish('venues', function() {
|
||||
@@ -58,12 +70,30 @@ if(Meteor.isServer) {
|
||||
//});
|
||||
|
||||
Meteor.methods({
|
||||
createVenue: function(name, type) {
|
||||
createVenue: function(name, type, frequency) {
|
||||
check(name, String);
|
||||
check(type, String);
|
||||
check(frequency, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Venues.insert({name, type, createdAt: new Date()});
|
||||
Venues.insert({name, type, frequency, createdAt: new Date()});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
//deleteVenue: function(id) {
|
||||
// if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
// Venues.remove(id); //TODO: If this is ever allowed, we should either remove or replace references to the deleted venue in the rest of the database.
|
||||
// }
|
||||
// else throw new Meteor.Error(403, "Not authorized.");
|
||||
//},
|
||||
updateVenue: function(id, name, type, frequency) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(type, String);
|
||||
check(frequency, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Venues.update(id, {$set: {name, type, frequency, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
@@ -92,22 +122,6 @@ if(Meteor.isServer) {
|
||||
Venues.update(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
//deleteVenue: function(id) {
|
||||
// if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
// Venues.remove(id); //TODO: If this is ever allowed, we should either remove or replace references to the deleted venue in the rest of the database.
|
||||
// }
|
||||
// else throw new Meteor.Error(403, "Not authorized.");
|
||||
//},
|
||||
updateVenue: function(id, name, type) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(type, String);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Venues.update(id, {$set: {name, type, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
125
imports/api/Worker.js
Normal file
125
imports/api/Worker.js
Normal file
@@ -0,0 +1,125 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import { check } from 'meteor/check';
|
||||
import {SimpleSchema} from 'meteor/aldeed:simple-schema';
|
||||
|
||||
Workers = new Mongo.Collection('Workers');
|
||||
let WORKER_ACTIVITIES = ['sales', 'prep', 'canning', 'farming'];
|
||||
let workersSchema = new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
label: "Name",
|
||||
optional: false,
|
||||
trim: true,
|
||||
index: 1,
|
||||
unique: true
|
||||
},
|
||||
activities: {
|
||||
type: [String],
|
||||
label: "Activities",
|
||||
optional: false,
|
||||
trim: true
|
||||
},
|
||||
hourlyRate: {
|
||||
type: SimpleSchema.Integer,
|
||||
label: "HourlyRate",
|
||||
optional: false,
|
||||
min: 0
|
||||
},
|
||||
createdAt: { //Force the value to the current date on the server.
|
||||
type: Date,
|
||||
label: "Created On",
|
||||
// autoValue: function() { //The disadvantage of autoValue is that it sets the date after insertion, causing the UI to update twice - once where the item has no date, and then again where the date is set. Sorted lists will cause the item to bounce around.
|
||||
// if(this.isInsert) return new Date();
|
||||
// else if(this.isUpsert) return {$setOnInsert: new Date()};
|
||||
// else this.unset();
|
||||
// },
|
||||
// denyUpdate: true,
|
||||
optional: false
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
label: "Updated On",
|
||||
// autoValue: function() {
|
||||
// if(this.isUpdate) return new Date();
|
||||
// },
|
||||
// denyInsert: true,
|
||||
optional: true
|
||||
},
|
||||
deactivated: {
|
||||
type: Boolean,
|
||||
label: "Deactivated",
|
||||
optional: true
|
||||
},
|
||||
hidden: {
|
||||
type: Boolean,
|
||||
label: "Hidden",
|
||||
optional: true
|
||||
}
|
||||
});
|
||||
workersSchema.constants = {activities: WORKER_ACTIVITIES};
|
||||
Workers.attachSchema(workersSchema);
|
||||
|
||||
if(Meteor.isServer) Meteor.publish('Workers', function() {
|
||||
return Workers.find({});
|
||||
});
|
||||
|
||||
if(Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
createWorker: function(name, activities, hourlyRate) {
|
||||
check(name, String);
|
||||
check(activities, [String]);
|
||||
check(hourlyRate, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.insert({name, activities, hourlyRate, createdAt: new Date()});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
//deleteWorker: function(id) {
|
||||
// if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
// //TODO: Should troll the database looking for references to remove or replace. This is currently not used.
|
||||
// Workers.remove(id);
|
||||
// }
|
||||
// else throw new Meteor.Error(403, "Not authorized.");
|
||||
//},
|
||||
updateWorker: function(id, name, activities, hourlyRate) {
|
||||
check(id, String);
|
||||
check(name, String);
|
||||
check(activities, [String]);
|
||||
check(hourlyRate, Number);
|
||||
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {name, activities, hourlyRate, updatedAt: new Date()}});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
deactivateWorker: function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
//Workers.remove(id);
|
||||
Workers.update(id, {$set: {deactivated: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
reactivateWorker: function(id) {
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {deactivated: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
hideWorker: function(id) { //One step past deactivated - will only show in the Workers list if hidden Workers are enabled.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {hidden: true}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
},
|
||||
showWorker: function(id) { //Returns the measure to being simply deactivated. Will again show in lists.
|
||||
if(Roles.userIsInRole(this.userId, [Meteor.UserRoles.ROLE_UPDATE])) {
|
||||
Workers.update(id, {$set: {hidden: false}}, {bypassCollection2: true});
|
||||
}
|
||||
else throw new Meteor.Error(403, "Not authorized.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default Workers;
|
||||
@@ -7,9 +7,10 @@ import SalesSheets from "./SalesSheet.js";
|
||||
import Logs from "./Logs.js";
|
||||
import Users from "./User.js";
|
||||
import UserRoles from "./Roles.js";
|
||||
import Workers from "./Worker.js";
|
||||
|
||||
//Save the collections in the Meteor.collections property for easy access without name conflicts.
|
||||
Meteor.collections = {Measures, Venues, Products, ProductTags, Sales, SalesSheets, Logs, Users, UserRoles};
|
||||
Meteor.collections = {Measures, Venues, Products, ProductTags, Sales, SalesSheets, Logs, Users, UserRoles, Workers};
|
||||
|
||||
//If this is the server then setup the default admin user if none exist.
|
||||
if(Meteor.isServer) {
|
||||
|
||||
Reference in New Issue
Block a user