Skip to content
This repository has been archived by the owner on Aug 14, 2018. It is now read-only.

Commit

Permalink
feat(checkin): added full model, base view, base controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
therebelrobot committed Oct 26, 2016
1 parent 127aff5 commit ec8d160
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var projectsCtrl = require('./controllers/projects')
var contactCtrl = require('./controllers/contact')
var usersCtrl = require('./controllers/user')
var brigadeCtrl = require('./controllers/brigade')
var checkinCtrl = require('./controllers/checkin')

/*
* Helpers
Expand Down Expand Up @@ -227,6 +228,13 @@ app.post('/brigade',
passportConf.checkScopes(['user', 'repo', 'admin:org', 'admin:repo_hook', 'admin:org_hook']),
brigadeCtrl.postBrigade)

/**
* Meta Routes
*/

app.get('/checkin', checkinCtrl.getCheckin)
app.post('/checkin', checkinCtrl.postCheckin)

/**
* Project routes.
*/
Expand Down
9 changes: 9 additions & 0 deletions config/defaultLocations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
"Basement Lounge",
"Center Table",
"Glass Conference Room",
"Left Side Table",
"Left Side Lounge",
"Other",
"Right Side Lounge"
]
9 changes: 9 additions & 0 deletions config/defaultReferredBy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
"Meetup",
"Friend",
"Event",
"Facebook",
"Twitter",
"Youtube",
"Local Government"
]
35 changes: 35 additions & 0 deletions config/defaultSkills.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
"Android (Java)",
"AngularJS",
"C++",
"C#",
"Django",
"GIT",
"Graphic Design",
"Hibernate",
"HTML/CSS",
"iOS (Swift/Objective C)",
"Java",
"Javascript",
"JSON",
"Python",
"Maya LT",
"Marketing",
"Mongo",
"MySQL",
"Node",
".NET",
"PHP",
"Policy Work",
"Project Management",
"R",
"Ruby",
"Ruby on Rails",
"Spring",
"SQL",
"Statistics/Machine Learning",
"UI/UX Design",
"Unity",
"User Testing",
"WordPress"
]
17 changes: 17 additions & 0 deletions controllers/checkin/getCheckin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const defaultSkills = require('../../config/defaultSkills.json')
const defaultLocations = require('../../config/defaultLocations.json')
const defaultReferredBy = require('../../config/defaultReferredBy.json')
// TODO(therebelrobot): Move these into manage checkin page


module.exports = function getCheckin (req, res, next) {
res.render(res.locals.brigade.theme.slug + '/views/checkin/index', {
title: 'Check in',
view: 'checkin',
brigade: res.locals.brigade,
user: user || {},
locations: defaultLocations,
skills: defaultSkills,
referredBy: defaultReferredBy
})
}
4 changes: 4 additions & 0 deletions controllers/checkin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
getCheckin: require('./getCheckin'),
postCheckin: require('./postCheckin')
}
3 changes: 3 additions & 0 deletions controllers/checkin/postCheckin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function getCheckin (req, res, next) {

}
21 changes: 21 additions & 0 deletions models/Checkins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var mongoose = require('mongoose')

const Users = require('../Users')

const schema = require('./schema')
const syncUser = require('./syncUser')
const createUser = require('./createUser')

var checkinSchema = new mongoose.Schema(schema)

checkinSchema.post('save', function (doc, next) {
// check username presence + for corresponding user
if (!doc.username || !doc.username.length) return next()
Users.findOne({ username: doc.username }, (err, user) => {
if (err) throw err
if (!user) user = new Users()
syncUser(doc, user).then(next)
})
})

module.exports = mongoose.model('Checkins', checkinSchema)
14 changes: 14 additions & 0 deletions models/Checkins/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
date: { type: Date },
name: { type: String, default: '' },
email: { type: String, default: '' },
githubUsername: { type: String, default: '' }, // if present, sync to user model
teams: { type: Array, default: [] },
mailingList: { type: Boolean, default: false },
referredBy: { type: String, default: '' },
skills: { type: Array, default: [] },
lead: {
expectedAttendance: { type: Number, default: 0 },
reserve: { type: String, default: '' }
}
}
19 changes: 19 additions & 0 deletions models/Checkins/syncUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = function syncUser (doc, user) {
return new Promise((resolve, reject) => {
if(!user.username) user.username = doc.username // handle new account creation
user.name = doc.name
user.teams.projects = [
...user.teams.projects,
doc.projects
]
user.lastCheckin = doc.date
user.email = doc.email
user.mailingList = doc.mailingList
user.referredBy = doc.referredBy
user.skills = doc.skills
user.save(err => {
if (err) return reject(err)
resolve(doc)
})
})
}
7 changes: 6 additions & 1 deletion models/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ var defaultHeaders = {
var userSchema = new mongoose.Schema({
username: { type: String, unique: true },
email: {type: String, default: ''},
/* password: {type:String, default:''},*/
lastCheckin: {type: Date},
mailingList: {type: Boolean, default: false},
referredBy: {type: String, default: ''},
skills: {type: Array, default: []},
github: {type: String, default: ''},
tokens: {type: Array, default: []},
scopes: {type: Array, default: []},
postAuthLink: {type: String, default: ''},

roles: {
read: {type: Boolean, default: true},
blog: {type: Boolean, default: false},
Expand All @@ -29,6 +33,7 @@ var userSchema = new mongoose.Schema({
superAdmin: {type: Boolean, default: false}
},
teams: {
lead: { type: Array, default: [] },
project: { type: Array, default: [] },
core: { type: Array, default: [] }
},
Expand Down
16 changes: 16 additions & 0 deletions themes/codeforpoland/views/checkin/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends ../layout

block content
.row.breadcrumbs
.col-sm-12
a(href='/')= brigade.name
|   / 
a(href='/checkin') Check In
.row.page-header
.col-sm-12
h1.page-title Hack Night Check In
.row
hr
.container
.row
| Test Content here

0 comments on commit ec8d160

Please sign in to comment.