Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
schedules-legacy
Commits
7f822200
Commit
7f822200
authored
Nov 07, 2016
by
Mark Stenglein
Browse files
Changes to allow the models to be imported anywhere with ease.
- I should really be doing something else right now....like homework.
parent
fe09ad9f
Changes
8
Show whitespace changes
Inline
Side-by-side
schedules/app.js
View file @
7f822200
...
...
@@ -7,13 +7,13 @@
////////////////////////////////////////////////////////////////////////////////
// Load in the different packages
require
(
'
app-module-path
'
).
addPath
(
__dirname
);
var
express
=
require
(
'
express
'
);
var
path
=
require
(
'
path
'
);
var
logger
=
require
(
'
morgan
'
);
var
cookieParser
=
require
(
'
cookie-parser
'
);
var
bodyParser
=
require
(
'
body-parser
'
);
var
Sequelize
=
require
(
'
sequelize
'
);
//var config = require('config');
// Load in Routes
// TODO: Make this a dynamic loading system that simply scans the directory
...
...
@@ -42,7 +42,7 @@ app.use(require('node-sass-middleware')({
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
// Initialize the Database and Connection
app
.
set
(
'
db
'
,
path
.
join
(
__dirname
,
'
models
'
,
'
index
'
));
var
db
=
require
(
path
.
join
(
__dirname
,
'
models
'
));
// Populate initial data
// TODO: populate the information
...
...
schedules/models/Section.js
View file @
7f822200
module
.
exports
=
function
(
sequelize
,
DataTypes
)
{
var
Section
=
sequelize
.
define
(
"
Section
"
,
{
return
sequelize
.
define
(
"
Section
"
,
{
// unique index/key
crn
:
{
type
:
DataTypes
.
STRING
,
...
...
@@ -10,7 +10,7 @@ module.exports = function(sequelize, DataTypes) {
title
:
DataTypes
.
STRING
,
section
:
DataTypes
.
STRING
,
instructor
:
type
:
DataTypes
.
STRING
,
instructor
:
DataTypes
.
STRING
,
campus
:
DataTypes
.
STRING
,
location
:
DataTypes
.
STRING
,
...
...
@@ -22,7 +22,7 @@ module.exports = function(sequelize, DataTypes) {
endDate
:
DataTypes
.
DATE
,
Msession
:
{
type
:
DataTypes
.
BOOL
,
type
:
DataTypes
.
BOOL
EAN
,
allowNull
:
false
,
defaultValue
:
false
},
...
...
@@ -30,7 +30,7 @@ module.exports = function(sequelize, DataTypes) {
MtimeEnd
:
DataTypes
.
TIME
,
Tsession
:
{
type
:
DataTypes
.
BOOL
,
type
:
DataTypes
.
BOOL
EAN
,
allowNull
:
false
,
defaultValue
:
false
},
...
...
@@ -38,7 +38,7 @@ module.exports = function(sequelize, DataTypes) {
TtimeEnd
:
DataTypes
.
TIME
,
Wsession
:
{
type
:
DataTypes
.
BOOL
,
type
:
DataTypes
.
BOOL
EAN
,
allowNull
:
false
,
defaultValue
:
false
},
...
...
@@ -46,7 +46,7 @@ module.exports = function(sequelize, DataTypes) {
WtimeEnd
:
DataTypes
.
TIME
,
Rsession
:
{
type
:
DataTypes
.
BOOL
,
type
:
DataTypes
.
BOOL
EAN
,
allowNull
:
false
,
defaultValue
:
false
},
...
...
@@ -54,7 +54,7 @@ module.exports = function(sequelize, DataTypes) {
RtimeEnd
:
DataTypes
.
TIME
,
Fsession
:
{
type
:
DataTypes
.
BOOL
,
type
:
DataTypes
.
BOOL
EAN
,
allowNull
:
false
,
defaultValue
:
false
},
...
...
@@ -62,41 +62,41 @@ module.exports = function(sequelize, DataTypes) {
FtimeEnd
:
DataTypes
.
TIME
},
{
validate
:
{
Msession
:
function
(
value
)
{
if
(
Msession
===
true
)
&&
(
MtimeStart
===
null
||
MtimeEnd
===
null
)
{
Msession
_validate
:
function
(
value
)
{
if
(
(
Msession
===
true
)
&&
(
MtimeStart
===
null
||
MtimeEnd
===
null
)
)
{
throw
new
Error
(
'
Start and end times must be defined for
'
+
'
Monday if class is set to true.
'
);
}
},
Tsession
:
function
(
value
)
{
if
(
Tsession
===
true
)
&&
(
TtimeStart
===
null
||
TtimeEnd
===
null
)
{
Tsession
_validate
:
function
(
value
)
{
if
(
(
Tsession
===
true
)
&&
(
TtimeStart
===
null
||
TtimeEnd
===
null
)
)
{
throw
new
Error
(
'
Start and end times must be defined for
'
+
'
Tuesday if class is set to true.
'
);
}
},
Wsession
:
function
(
value
)
{
if
(
Wsession
===
true
)
&&
(
WtimeStart
===
null
||
WtimeEnd
===
null
)
{
Wsession
_validate
:
function
(
value
)
{
if
(
(
Wsession
===
true
)
&&
(
WtimeStart
===
null
||
WtimeEnd
===
null
)
)
{
throw
new
Error
(
'
Start and end times must be defined for
'
+
'
Wednesday if class is set to true.
'
);
}
},
Rsession
:
function
(
value
)
{
if
(
Rsession
===
true
)
&&
(
RtimeStart
===
null
||
RtimeEnd
===
null
)
{
Rsession
_validate
:
function
(
value
)
{
if
(
(
Rsession
===
true
)
&&
(
RtimeStart
===
null
||
RtimeEnd
===
null
)
)
{
throw
new
Error
(
'
Start and end times must be defined for
'
+
'
Thursday if class is set to true.
'
);
}
},
Fsession
:
function
(
value
)
{
if
(
Fsession
===
true
)
&&
(
FtimeStart
===
null
||
FtimeEnd
===
null
)
{
Fsession
_validate
:
function
(
value
)
{
if
(
(
Fsession
===
true
)
&&
(
FtimeStart
===
null
||
FtimeEnd
===
null
)
)
{
throw
new
Error
(
'
Start and end times must be defined for
'
+
'
Friday if class is set to true.
'
);
}
...
...
schedules/models/Semester.js
View file @
7f822200
...
...
@@ -8,12 +8,20 @@ module.exports = function(sequelize, DataTypes) {
name
:
DataTypes
.
STRING
,
universitySlug
:
{
type
:
DataTypes
.
STRING
,
references
:
{
model
:
University
,
key
:
slug
type
:
DataTypes
.
STRING
//references: {
// model: University,
// key: slug
//}
}
},
{
classMethods
:
{
associate
:
function
(
models
)
{
Semester
.
belongsTo
(
models
.
University
,
{
foreignKey
:
'
slug
'
}
);
}
}
})
});
return
Semester
;
}
schedules/models/University.js
View file @
7f822200
...
...
@@ -15,5 +15,13 @@ module.exports = function(sequelize, DataTypes) {
type
:
DataTypes
.
STRING
,
allowNull
:
false
}
})
},
{
classMethods
:
{
associate
:
function
(
models
)
{
University
.
hasMany
(
models
.
Semester
,
{
foreignKey
:
'
slug
'
}
);
}
}
});
return
University
;
}
schedules/models/index.js
View file @
7f822200
...
...
@@ -13,16 +13,16 @@ var sequelize = new Sequelize(sequelizeConf);
// empty variable to load entire database into
var
db
=
{};
var
modelNames
=
[
'
Section
'
,
'
Semester
'
,
'
University
'
]
// this section load every model file in the `models` dir into the database
fs
.
readdirSync
(
__dirname
)
.
flter
(
function
(
file
)
{
return
(
file
.
indexOf
(
"
.
"
!==
0
))
&&
(
file
!==
"
index.js
"
);
})
.
forEach
(
function
(
file
)
{
var
model
=
sequelize
.
import
(
path
.
join
(
__dirname
,
file
));
modelNames
.
forEach
(
function
(
modelName
)
{
var
model
=
sequelize
.
import
(
path
.
join
(
__dirname
,
modelName
));
db
[
model
.
name
]
=
model
;
});
});
// TODO: figure out exactly what this is doing
Object
.
keys
(
db
).
forEach
(
function
(
modelName
)
{
...
...
schedules/package.json
View file @
7f822200
...
...
@@ -6,6 +6,7 @@
"start"
:
"node ./bin/www"
},
"dependencies"
:
{
"app-module-path"
:
"^2.1.0"
,
"body-parser"
:
"~1.15.1"
,
"config"
:
"^1.24.0"
,
"cookie-parser"
:
"~1.4.3"
,
...
...
schedules/routes/api/v1.js
View file @
7f822200
...
...
@@ -6,9 +6,9 @@
var
express
=
require
(
'
express
'
);
var
router
=
express
.
Router
();
var
mongoose
=
require
(
'
mongoose
'
);
var
Semester
=
require
(
'
../../models/Semester
'
);
var
ical
=
require
(
'
ical-generator
'
);
var
db
=
require
(
'
models
'
);
var
config
=
require
(
'
config
'
);
// Load site wide configurations
...
...
@@ -26,23 +26,17 @@ router.get('/json/schools', function(req, res, next) {
router
.
get
(
'
/json/classes/:SEMSLUG
'
,
function
(
req
,
res
,
next
)
{
var
slug
=
req
.
params
[
'
SEMSLUG
'
];
// find each person with matching slug
var
query
=
Semester
.
findOne
({
'
slug
'
:
slug
});
// remove unwanted fields from request
query
.
select
(
'
-_id -classes._id -classes.session_templates._id
'
);
// excecute the request (caches with redis)
query
.
lean
().
exec
(
function
(
err
,
semester
)
{
// if there was an error or nothing was returned
if
(
err
||
(
!
semester
))
{
// send an error message
res
.
json
({
'
results
'
:
'
error, try something different
'
})
}
// else send out the semester object as json
else
{
res
.
json
(
semester
);
}
})
});
////////////////////////////////////////////////////////////////////////////////
...
...
schedules/routes/index.js
View file @
7f822200
...
...
@@ -7,6 +7,7 @@
var
express
=
require
(
'
express
'
);
var
router
=
express
.
Router
();
var
config
=
require
(
'
config
'
);
var
db
=
require
(
'
models
'
);
// Load site wide configurations
var
siteInfo
=
config
.
get
(
'
general
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment