Skip to content

Commit

Permalink
Merge branch 'Automatic-CheckIn' into frontendcheckin
Browse files Browse the repository at this point in the history
  • Loading branch information
angeltrevinov committed Jul 22, 2019
2 parents a3f32bd + c7b8a2c commit e147832
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 5 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var cookieParser = require('cookie-parser');
var mongoose = require('mongoose');
var port = process.env.PORT || 3000;
var database = process.env.DATABASE || process.env.MONGODB_URI || "mongodb://localhost:27017";
mongoose.Promise = Promise;

var settingsConfig = require('./config/settings');
var adminConfig = require('./config/admin');
Expand Down
19 changes: 19 additions & 0 deletions app/server/controllers/SettingsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,23 @@ SettingsController.getPublicSettings = function(callback){
Settings.getPublicSettings(callback);
};

/**
* Adds the Setting's schema's newly added fields to the records
* @param {Function} callback [description]
*/

SettingsController.updateRecordsWithMissingFields = function(callback) {
var settingSchema = Settings.schema.obj;

Settings.update({},
{ $set: {
checkInOpen: settingSchema.checkInOpen.default,
teamSizeAccepted: settingSchema.teamSizeAccepted.default,
hackLocation: settingSchema.hackLocation,
maxTableCount: settingSchema.maxTableCount.default,
currentTableCount: settingSchema.currentTableCount.default
}}, { multi: true })
.exec(callback);
}

module.exports = SettingsController;
13 changes: 13 additions & 0 deletions app/server/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,19 @@ UserController.checkOutById = function(id, user, callback){
callback);
};

/**
* Adds the schema's newly added fields to the records that do not contain it
* @param {Function} callback [description]
*/
UserController.updateRecordsWithMissingFields = function(callback) {
var userSchema = User.schema.obj;

User.update({ 'status.tableNumber': {$exists: false} },
{ $set: {
'status.tableNumber': userSchema.status.tableNumber.default,
}}, { multi: true })
.exec(callback);
}

/**
* [ADMIN ONLY]
Expand Down
22 changes: 22 additions & 0 deletions app/server/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var validator = require('validator');
*
* @type {mongoose}
*/
var geolocation = {
latitude: 0,
longitude: 0
};

var schema = new mongoose.Schema({
status: String,
timeOpen: {
Expand Down Expand Up @@ -37,6 +42,23 @@ var schema = new mongoose.Schema({
confirmationText: {
type: String
},
checkInOpen: {
type: Number,
default: 0
},
teamSizeAccepted: {
type: Number,
default: 4
},
hackLocation: geolocation,
maxTableCount: {
type: Number,
default: 100
},
currentTableCount: {
type: Number,
default: 0
}
});

/**
Expand Down
4 changes: 4 additions & 0 deletions app/server/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ var status = {
reimbursementGiven: {
type: Boolean,
default: false
},
tableNumber: {
type: Number,
default: -1
}
};

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"async": "^1.4.2",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.18.3",
"bower": "^1.8.0",
"bower": "^1.8.8",
"cookie-parser": "~1.3.2",
"dotenv": "^1.2.0",
"email-templates": "^2.0.1",
Expand All @@ -16,7 +16,7 @@
"gulp-minify-css": "^1.2.0",
"gulp-ng-annotate": "^1.1.0",
"gulp-nodemon": "^2.2.1",
"gulp-sass": "^2.3.2",
"gulp-sass": "^3.0.0",
"gulp-sourcemaps": "^1.12.0",
"gulp-uglify": "^1.5.4",
"handlebars": "^3.0.3",
Expand Down
12 changes: 12 additions & 0 deletions scripts/addSettingsMissingFields.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require('dotenv').load({silent: true});

// Connect to mongodb
var mongoose = require('mongoose');
var database = process.env.MONGODB_URI || "mongodb://localhost:27017"
mongoose.connect(database);

var SettingsController = require('../app/server/controllers/SettingsController');

SettingsController.updateRecordsWithMissingFields(function() {
console.log('Updated settings to include missing fields');
})
65 changes: 65 additions & 0 deletions scripts/cloneRemoteDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function clone(){
require('dotenv').load({silent:true});
// Connect locally to mongodb

const mongoose = require('mongoose'),
localDB = process.env.MONGODB_URI || "mongodb://localhost:27017",
remoteDB = process.env.REMOTE_URI,
Settings = require('../app/server/models/Settings'),
User = require('../app/server/models/User');
mongoose.Promise = Promise;

// Connect to remote db
if(!remoteDB) return console.log("NO REMOTE URI");

let local = mongoose.createConnection(localDB);
let remote = mongoose.createConnection(remoteDB);

console.log("LOCAL DB name => ", local.name);
console.log("REMOTE DB name => ", remote.name);


// Gets remote settings
remote.model('Settings').findOne({}).select('-_id')
.then(settingsR => {
console.log("New Settings :", settingsR)
// Updates local settings
return local.model('Settings').findOneAndUpdate({}, settingsR)
})
.then(settingsPrior => {
console.log('Old Settings :', settingsPrior);
// Droops users
return local.db.dropCollection('users')
})
.then(() =>{
console.log("Dropped local user collection");
// Gets remote users
return remote.model('User').find({}).select('+password +salt +status.admittedBy')
})
.then(usersR => {
console.log('Amount of remote users :', usersR.length);
let LocalUser = local.model('User');
let p = usersR.map( user => {
return new Promise((resolve, reject) => {
let u = new LocalUser(user.toObject());
u.save((err,newUser) => {
if(err) return reject(err)
resolve(newUser);
})
});
})
// Creates users locally
return Promise.all(p)
})
.then(newUsers => {
console.log('New Users :', newUsers.length);
process.exit(0);
})
.catch(err =>{
console.log("ERROR");
console.log('err :', err);
process.exit(1);
})
}

clone();

0 comments on commit e147832

Please sign in to comment.