Initial cut - untested.
This commit is contained in:
@@ -33,7 +33,7 @@ if (Meteor.isServer) {
|
||||
* @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) {
|
||||
async 'AssetAssignmentHistory.get'(params) {
|
||||
let result
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
@@ -53,11 +53,11 @@ if (Meteor.isServer) {
|
||||
if(params.email) check(params.email, String)
|
||||
|
||||
if(params.email) {
|
||||
let person = Students.findOne({email: params.email})
|
||||
let person = await Students.findOneAsync({email: params.email})
|
||||
|
||||
if(person) params.studentId = person._id;
|
||||
else {
|
||||
person = Staff.findOne({email: params.email})
|
||||
person = await Staff.findOneAsync({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.")
|
||||
@@ -69,8 +69,8 @@ if (Meteor.isServer) {
|
||||
else if(params.assetId) query.assetId = params.assetId;
|
||||
else if(params.deviceId) query.deviceId = params.deviceId;
|
||||
|
||||
asset = Assets.findOne(query)
|
||||
if(asset) assetType = AssetTypes.findOne({_id: asset.assetTypeId})
|
||||
asset = await Assets.findOneAsync(query)
|
||||
if(asset) assetType = await AssetTypes.findOneAsync({_id: asset.assetTypeId})
|
||||
}
|
||||
else {
|
||||
if(params.studentId) {
|
||||
@@ -85,25 +85,25 @@ if (Meteor.isServer) {
|
||||
query = undefined;
|
||||
}
|
||||
|
||||
person = query.assigneeType === "Student" ? Students.findOne({id: query.assigneeId}) : Staff.findOne({id: query.assigneeId})
|
||||
person = query.assigneeType === "Student" ? await Students.findOneAsync({id: query.assigneeId}) : await Staff.findOneAsync({id: query.assigneeId})
|
||||
}
|
||||
|
||||
if(query) {
|
||||
//Sort by the last time the record was updated from most to least recent.
|
||||
result = AssetAssignmentHistory.find(query, {sort: {endDate: -1}}).fetch();
|
||||
result = await AssetAssignmentHistory.find(query, {sort: {endDate: -1}}).fetchAsync();
|
||||
|
||||
//Expand the assignee, asset, and asset type data.
|
||||
for(let next of result) {
|
||||
if(person) next.assignee = person
|
||||
else next.assignee = next.assigneeType === "Student" ? Students.findOne({_id: next.assigneeId}) : Staff.findOne({_id: next.assigneeId})
|
||||
else next.assignee = next.assigneeType === "Student" ? await Students.findOneAsync({_id: next.assigneeId}) : await Staff.findOneAsync({_id: next.assigneeId})
|
||||
|
||||
if(asset) {
|
||||
next.asset = asset
|
||||
next.assetType = assetType
|
||||
}
|
||||
else {
|
||||
next.asset = Assets.findOne({assetId: next.assetId})
|
||||
if(next.asset) next.assetType = AssetTypes.findOne({_id: next.asset.assetTypeId})
|
||||
next.asset = await Assets.findOneAsync({assetId: next.assetId})
|
||||
if(next.asset) next.assetType = await AssetTypes.findOneAsync({_id: next.asset.assetTypeId})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user