Finished core functionality.
This commit is contained in:
@@ -30,7 +30,7 @@ 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.
|
||||
* @param params An object with a single attribute. The attribute must be one of: email, deviceId, 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) {
|
||||
@@ -41,9 +41,24 @@ if (Meteor.isServer) {
|
||||
if(params.staffId) check(params.staffId, String)
|
||||
if(params.assetId) check(params.assetId, String)
|
||||
if(params.serial) check(params.serial, String)
|
||||
if(params.deviceId) check(params.deviceId, String)
|
||||
if(params.email) check(params.email, String)
|
||||
|
||||
if(params.email) {
|
||||
let person = Students.findOne({email: params.email})
|
||||
|
||||
if(person) params.studentId = person._id;
|
||||
else {
|
||||
person = Staff.findOne({email: params.email})
|
||||
|
||||
if(person) params.staffId = person._id;
|
||||
// else throw new Meteor.Error("Could not find a student or staff member with the given email.")
|
||||
}
|
||||
}
|
||||
|
||||
if(params.serial) query.serial = params.serial;
|
||||
else if(params.assetId) query.assetId = params.assetId;
|
||||
else if(params.deviceId) query.deviceId = params.deviceId;
|
||||
else if(params.studentId) {
|
||||
query.assigneeId = params.studentId
|
||||
query.assigneeType = "Student"
|
||||
@@ -59,11 +74,48 @@ if (Meteor.isServer) {
|
||||
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();
|
||||
let assets = [];
|
||||
|
||||
// Get the current assignment for the device or person.
|
||||
if(query.assetId || query.deviceId || query.serial) {
|
||||
let asset = Assets.findOne(query)
|
||||
|
||||
if(asset) assets = [asset]
|
||||
}
|
||||
else {
|
||||
// Find the assets assigned to the person.
|
||||
assets = Assets.find({assigneeId: params.studentId ? params.studentId : params.staffId}).fetch()
|
||||
}
|
||||
|
||||
// Prepend a partial assignment history record to the list. We want to show active assignments in the results.
|
||||
for(let asset of assets) {
|
||||
if(asset && asset.assigneeId) {
|
||||
let assetType = AssetTypes.findOne(asset.assetTypeId)
|
||||
let current = {
|
||||
_id: 0,
|
||||
assetKey: asset._id,
|
||||
assetId: asset.assetId,
|
||||
serial: asset.serial,
|
||||
assetTypeName: assetType.name,
|
||||
assigneeType: asset.assigneeType,
|
||||
assigneeId: asset.assigneeId,
|
||||
startDate: asset.assignmentDate,
|
||||
startCondition: asset.condition,
|
||||
startConditionDetails: asset.conditionDetails
|
||||
}
|
||||
|
||||
result = [current, ...result]
|
||||
}
|
||||
}
|
||||
|
||||
//Add some additional data to the records.
|
||||
for(let next of result) {
|
||||
if(next.serial) {
|
||||
next.asset = Assets.findOne({serial: next.serial});
|
||||
// console.log(next)
|
||||
if(next.assetKey) {
|
||||
next.asset = Assets.findOne({_id: next.assetKey})
|
||||
}
|
||||
else if(next.assetId) {
|
||||
next.asset = Assets.findOne({assetId: next.assetId});
|
||||
}
|
||||
|
||||
if(next.asset) {
|
||||
|
||||
Reference in New Issue
Block a user