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

Hampir beres, tinggal Instance method sama Validasi email terpakai #3

Open
wants to merge 30 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 29 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const express = require('express')
const app = express()
const ejs = require('ejs')
const bodyParser = require('body-parser');
const session = require('express-session')

// Router
const indexRoute = require('./routes/index-route');
const teacherRoute = require('./routes/teacher-route');
const subjectRoute = require('./routes/subject-route');
const studentRoute = require('./routes/student-route');

app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(session({
secret: 'schoolmania'
}))

app.locals.Helper = require('./helpers/helper')

app.use('/', indexRoute);
app.use('/teachers', teacherRoute);
app.use('/subjects', subjectRoute);
app.use('/students', studentRoute);

app.listen(process.env.PORT || '3000', function () {
console.log('Example app listening on port 3000!')
})
12 changes: 12 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"development": {
"username": "postgres",
"password": "postgres",
"database": "school_db",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"use_env_variable": "DATABASE_URL"
}
}
27 changes: 27 additions & 0 deletions helpers/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Helper {
static getScoreLetter(score) {
let result = '';

if (score === null || typeof score === 'undefined') {
return 'Empty';
}

if (score > 85) {
return result = 'A';
}

if (score > 70) {
return result = 'B'
}

if (score > 55) {
return result = 'C'
}

if (score <= 55) {
return result = 'E'
}
}
}

module.exports = Helper;
30 changes: 30 additions & 0 deletions migrations/20171102045822-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');
}
};
26 changes: 26 additions & 0 deletions migrations/20171102050040-add-email-to-teacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'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 });
*/

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');
*/
queryInterface.removeColumn('Teachers', 'email');
}
};
27 changes: 27 additions & 0 deletions migrations/20171102061643-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');
}
};
27 changes: 27 additions & 0 deletions migrations/20171102082325-create-student.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('Students', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Students');
}
};
27 changes: 27 additions & 0 deletions migrations/20171102083513-add-email-to-student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'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 });
*/
queryInterface.addColumn( 'Students', 'last_name', Sequelize.STRING );
queryInterface.addColumn( 'Students', 'email', Sequelize.STRING );
},

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

Example:
return queryInterface.dropTable('users');
*/
queryInterface.removeColumn( 'Students', 'last_name' );
queryInterface.removeColumn( 'Students', 'email' );
}
};
28 changes: 28 additions & 0 deletions migrations/20171102110033-add-unique-email-to-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'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 });
*/
queryInterface.changeColumn( 'Students', 'email', {
type : Sequelize.STRING,
unique : true,
});
},

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

Example:
return queryInterface.dropTable('users');
*/
queryInterface.removeConstraint( 'Students', 'email');
}
};
25 changes: 25 additions & 0 deletions migrations/20171104055109-add-one-subject-to-many-teacher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'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 });
*/
queryInterface.addColumn('Teachers', 'SubjectId', Sequelize.INTEGER);
},

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

Example:
return queryInterface.dropTable('users');
*/
queryInterface.removeColumn( 'Teachers', 'SubjectId');
}
};
25 changes: 25 additions & 0 deletions migrations/20171104080750-add-subject-id-to-teacher-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'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 });
*/
queryInterface.addColumn('Teachers', 'SubjectId', Sequelize.INTEGER);
},

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

Example:
return queryInterface.dropTable('users');
*/
queryInterface.removeColumn( 'Teachers', 'SubjectId');
}
};
33 changes: 33 additions & 0 deletions migrations/20171105022108-create-student-subject.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('StudentSubjects', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
StudentId: {
type: Sequelize.INTEGER
},
SubjectId: {
type: Sequelize.INTEGER
},
Score: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('StudentSubjects');
}
};
33 changes: 33 additions & 0 deletions migrations/20171107142807-create-account.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('Accounts', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
username: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
StudentId: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Accounts');
}
};
Loading