Commit 6cf40c8a authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Add models

parent 6f6a81f5
module.exports = function(sequelize, DataTypes) {
var Section = sequelize.define("Section", {
// unique index/key
crn : DataTypes.STRING,
crn : {
type: DataTypes.STRING,
unique: true
},
name : DataTypes.STRING,
title : DataTypes.STRING,
section : DataTypes.STRING,
// should be foreign key
instructor : DataTypes.STRING,
instructor : type: DataTypes.STRING,
// should be foreign key
campus : DataTypes.STRING,
// should be foreign key
location : DataTypes.STRING,
// should be foreign key
class_type : DataTypes.STRING,
// Start Time Information
startDate : DataTypes.DATE,
endDate : DataTypes.DATE,
Msession : DataTypes.BOOL,
Msession : {
type: DataTypes.BOOL,
allowNull: false,
defaultValue: false
},
MtimeStart : DataTypes.TIME,
MtimeEnd : DataTypes.TIME,
Tsession : DataTypes.BOOL,
Tsession : {
type: DataTypes.BOOL,
allowNull: false,
defaultValue: false
},
TtimeStart : DataTypes.TIME,
TtimeEnd : DataTypes.TIME,
Wsession : DataTypes.BOOL,
Wsession : {
type: DataTypes.BOOL,
allowNull: false,
defaultValue: false
},
WtimeStart : DataTypes.TIME,
WtimeEnd : DataTypes.TIME,
Rsession : DataTypes.BOOL,
Rsession : {
type: DataTypes.BOOL,
allowNull: false,
defaultValue: false
},
RtimeStart : DataTypes.TIME,
RtimeEnd : DataTypes.TIME,
Fsession : DataTypes.BOOL,
Fsession : {
type: DataTypes.BOOL,
allowNull: false,
defaultValue: false
},
FtimeStart : DataTypes.TIME,
FtimeEnd : DataTypes.TIME
}, {
validate: {
Msession: 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) {
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) {
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) {
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) {
throw new Error('Start and end times must be defined for' +
' Friday if class is set to true.');
}
}
}
}, {
indexes: [
{
unique: true,
fields: ['crn']
},
{
unique: false,
fields: ['instructor']
},
{
unique: false,
fields: ['campus']
},
{
unique: false,
fields: ['location']
},
{
unique: false,
fields: ['title']
}
]
})
}
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports = function(sequelize, DataTypes) {
var Semester = sequelize.define("Semester", {
slug: {
type: DataTypes.STRING,
unique: true
},
// create a schema
var semesterSchema = new Schema({
school: { type: String, required: true },
semester: { type: String, required: true },
slug: { type: String, required: true },
classes: [
{
crn: { type: String, required: true },
name: { type: String, required: true },
title: { type: String, required: true },
section: { type: String, required: true },
campus: { type: String, required: true },
session_templates: [
{
date_range: { type: String, required: true },
days: { type: String },
time: { type: String },
location: { type: String, required: true },
class_type: { type: String, required: true },
instructors: { type: String, required: true },
}
],
notification: { type: String, required: true }
}
]
});
semesterSchema.set('redisCache', true);
name: DataTypes.STRING,
// the schema is useless so far
// we need to create a model using it
var Semester = mongoose.model('Semester', semesterSchema);
universitySlug: {
type: DataTypes
references: {
model: University
key: slug
}
}
})
}
// make this available to our users in our Node applications
module.exports = Semester;
module.exports = function(sequelize, DataTypes) {
var University = sequelize.define("University", {
slug: {
type: DataTypes.STRING,
allowNull: false,
unique: true
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
website: {
type: DataTypes.STRING,
allowNull: false
}
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment