Files
DistrictCentral/imports/api/asset-assignments.js

95 lines
2.7 KiB
JavaScript
Raw Normal View History

2022-06-20 08:24:35 -07:00
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";
2022-06-20 08:24:35 -07:00
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
2022-06-20 08:24:35 -07:00
type: SimpleSchema.Integer,
label: "Assignee Type",
optional: false,
min: 0,
max: 1,
2022-06-20 08:24:35 -07:00
exclusiveMin: false,
exclusiveMax: false,
},
});
AssetAssignments.attachSchema(AssetAssignmentsSchema);
*/
if (Meteor.isServer) {
// Drop any old indexes we no longer will use. Create indexes we need.
//try {AssetAssignments._dropIndex("name")} catch(e) {}
//AssetAssignments.createIndex({name: "text"}, {name: "name", unique: false});
try {AssetTypes._dropIndex("AssetID")} catch(e) {} //Typo put this as an index in AssetTypes instead of AssetAssignments.
AssetAssignments.createIndex({assetId: 1}, {name: "AssetID", unique: false});
2022-06-20 08:24:35 -07:00
// This code only runs on the server
Meteor.publish('assetAssignments', function(assetId) {
// let query = {};
//
// if(assetId) {
// query.assetId = assetId;
// }
//
// return AssetAssignments.find(query);
return [];
2022-06-20 08:24:35 -07:00
});
}
Meteor.methods({
'AssetAssignments.getOne'(assetId) {
check(assetId, String);
return AssetAssignments.findOne(assetId);
},
/**
* 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.");
// console.error(assigneeType);
// }
// else if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
// AssetAssignments.insert({assetId, assigneeType, assigneeId});
// }
2022-06-20 08:24:35 -07:00
},
'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.
// }
2022-06-20 08:24:35 -07:00
},
});