Initial cut - untested.
This commit is contained in:
@@ -42,7 +42,7 @@ if (Meteor.isServer) {
|
||||
* @param params An object with a single attribute. The attribute must be one of: deviceId, serial, email. It will find all Chromebook data that starts with the given attribute value.
|
||||
* @returns {any} Array of Chromebook data objects.
|
||||
*/
|
||||
'DataCollection.chromebookData'(params) {
|
||||
async 'DataCollection.chromebookData'(params) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let query = {};
|
||||
|
||||
@@ -51,7 +51,7 @@ if (Meteor.isServer) {
|
||||
|
||||
// For asset ID's, we need to get the serial from the asset collection first.
|
||||
if(params.assetId) {
|
||||
let asset = Assets.findOne({assetId : params.assetId});
|
||||
let asset = await Assets.findOneAsync({assetId : params.assetId});
|
||||
|
||||
if(asset) {
|
||||
params.serial = asset.serial;
|
||||
@@ -70,14 +70,14 @@ if (Meteor.isServer) {
|
||||
$options: "i"
|
||||
} : params.serial;
|
||||
else if(params.studentId) {
|
||||
const student = Students.findOne({_id: params.studentId})
|
||||
const student = await Students.findOneAsync({_id: params.studentId})
|
||||
|
||||
// console.log(student)
|
||||
if(student) query.email = student.email;
|
||||
else query = undefined
|
||||
}
|
||||
else if(params.staffId) {
|
||||
const staff = Staff.findOne({_id: params.staffId})
|
||||
const staff = await Staff.findOneAsync({_id: params.staffId})
|
||||
|
||||
if(staff) query.email = staff.email;
|
||||
else query = undefined
|
||||
@@ -101,27 +101,27 @@ if (Meteor.isServer) {
|
||||
// console.log(query);
|
||||
|
||||
//Sort by the last time the record was updated from most to least recent.
|
||||
let result = Meteor.Records.find(query, {sort: {endTime: -1}}).fetch();
|
||||
let result = await Meteor.Records.find(query, {sort: {endTime: -1}}).fetchAsync();
|
||||
// console.log("Found: ");
|
||||
// console.log(result);
|
||||
|
||||
//Add some additional data to the records.
|
||||
for (let next of result) {
|
||||
if (next.serial) {
|
||||
next.asset = Assets.findOne({serial: next.serial});
|
||||
next.asset = await Assets.findOneAsync({serial: next.serial});
|
||||
}
|
||||
|
||||
if (next.email) {
|
||||
next.person = Students.findOne({email: next.email});
|
||||
|
||||
if (!next.person) next.person = Staff.findOne({email: next.email});
|
||||
if (!next.person) next.person = await Staff.findOneAsync({email: next.email});
|
||||
}
|
||||
|
||||
if (next.asset) {
|
||||
next.assetType = AssetTypes.findOne({_id: next.asset.assetTypeId})
|
||||
next.assetType = await AssetTypes.findOneAsync({_id: next.asset.assetTypeId})
|
||||
|
||||
if (next.asset.assigneeId) {
|
||||
next.assignedTo = next.asset.assigneeType === "Student" ? Students.findOne({_id: next.asset.assigneeId}) : Staff.findOne({_id: next.asset.assigneeId})
|
||||
next.assignedTo = next.asset.assigneeType === "Student" ? await Students.findOneAsync({_id: next.asset.assigneeId}) : await Staff.findOneAsync({_id: next.asset.assigneeId})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user