Continued work on the historical pages.
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import {Mongo} from "meteor/mongo";
|
||||
import {Meteor} from "meteor/meteor";
|
||||
import {check} from "meteor/check";
|
||||
import {Assets} from "/imports/api/assets";
|
||||
import {Students} from "/imports/api/students";
|
||||
import {Staff} from "/imports/api/staff";
|
||||
import {AssetTypes} from "/imports/api/asset-types";
|
||||
|
||||
export const AssetAssignmentHistory = new Mongo.Collection('assetAssignmentHistory');
|
||||
|
||||
@@ -17,4 +23,62 @@ startCondition: One of the condition options: [New, Like New, Good, Okay, Damage
|
||||
endCondition: One of the condition options: [New, Like New, Good, Okay, Damaged] (see assets.unassign for details).
|
||||
startConditionDetails: An optional text block for details on the condition.
|
||||
endConditionDetails: An optional text block for details on the condition.
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
/**
|
||||
* Collects historical data on asset assignments.
|
||||
* @param params An object with a single attribute. The attribute must be one of: assetId, serial, staffId, or studentId. It will find all Assignment data for the given attribute value.
|
||||
* @returns {any} Array of Asset Assignment History objects.
|
||||
*/
|
||||
'AssetAssignmentHistory.get'(params) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let query = {};
|
||||
|
||||
if(params.studentId) check(params.studentId, String)
|
||||
if(params.staffId) check(params.staffId, String)
|
||||
if(params.assetId) check(params.assetId, String)
|
||||
if(params.serial) check(params.serial, String)
|
||||
|
||||
if(params.serial) query.serial = params.serial;
|
||||
else if(params.assetId) query.assetId = params.assetId;
|
||||
else if(params.studentId) {
|
||||
query.assigneeId = params.studentId
|
||||
query.assigneeType = "Student"
|
||||
}
|
||||
else if(params.staffId) {
|
||||
query.assigneeId = params.staffId
|
||||
query.assigneeType = "Staff"
|
||||
}
|
||||
else {
|
||||
query = undefined;
|
||||
}
|
||||
|
||||
if(query) {
|
||||
//Sort by the last time the record was updated from most to least recent.
|
||||
let result = AssetAssignmentHistory.find(query, {sort: {endDate: -1}}).fetch();
|
||||
|
||||
//Add some additional data to the records.
|
||||
for(let next of result) {
|
||||
if(next.serial) {
|
||||
next.asset = Assets.findOne({serial: next.serial});
|
||||
}
|
||||
|
||||
if(next.asset) {
|
||||
next.assetType = AssetTypes.findOne({_id: next.asset.assetType})
|
||||
}
|
||||
|
||||
if(next.assigneeId) {
|
||||
next.assignee = next.asset.assigneeType === "Student" ? Students.findOne({_id: next.assigneeId}) : Staff.findOne({_id: next.assigneeId})
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} else return null;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user