80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
import {Mongo} from "meteor/mongo";
|
|
import {Meteor} from "meteor/meteor";
|
|
import { check } from 'meteor/check';
|
|
import { Roles } from 'meteor/alanning:roles';
|
|
//import SimpleSchema from "simpl-schema";
|
|
import {AssetTypes} from "./asset-types";
|
|
|
|
export const AssetAssignments = new Mongo.Collection('assetAssignments');
|
|
/*
|
|
const TYPE_STUDENT = 1;
|
|
const TYPE_STAFF = 2;
|
|
|
|
const AssetAssignmentsSchema = new SimpleSchema({
|
|
assetId: {
|
|
type: String,
|
|
label: "Asset ID",
|
|
optional: false,
|
|
index: 1,
|
|
unique: false
|
|
},
|
|
assigneeId: {
|
|
type: String,
|
|
label: "Assignee ID",
|
|
optional: false,
|
|
},
|
|
assigneeType: { // 0: Student, 1: Staff
|
|
type: SimpleSchema.Integer,
|
|
label: "Assignee Type",
|
|
optional: false,
|
|
min: 0,
|
|
max: 1,
|
|
exclusiveMin: false,
|
|
exclusiveMax: false,
|
|
},
|
|
});
|
|
|
|
AssetAssignments.attachSchema(AssetAssignmentsSchema);
|
|
*/
|
|
|
|
if (Meteor.isServer) {
|
|
// Drop any old indexes we no longer will use. Create indexes we need.
|
|
//try {AssetTypes._dropIndex("name")} catch(e) {}
|
|
//AssetTypes.createIndex({name: "text"}, {name: "name", unique: false});
|
|
AssetTypes.createIndex({assetId: 1}, {name: "AssetID", unique: false});
|
|
|
|
// This code only runs on the server
|
|
Meteor.publish('assetAssignments', function() {
|
|
return AssetAssignments.find({});
|
|
});
|
|
}
|
|
Meteor.methods({
|
|
/**
|
|
* Assigns the asset to the assignee. The assignee should either be a Student or Staff member.
|
|
* @param assetId The Mongo ID of the asset (asset._id).
|
|
* @param assigneeType One of: 'Student', 'Staff'
|
|
* @param assigneeId The Mongo ID of the Student or Staff (person._id).
|
|
*/
|
|
'AssetAssignments.add'(assetId, assigneeType, assigneeId) {
|
|
check(assigneeId, String);
|
|
check(assigneeType, String);
|
|
check(assetId, String);
|
|
|
|
if(assigneeType !== 'Student' || assigneeType !== 'Staff') {
|
|
// Should never happen.
|
|
console.error("Error: Received incorrect assignee type in adding an assignment.");
|
|
}
|
|
else if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
|
AssetAssignments.insert({assetId, assigneeType: assigneeType === "Student" ? 0 : 1, assigneeId});
|
|
}
|
|
},
|
|
'AssetAssignments.remove'(_id) {
|
|
check(_id, String);
|
|
|
|
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
|
//TODO: Need to first verify there are no checked out assets to the staff member.
|
|
}
|
|
},
|
|
});
|
|
|