Initial cut - untested.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user