Initial cut - untested.
This commit is contained in:
@@ -6,28 +6,28 @@ import { Roles } from 'meteor/alanning:roles';
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Meteor.methods({
|
||||
'admin.fixRecords'(input) {
|
||||
async 'admin.fixRecords'(input) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
console.log("In Fix Records");
|
||||
console.log("Deleting invalid records...");
|
||||
|
||||
// Delete any records missing key fields.
|
||||
Meteor.Records.remove({serial: {$exists: false}});
|
||||
Meteor.Records.remove({deviceId: {$exists: false}});
|
||||
Meteor.Records.remove({endTime: {$exists: false}});
|
||||
await Meteor.Records.removeAsync({serial: {$exists: false}});
|
||||
await Meteor.Records.removeAsync({deviceId: {$exists: false}});
|
||||
await Meteor.Records.removeAsync({endTime: {$exists: false}});
|
||||
|
||||
console.log("Consolidating records...");
|
||||
|
||||
let emails = _.uniq(Meteor.Records.find({}, {
|
||||
let emails = _.uniq((await Meteor.Records.find({}, {
|
||||
sort: {email: 1},
|
||||
fields: {email: true}
|
||||
}).fetch().map(function (x) {
|
||||
}).fetchAsync()).map(function (x) {
|
||||
return x.email;
|
||||
}), true);
|
||||
|
||||
emails.forEach(email => {
|
||||
for(const email of emails) {
|
||||
// Find all records for the user sorted from oldest to newest.
|
||||
let records = Meteor.Records.find({email}, {sort: {startTime: 1}}).fetch();
|
||||
let records = await Meteor.Records.find({email}, {sort: {startTime: 1}}).fetchAsync();
|
||||
let newRecords = [];
|
||||
let record = records[0];
|
||||
|
||||
@@ -46,12 +46,12 @@ if (Meteor.isServer) {
|
||||
}
|
||||
newRecords.push(record);
|
||||
|
||||
Meteor.Records.remove({email});
|
||||
await Meteor.Records.removeAsync({email});
|
||||
|
||||
for (let index = 0; index < newRecords.length; index++) {
|
||||
Meteor.Records.insert(newRecords[index]);
|
||||
await Meteor.Records.insertAsync(newRecords[index]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,26 +48,26 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'assetTypes.add'(name, description, year) {
|
||||
async 'assetTypes.add'(name, description, year) {
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
check(year, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
AssetTypes.insert({name, description, year});
|
||||
await AssetTypes.insertAsync({name, description, year});
|
||||
}
|
||||
},
|
||||
'assetTypes.update'(_id, name, description, year) {
|
||||
async 'assetTypes.update'(_id, name, description, year) {
|
||||
check(_id, String);
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
check(year, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
AssetTypes.update({_id}, {$set: {name, description, year}});
|
||||
await AssetTypes.updateAsync({_id}, {$set: {name, description, year}});
|
||||
}
|
||||
},
|
||||
'assetTypes.remove'(_id) {
|
||||
async 'assetTypes.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
|
||||
@@ -84,7 +84,7 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'assets.add'(assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
async 'assets.add'(assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
check(assetTypeId, String);
|
||||
check(assetId, String);
|
||||
check(serial, String);
|
||||
@@ -101,29 +101,29 @@ Meteor.methods({
|
||||
assetId = assetId.toUpperCase();
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let assetType = AssetTypes.findOne({assetTypeId});
|
||||
let assetType = await AssetTypes.findOneAsync({assetTypeId});
|
||||
|
||||
if(Assets.findOne({assetId})) {
|
||||
if(await Assets.findOneAsync({assetId})) {
|
||||
//return {error: true, errorType: 'duplicateAssetId'}
|
||||
throw new Meteor.Error("Duplicate Asset Id", "Cannot use the same asset ID twice.")
|
||||
}
|
||||
else if(serial) {
|
||||
Assets.insert({assetTypeId, assetId, serial, condition, conditionDetails});
|
||||
await Assets.insertAsync({assetTypeId, assetId, serial, condition, conditionDetails});
|
||||
}
|
||||
else {
|
||||
Assets.insert({assetTypeId, assetId, condition, conditionDetails});
|
||||
await Assets.insertAsync({assetTypeId, assetId, condition, conditionDetails});
|
||||
}
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.update'(_id, assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
async 'assets.update'(_id, assetTypeId, assetId, serial, condition, conditionDetails) {
|
||||
check(_id, String);
|
||||
check(assetTypeId, String);
|
||||
check(assetId, String);
|
||||
if(serial) check(serial, String);
|
||||
check(condition, String);
|
||||
if(conditionDetails) check(conditionDetails, String);
|
||||
const existing = Assets.findOne({_id})
|
||||
const existing = await Assets.findOneAsync({_id})
|
||||
|
||||
if(!conditions.includes(condition)) {
|
||||
//Should never happen.
|
||||
@@ -133,17 +133,17 @@ Meteor.methods({
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
//TODO: Need to first verify there are no checked out assets to the staff member.
|
||||
Assets.update({_id}, {$set: {assetTypeId, assetId, serial, condition, conditionDetails}});
|
||||
await Assets.updateAsync({_id}, {$set: {assetTypeId, assetId, serial, condition, conditionDetails}});
|
||||
|
||||
if(assetId !== existing.assetId) {
|
||||
//When changing the asset id we also need to update the other locations in the data where that ID exists.
|
||||
// assetAssignmentHistory.assetId
|
||||
AssetAssignmentHistory.updateMany({assetId: existing.assetId}, {$set: {assetId}})
|
||||
await AssetAssignmentHistory.updateManyAsync({assetId: existing.assetId}, {$set: {assetId}})
|
||||
}
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.updateCondition'(_id, condition, conditionDetails) {
|
||||
async 'assets.updateCondition'(_id, condition, conditionDetails) {
|
||||
console.log("updating condtition: " + condition + " / " + conditionDetails)
|
||||
check(_id, String)
|
||||
check(condition, String)
|
||||
@@ -157,15 +157,15 @@ Meteor.methods({
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
console.log("updating .... ")
|
||||
Assets.update({_id}, {$set: {condition, conditionDetails}});
|
||||
await Assets.updateAsync({_id}, {$set: {condition, conditionDetails}});
|
||||
}
|
||||
else throw new Meteor.Error("User Permission Error");
|
||||
},
|
||||
'assets.remove'(_id) {
|
||||
async 'assets.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let asset = Assets.findOne({_id});
|
||||
let asset = await Assets.findOneAsync({_id});
|
||||
|
||||
if(asset) {
|
||||
// Ensure the asset is not assigned still. Must unassign then remove. That allows us to maintain historical records for assignees.
|
||||
@@ -173,7 +173,7 @@ Meteor.methods({
|
||||
throw new Meteor.Error("Must unassign the asset before removal.");
|
||||
}
|
||||
else {
|
||||
Assets.remove({_id});
|
||||
await Assets.removeAsync({_id});
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -192,7 +192,7 @@ Meteor.methods({
|
||||
* @param conditionDetails A text block detailing the current condition (if it is needed).
|
||||
* @param date The date/time of the action. Will be set to the current date/time if not provided.
|
||||
*/
|
||||
'assets.assign'(assetId, assigneeType, assigneeId, condition, conditionDetails, date) {
|
||||
async 'assets.assign'(assetId, assigneeType, assigneeId, condition, conditionDetails, date) {
|
||||
check(assigneeId, String);
|
||||
check(assigneeType, String);
|
||||
check(assetId, String);
|
||||
@@ -215,7 +215,7 @@ Meteor.methods({
|
||||
throw new Meteor.Error("Error: Received incorrect assignee type in adding an assignment.");
|
||||
}
|
||||
else if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let asset = Assets.findOne({assetId});
|
||||
let asset = await Assets.findOneAsync({assetId});
|
||||
|
||||
if(asset) {
|
||||
if(asset.assigneeId) {
|
||||
@@ -224,7 +224,7 @@ Meteor.methods({
|
||||
throw new Meteor.Error("Asset is already assigned.", "Cannot assign an asset that has already been assigned.");
|
||||
}
|
||||
else {
|
||||
Assets.update({assetId}, {$set: {assigneeType, assigneeId, assignmentDate: date, condition, conditionDetails, assignedBy: Meteor.userId()}});
|
||||
await Assets.updateAsync({assetId}, {$set: {assigneeType, assigneeId, assignmentDate: date, condition, conditionDetails, assignedBy: Meteor.userId()}});
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -242,7 +242,7 @@ Meteor.methods({
|
||||
* @param conditionDetails A text block detailing the current condition (if it is needed).
|
||||
* @param date The date/time of the action. Will be set to the current date/time if not provided.
|
||||
*/
|
||||
'assets.unassign'(assetId, comment, condition, conditionDetails, date) {
|
||||
async 'assets.unassign'(assetId, comment, condition, conditionDetails, date) {
|
||||
check(assetId, String);
|
||||
if(date) check(date, Date);
|
||||
if(comment) check(comment, String);
|
||||
@@ -258,17 +258,17 @@ Meteor.methods({
|
||||
}
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "laptop-management", {anyScope:true})) {
|
||||
let asset = Assets.findOne({assetId});
|
||||
let asset = await Assets.findOneAsync({assetId});
|
||||
|
||||
if(asset) {
|
||||
let assetType = AssetTypes.findOne({_id: asset.assetTypeId});
|
||||
let assetType = await AssetTypes.findOneAsync({_id: asset.assetTypeId});
|
||||
|
||||
try {
|
||||
AssetAssignmentHistory.insert({assetKey: asset._id, assetId, serial: asset.serial, assetTypeName: (assetType ? assetType.name : "UNK"), assigneeType: asset.assigneeType, assigneeId: asset.assigneeId, startDate: asset.assignmentDate, endDate: date, startCondition: asset.condition, endCondition: condition, startConditionDetails: asset.conditionDetails, endConditionDetails: conditionDetails, comment, unassignedBy: Meteor.userId(), assignedBy: asset.assignedBy});
|
||||
await AssetAssignmentHistory.insertAsync({assetKey: asset._id, assetId, serial: asset.serial, assetTypeName: (assetType ? assetType.name : "UNK"), assigneeType: asset.assigneeType, assigneeId: asset.assigneeId, startDate: asset.assignmentDate, endDate: date, startCondition: asset.condition, endCondition: condition, startConditionDetails: asset.conditionDetails, endConditionDetails: conditionDetails, comment, unassignedBy: Meteor.userId(), assignedBy: asset.assignedBy});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
Assets.update({assetId}, {$unset: {assigneeType: "", assigneeId: "", assignmentDate: "", assignedBy: ""}, $set: {condition, conditionDetails}});
|
||||
await Assets.updateAsync({assetId}, {$unset: {assigneeType: "", assigneeId: "", assignmentDate: "", assignedBy: ""}, $set: {condition, conditionDetails}});
|
||||
}
|
||||
else {
|
||||
console.error("Could not find the asset: " + assetId);
|
||||
@@ -280,7 +280,9 @@ Meteor.methods({
|
||||
/**
|
||||
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
||||
*/
|
||||
'assets.fixAssetAssignments'() {
|
||||
async 'assets.fixAssetAssignments'() {
|
||||
//Note: Did not update this to Meteor 3.0
|
||||
|
||||
// Removed this since it should no longer be relevant.
|
||||
|
||||
// let assignmentDate = new Date();
|
||||
@@ -310,17 +312,17 @@ Meteor.methods({
|
||||
/**
|
||||
* A fix to remove the AssetAssignment collection and merge it with the Asset collection.
|
||||
*/
|
||||
'assets.fixAssetCondition'() {
|
||||
async 'assets.fixAssetCondition'() {
|
||||
// Removed this since it should no longer be relevant.
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Assets.update({assetTypeId: 'xPu8YK39pmQW93Fuz', condition: {$exists: false}}, {$set: {condition: 'Okay', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 CB
|
||||
Assets.update({assetTypeId: 'casMp4pJ9t8FtpyuR', condition: {$exists: false}}, {$set: {condition: 'Good', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 Charger
|
||||
Assets.update({assetTypeId: 'ZD9XiHqGr6TcKH9Nv', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 CB
|
||||
Assets.update({assetTypeId: 'mfE9NtiFBotb8kp4v', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 Charger
|
||||
Assets.update({assetTypeId: 'btEsKYxW4Sgf7T8nA', condition: {$exists: false}}, {$set: {condition: 'Good',conditionDetails: 'Automated Condition'}}, {multi: true}); //Dell 3100 Charger
|
||||
Assets.update({assetTypeId: '9bszeFJNPteMDbye5', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A CB
|
||||
Assets.update({assetTypeId: 'tCj7s5T2YcFXZEaqE', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A Charger
|
||||
await Assets.updateAsync({assetTypeId: 'xPu8YK39pmQW93Fuz', condition: {$exists: false}}, {$set: {condition: 'Okay', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 CB
|
||||
await Assets.updateAsync({assetTypeId: 'casMp4pJ9t8FtpyuR', condition: {$exists: false}}, {$set: {condition: 'Good', conditionDetails: 'Automated Condition'}}, {multi: true}); //Lenovo E100 Charger
|
||||
await Assets.updateAsync({assetTypeId: 'ZD9XiHqGr6TcKH9Nv', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 CB
|
||||
await Assets.updateAsync({assetTypeId: 'mfE9NtiFBotb8kp4v', condition: {$exists: false}}, {$set: {condition: 'New'}}, {multi: true}); //Acer CB315 Charger
|
||||
await Assets.updateAsync({assetTypeId: 'btEsKYxW4Sgf7T8nA', condition: {$exists: false}}, {$set: {condition: 'Good',conditionDetails: 'Automated Condition'}}, {multi: true}); //Dell 3100 Charger
|
||||
await Assets.updateAsync({assetTypeId: '9bszeFJNPteMDbye5', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A CB
|
||||
await Assets.updateAsync({assetTypeId: 'tCj7s5T2YcFXZEaqE', condition: {$exists: false}}, {$set: {condition: 'Like New',conditionDetails: 'Automated Condition'}}, {multi: true}); //HP 11A Charger
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,25 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'sites.update'(_id, name, externalId) {
|
||||
async 'sites.update'(_id, name, externalId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Sites.update({_id}, {$set: {name, externalId}});
|
||||
await Sites.updateAsync({_id}, {$set: {name, externalId}});
|
||||
}
|
||||
},
|
||||
'sites.add'(name, externalId) {
|
||||
async 'sites.add'(name, externalId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Sites.insert({name, externalId});
|
||||
await Sites.insertAsync({name, externalId});
|
||||
}
|
||||
},
|
||||
'sites.remove'(_id) {
|
||||
async 'sites.remove'(_id) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
let site = Sites.find({_id});
|
||||
let site = await Sites.findOneAsync({_id});
|
||||
|
||||
if(site) {
|
||||
//Clear any site references in student/room entries.
|
||||
Students.update({siteId: _id}, {$unset: {siteId: 1}});
|
||||
Staff.update({siteId: _id}, {$unset: {siteId: 1}});
|
||||
Sites.remove({_id});
|
||||
await Students.updateAsync({siteId: _id}, {$unset: {siteId: 1}});
|
||||
await Staff.updateAsync({siteId: _id}, {$unset: {siteId: 1}});
|
||||
await Sites.removeAsync({_id});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -17,17 +17,17 @@ if (Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'staff.add'(id, firstName, lastName, email, siteId) {
|
||||
async 'staff.add'(id, firstName, lastName, email, siteId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Staff.insert({id, firstName, lastName, email, siteId});
|
||||
await Staff.insertAsync({id, firstName, lastName, email, siteId});
|
||||
}
|
||||
},
|
||||
'staff.update'(_id, id, firstName, lastName, email, siteId) {
|
||||
async 'staff.update'(_id, id, firstName, lastName, email, siteId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Staff.update({_id}, {$set: {id, firstName, lastName, email, siteId}});
|
||||
await Staff.updateAsync({_id}, {$set: {id, firstName, lastName, email, siteId}});
|
||||
}
|
||||
},
|
||||
'staff.remove'(_id) {
|
||||
async 'staff.remove'(_id) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
//TODO: Need to first verify there are no checked out assets to the staff member.
|
||||
}
|
||||
@@ -52,12 +52,12 @@ Meteor.methods({
|
||||
* StuEmail,Student ID,First Name,Last Name,Grade,First Name Alias,Last Name Alias
|
||||
* @type: Currently only supports 'CSV' or 'Aeries Text Report'
|
||||
*/
|
||||
'staff.loadCsv'(csv, type, siteId) {
|
||||
async 'staff.loadCsv'(csv, type, siteId) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
check(csv, String);
|
||||
check(siteId, String);
|
||||
|
||||
let site = Sites.findOne({_id: siteId});
|
||||
let site = await Sites.findOneAsync({_id: siteId});
|
||||
|
||||
if(site) {
|
||||
let cleanCsv;
|
||||
@@ -107,8 +107,8 @@ Meteor.methods({
|
||||
|
||||
const bound = Meteor.bindEnvironment((callback) => {callback();});
|
||||
|
||||
parse(cleanCsv, {}, function(err, records) {
|
||||
bound(() => {
|
||||
parse(cleanCsv, {}, async function(err, records) {
|
||||
bound(async () => {
|
||||
if(err) console.error(err);
|
||||
else {
|
||||
let foundIds = new Set();
|
||||
@@ -138,7 +138,7 @@ Meteor.methods({
|
||||
|
||||
//console.log(staff);
|
||||
try {
|
||||
Staff.upsert({id: staff.id}, {$set: staff});
|
||||
await Staff.upsertAsync({id: staff.id}, {$set: staff});
|
||||
}
|
||||
catch(err) {
|
||||
console.error(err);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {parse} from 'csv-parse';
|
||||
export const Students = new Mongo.Collection('students');
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Students.createIndex({id: 1}, {name: "External ID", unique: true});
|
||||
await Students.createIndexAsync({id: 1}, {name: "External ID", unique: true});
|
||||
|
||||
// This code only runs on the server
|
||||
Meteor.publish('students', function(siteId) {
|
||||
@@ -17,26 +17,26 @@ if (Meteor.isServer) {
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
'students.add'(id, firstName, firstNameAlias, lastName, email, siteId, grade, active) {
|
||||
async 'students.add'(id, firstName, firstNameAlias, lastName, email, siteId, grade, active) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Students.insert({id, firstName, firstNameAlias, lastName, email, siteId, grade, active, activeChangeTimestamp: active ? "" : new Date()});
|
||||
await Students.insertAsync({id, firstName, firstNameAlias, lastName, email, siteId, grade, active, activeChangeTimestamp: active ? "" : new Date()});
|
||||
}
|
||||
},
|
||||
'students.update'(_id, id, firstName, firstNameAlias, lastName, email, siteId, grade, active) {
|
||||
async 'students.update'(_id, id, firstName, firstNameAlias, lastName, email, siteId, grade, active) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Students.update({_id}, {$set: {id, firstName, firstNameAlias, lastName, email, siteId, grade, active, activeChangeTimestamp: active ? "" : new Date()}});
|
||||
await Students.updateAsync({_id}, {$set: {id, firstName, firstNameAlias, lastName, email, siteId, grade, active, activeChangeTimestamp: active ? "" : new Date()}});
|
||||
}
|
||||
},
|
||||
'students.remove'(_id) {
|
||||
async 'students.remove'(_id) {
|
||||
// Does not actually remove the student (not currently possible. Does set the student to not-active.
|
||||
// If we want to remove students we should allow it for non-active students if there are no assets assigned.
|
||||
// We may want to do this automatically, perhaps for students that have been non-active for a long period of time.
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
// Set the student as non-active and set the timestamp for the change (so we know how long they have been inactive for - so we can potentially automatically remove them later.
|
||||
Students.update({_id}, {$set: {active: false, activeChangeTimestamp: new Date()}})
|
||||
await Students.updateAsync({_id}, {$set: {active: false, activeChangeTimestamp: new Date()}})
|
||||
}
|
||||
},
|
||||
'students.getPossibleGrades'() {
|
||||
async 'students.getPossibleGrades'() {
|
||||
return Students.rawCollection().distinct('grade', {});
|
||||
},
|
||||
/**
|
||||
@@ -44,12 +44,12 @@ if (Meteor.isServer) {
|
||||
* @param _id The student's database ID.
|
||||
* @param alias The alias to set for the student.
|
||||
*/
|
||||
'students.setAlias'(_id, alias) {
|
||||
async 'students.setAlias'(_id, alias) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
check(_id, String);
|
||||
check(alias, String);
|
||||
|
||||
Students.update({_id}, !alias || !alias.length() ? {$unset: {alias: true}} : {$set: {alias}});
|
||||
await Students.updateAsync({_id}, !alias || !alias.length() ? {$unset: {alias: true}} : {$set: {alias}});
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -81,12 +81,12 @@ if (Meteor.isServer) {
|
||||
* TODO: Each imported student should be attached to the correct site
|
||||
* TODO: Any students not imported should be marked as deactivated
|
||||
*/
|
||||
'students.loadCsv'(csv, type, test) {
|
||||
async 'students.loadCsv'(csv, type, test) {
|
||||
try {
|
||||
if (Roles.userIsInRole(Meteor.userId(), "admin", {anyScope: true})) {
|
||||
check(csv, String)
|
||||
|
||||
let sites = Sites.find().fetch()
|
||||
let sites = await Sites.find().fetchAsync()
|
||||
let sitesByExternalId = {}
|
||||
|
||||
// Map all sites by external ID so we can quickly find the site for each imported student.
|
||||
@@ -95,7 +95,7 @@ if (Meteor.isServer) {
|
||||
sitesByExternalId[site.externalId] = site
|
||||
|
||||
//Note: Only include active students since we don't want to repeatedly make students non-active (resetting the timestamp).
|
||||
let existingStudents = Students.find({active: true}).fetch()
|
||||
let existingStudents = await Students.find({active: true}).fetchAsync()
|
||||
let existingStudentIds = new Set()
|
||||
|
||||
// Collect all pre-existing student ID's. Will remove them as we import, and use the remaining set to de-activate the students no longer in the district.
|
||||
@@ -144,7 +144,7 @@ if (Meteor.isServer) {
|
||||
* @param test
|
||||
* @returns {string}
|
||||
*/
|
||||
const readCsv = (err, records, sitesByExternalId, existingStudentIds, test) => {
|
||||
const readCsv = async (err, records, sitesByExternalId, existingStudentIds, test) => {
|
||||
let output = ""
|
||||
|
||||
if (err) console.error(err)
|
||||
@@ -189,7 +189,7 @@ if (Meteor.isServer) {
|
||||
if (!test) {
|
||||
try {
|
||||
existingStudentIds.delete(student.id)
|
||||
Students.upsert({id: student.id}, {$set: student})
|
||||
await Students.upsertAsync({id: student.id}, {$set: student})
|
||||
} catch (err) {
|
||||
console.log("Error while calling Students.upsert(..)")
|
||||
console.error(err)
|
||||
@@ -212,10 +212,10 @@ if (Meteor.isServer) {
|
||||
nonActiveCount++
|
||||
|
||||
if (test) {
|
||||
output += "Changing active status for student: " + Students.findOne({id: studentId}) + "\r\n"
|
||||
output += "Changing active status for student: " + await Students.findOneAsync({id: studentId}) + "\r\n"
|
||||
} else {
|
||||
try {
|
||||
Students.update({id: studentId}, {
|
||||
await Students.updateAsync({id: studentId}, {
|
||||
$set: {
|
||||
active: false,
|
||||
activeChangeTimestamp: new Date()
|
||||
@@ -238,5 +238,4 @@ if (Meteor.isServer) {
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ if (Meteor.isServer) {
|
||||
});
|
||||
|
||||
Meteor.methods({
|
||||
'users.setUserRoles'(userId, roles) {
|
||||
async 'users.setUserRoles'(userId, roles) {
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
check(userId, String);
|
||||
check(roles, Array);
|
||||
|
||||
@@ -25,7 +25,7 @@ if(Meteor.isServer) {
|
||||
});
|
||||
}
|
||||
Meteor.methods({
|
||||
'workshops.add'(name, description, signupLimit) {
|
||||
async 'workshops.add'(name, description, signupLimit) {
|
||||
let signupSheet = [];
|
||||
|
||||
console.log(name)
|
||||
@@ -40,10 +40,10 @@ Meteor.methods({
|
||||
}))
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.insert({name, description, signupLimit, signupSheet});
|
||||
await Workshops.insertAsync({name, description, signupLimit, signupSheet});
|
||||
}
|
||||
},
|
||||
'workshops.update'(_id, name, description, signupLimit) {
|
||||
async 'workshops.update'(_id, name, description, signupLimit) {
|
||||
check(_id, String);
|
||||
check(name, String);
|
||||
check(description, String);
|
||||
@@ -54,45 +54,45 @@ Meteor.methods({
|
||||
}))
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.update({_id}, {$set: {name, description, signupLimit}});
|
||||
await Workshops.updateAsync({_id}, {$set: {name, description, signupLimit}});
|
||||
}
|
||||
},
|
||||
'workshops.signup'(_id) {
|
||||
async 'workshops.signup'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Meteor.userId()) {
|
||||
let workshop = Workshops.findOne(_id);
|
||||
let workshop = await Workshops.findOneAsync(_id);
|
||||
|
||||
if(workshop) {
|
||||
if(!workshop.signupLimit || workshop.signedUp.length < workshop.signupLimit) {
|
||||
Workshops.update({_id}, {$push: {signupSheet: {_id: Meteor.userId()}}});
|
||||
await Workshops.updateAsync({_id}, {$push: {signupSheet: {_id: Meteor.userId()}}});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'workshops.unsignup'(_id) {
|
||||
async 'workshops.unsignup'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Meteor.userId()) {
|
||||
let workshop = Workshops.findOne(_id);
|
||||
let workshop = await Workshops.findOneAsync(_id);
|
||||
|
||||
if(workshop) {
|
||||
Workshops.update({_id}, {$pull: {signupSheet: {_id: Meteor.userId()}}});
|
||||
await Workshops.updateAsync({_id}, {$pull: {signupSheet: {_id: Meteor.userId()}}});
|
||||
}
|
||||
}
|
||||
},
|
||||
'workshops.complete'(_id) {
|
||||
async 'workshops.complete'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.update({_id}, {$set: {isComplete: true}})
|
||||
await Workshops.updateAsync({_id}, {$set: {isComplete: true}})
|
||||
}
|
||||
},
|
||||
'workshops.remove'(_id) {
|
||||
async 'workshops.remove'(_id) {
|
||||
check(_id, String);
|
||||
|
||||
if(Roles.userIsInRole(Meteor.userId(), "admin", {anyScope:true})) {
|
||||
Workshops.remove({_id})
|
||||
await Workshops.removeAsync({_id})
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user