Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-7 #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 25 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const bodyParser = require('body-parser');
const express = require('express');
const app = express();

const index = require('./routers/index');
const teacher = require('./routers/teacher');
const subject = require('./routers/subject');
const student = require('./routers/student');


app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());

app.set('views', './views') // specify the views directory
app.set('view engine', 'ejs') // register the template engine

app.use('/', index)
app.use('/teachers', teacher)
app.use('/subjects', subject)
app.use('/students', student)


app.listen(3000, function() {
console.log("Sedang Berjalan .... !!!!");
});
9 changes: 9 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"development": {
"username": "postgres",
"password": "kucing548",
"database": "school",
"host": "localhost",
"dialect": "postgres"
}
}
30 changes: 30 additions & 0 deletions migrations/20171102064925-create-teacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Teachers', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Teachers');
}
};
24 changes: 24 additions & 0 deletions migrations/20171102065610-add-email-to-teacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
return queryInterface.addColumn('Teachers', 'email', Sequelize.STRING)
},

down: (queryInterface, Sequelize) => {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.dropTable('users');
*/
}
};
27 changes: 27 additions & 0 deletions migrations/20171102074303-create-subject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Subjects', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
subject_name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Subjects');
}
};
33 changes: 33 additions & 0 deletions migrations/20171102094812-create-student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Students', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Students');
}
};
30 changes: 30 additions & 0 deletions migrations/20171106085156-create-student-subject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('StudentSubjects', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
StudentId: {
type: Sequelize.INTEGER
},
SubjectId: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('StudentSubjects');
}
};
36 changes: 36 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(__filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../config/config.json')[env];
var db = {};

if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
26 changes: 26 additions & 0 deletions models/student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var Student = sequelize.define('Student', {
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
email: DataTypes.STRING
});

//classMethods
Student.associate = (models) => {

// many to many
Student.belongsToMany(models.Subject, {through: 'StudentSubject'});
Student.hasMany(models.StudentSubject);
}

//instance method
Student.prototype.getFullName = function () {
return `${this.first_name} ${this.last_name}`
};




return Student;
};
17 changes: 17 additions & 0 deletions models/studentsubject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var StudentSubject = sequelize.define('StudentSubject', {
StudentId: DataTypes.INTEGER,
SubjectId: DataTypes.INTEGER,
score: DataTypes.INTEGER
});

StudentSubject.associate = (models) => {

// cojunction
StudentSubject.belongsTo(models.Subject);
StudentSubject.belongsTo(models.Student);
}

return StudentSubject;
};
17 changes: 17 additions & 0 deletions models/subject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var Subject = sequelize.define('Subject', {
subject_name: DataTypes.STRING
});

Subject.associate = (models) => {
Subject.hasMany(models.Teacher);

// many to many
Subject.belongsToMany(models.Student, {through: 'StudentSubject'});
Subject.hasMany(models.StudentSubject);
}


return Subject;
};
19 changes: 19 additions & 0 deletions models/teacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
module.exports = (sequelize, DataTypes) => {
var Teacher = sequelize.define('Teacher', {
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
email: {
type: DataTypes.STRING,
validate: {
isEmail: true
}
},
SubjectId: DataTypes.INTEGER
});

Teacher.associate = (models) => {
Teacher.belongsTo(models.Subject);
}
return Teacher;
};
1 change: 1 addition & 0 deletions node_modules/.bin/mime

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

1 change: 1 addition & 0 deletions node_modules/.bin/semver

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

1 change: 1 addition & 0 deletions node_modules/.bin/uuid

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

21 changes: 21 additions & 0 deletions node_modules/@types/geojson/LICENSE

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

16 changes: 16 additions & 0 deletions node_modules/@types/geojson/README.md

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

Loading