Added an initial cut at a student segement of the site, with a list of workshops and the ability to sign up for them.
This commit is contained in:
@@ -9,7 +9,7 @@ import {AssetAssignmentHistory} from "/imports/api/asset-assignment-history";
|
||||
// console.log("Setting Up Assets...")
|
||||
|
||||
export const Assets = new Mongo.Collection('assets');
|
||||
export const conditions = ['New','Like New','Good','Okay','Damaged']
|
||||
export const conditions = ['New','Like New','Good','Okay','Damaged', 'Missing', 'Decommissioned']
|
||||
|
||||
/*
|
||||
const AssetsSchema = new SimpleSchema({
|
||||
@@ -90,7 +90,7 @@ Meteor.methods({
|
||||
check(condition, String);
|
||||
if(conditionDetails) check(conditionDetails, String);
|
||||
|
||||
if(condition !== 'New' && condition !== 'Like New' && condition !== 'Good' && condition !== 'Okay' && condition !== 'Damaged') {
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
console.error("Invalid condition option in assets.add(..)");
|
||||
throw new Meteor.Error("Invalid condition option.");
|
||||
@@ -123,7 +123,7 @@ Meteor.methods({
|
||||
check(condition, String);
|
||||
if(conditionDetails) check(conditionDetails, String);
|
||||
|
||||
if(condition !== 'New' && condition !== 'Like New' && condition !== 'Good' && condition !== 'Okay' && condition !== 'Damaged') {
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
console.error("Invalid condition option in assets.update(..)");
|
||||
throw new Meteor.Error("Invalid condition option.");
|
||||
@@ -176,7 +176,7 @@ Meteor.methods({
|
||||
|
||||
if(!date) date = new Date();
|
||||
|
||||
if(condition !== 'New' && condition !== 'Like New' && condition !== 'Good' && condition !== 'Okay' && condition !== 'Damaged') {
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
console.error("Invalid condition option in assets.unassign(..)");
|
||||
throw new Meteor.Error("Invalid condition option.");
|
||||
@@ -225,7 +225,7 @@ Meteor.methods({
|
||||
|
||||
if(!date) date = new Date();
|
||||
|
||||
if(condition !== 'New' && condition !== 'Like New' && condition !== 'Good' && condition !== 'Okay' && condition !== 'Damaged') {
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
console.error("Invalid condition option in assets.unassign(..)");
|
||||
throw new Meteor.Error("Invalid condition option.");
|
||||
|
||||
97
imports/api/workshops.js
Normal file
97
imports/api/workshops.js
Normal file
@@ -0,0 +1,97 @@
|
||||
import {Mongo} from "meteor/mongo";
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import { check, Match } from 'meteor/check';
|
||||
import { Roles } from 'meteor/alanning:roles';
|
||||
|
||||
//
|
||||
// An asset type is a specific type of equipment. Example: Lenovo 100e Chromebook.
|
||||
//
|
||||
export const Workshops = new Mongo.Collection('workshops');
|
||||
|
||||
if(Meteor.isServer) {
|
||||
// Drop any old indexes we no longer will use. Create indexes we need.
|
||||
//try {Workshops._dropIndex("External ID")} catch(e) {}
|
||||
//Workshops.createIndex({name: "text"}, {name: "name", unique: false});
|
||||
//Workshops.createIndex({id: 1}, {name: "External ID", unique: true});
|
||||
|
||||
//Debug: Show all indexes.
|
||||
// Workshops.rawCollection().indexes((err, indexes) => {
|
||||
// console.log(indexes);
|
||||
// });
|
||||
|
||||
// This code only runs on the server
|
||||
Meteor.publish('workshops', function() {
|
||||
return Workshops.find({});
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'workshops.add'(name, description, signupLimit) {
|
||||
let signupSheet = [];
|
||||
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
// Match a positive integer or undefined/null.
|
||||
check(signupLimit, Match.Where((x) => {
|
||||
check(x, Match.Maybe(Match.Integer));
|
||||
return x ? x > 0 : true
|
||||
}))
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.insert({name, description, signupLimit, signupSheet});
|
||||
}
|
||||
},
|
||||
'workshops.update'(_id, name, description, signupLimit) {
|
||||
check(_id, String);
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
// Match a positive integer or undefined/null.
|
||||
check(signupLimit, Match.Where((x) => {
|
||||
check(x, Match.Maybe(Match.Integer));
|
||||
return x ? x > 0 : true
|
||||
}))
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.update({_id}, {$set: {name, description, signupLimit}});
|
||||
}
|
||||
},
|
||||
'workshops.signup'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Meteor.userId()) {
|
||||
let workshop = Workshops.findOne(_id);
|
||||
|
||||
if(workshop) {
|
||||
if(!workshop.signupLimit || workshop.signedUp.length < workshop.signupLimit) {
|
||||
Workshops.update({_id}, {$push: {signupSheet: {_id: Meteor.userId()}}});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'workshops.unsignup'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Meteor.userId()) {
|
||||
let workshop = Workshops.findOne(_id);
|
||||
|
||||
if(workshop) {
|
||||
Workshops.update({_id}, {$pull: {signupSheet: {_id: Meteor.userId()}}});
|
||||
}
|
||||
}
|
||||
},
|
||||
'workshops.complete'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.update({_id}, {$set: {isComplete: true}})
|
||||
}
|
||||
},
|
||||
'workshops.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.remove({_id})
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// console.log("Asset types setup.")
|
||||
Reference in New Issue
Block a user