Initial cut - untested.

This commit is contained in:
2025-09-25 09:31:02 -07:00
parent 7a0666cc6c
commit 3775522265
33 changed files with 351 additions and 346 deletions

View File

@@ -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]);
}
});
}
}
},
});