Skip to content
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
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
PORT =
DBNAME=database
DBUSER=postgres
DBPASSWORD=password
PORT=5432
DBHOST=127.0.0.1
SECRETKEY=any_secret
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pids
*.seed
*.pid.lock

# My DB config
src/api/db/config/config.js

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand Down
7 changes: 0 additions & 7 deletions config.example.js

This file was deleted.

23 changes: 17 additions & 6 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"scripts": {
"start": "nodemon --exec babel-node ./src/server.js",
"watch:dev": "nodemon ./src/server.js",
"migrate": "sequelize db:migrate",
"migrate:undo": "sequelize db:migrate:undo:all",
"seed": "sequelize db:seed:all",
"build": "rm -rf ./build && babel -d ./build ./src -s",
"lint": "eslint --ext .js .",
"lint:check": "eslint .",
Expand All @@ -20,6 +23,7 @@
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"faker": "^5.5.3",
"pg": "^8.8.0",
"pg-hstore": "^2.3.4",
"sequelize": "^6.25.3"
Expand Down
14 changes: 12 additions & 2 deletions src/db/migrations/20221030101534-create-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@ module.exports = {
await queryInterface.createTable('Notices', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
notice: {
type: Sequelize.STRING
},
classId: {
type: Sequelize.UUID,
allowNull:false,
foreignKey:true
},
teacherId: {
type: Sequelize.UUID,
allowNull:false,
foreignKey:true
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
Expand Down
13 changes: 7 additions & 6 deletions src/db/migrations/20221030101627-create-assignment-score.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = {
await queryInterface.createTable('AssignmentScores', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
assignmentId: {
type:Sequelize.STRING,
Expand All @@ -17,11 +17,12 @@ module.exports = {
type:Sequelize.STRING,
allowNull:false
},
studentId: {
type:Sequelize.STRING,
allowNull:false
teacherId: {
type: Sequelize.UUID,
allowNull:false,
foreignKey:true
},
teacher: {
studentId: {
type:Sequelize.STRING,
allowNull:false
},
Expand Down
8 changes: 6 additions & 2 deletions src/db/migrations/20221030101644-create-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = {
await queryInterface.createTable('Assignments', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
assignment: {
type: Sequelize.STRING
Expand All @@ -16,6 +16,10 @@ module.exports = {
type: Sequelize.STRING,
allowNull:false
},
teacherId:{
type: Sequelize.UUID,
allowNull:false
},
studentId:{
type: Sequelize.STRING,
allowNull:false
Expand Down
4 changes: 2 additions & 2 deletions src/db/migrations/20221030101744-create-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = {
await queryInterface.createTable('Roles', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
role: {
type: Sequelize.STRING
Expand Down
9 changes: 7 additions & 2 deletions src/db/migrations/20221030101838-create-class-teacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ module.exports = {
await queryInterface.createTable('ClassTeachers', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
classId: {
type: Sequelize.STRING
},
teacherId:{
type: Sequelize.UUID,
allowNull:false,
foreignKey:true
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
Expand Down
8 changes: 6 additions & 2 deletions src/db/migrations/20221030101917-create-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ module.exports = {
await queryInterface.createTable('Classes', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
className: {
type: Sequelize.STRING
},
year: {
type:Sequelize.STRING,
allowNull:false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
Expand Down
12 changes: 7 additions & 5 deletions src/db/migrations/20221030102005-create-class-student.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
'use strict';

const { DataTypes } = require('sequelize');

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('ClassStudents', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.UUID
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4
},
studentId:{
type: Sequelize.UUID,
allowNull:false,
foreignKey:true
},
classId:{
type: Sequelize .UUID,
allowNull:false,
foreignKey:true
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
Expand Down
8 changes: 6 additions & 2 deletions src/db/models/classstudent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull:false,
unique:true,
primaryKey: true
},
studentId:{
type: DataTypes.UUID,
allowNull:false,
foreignKey:true
}
},
classId:{
type: DataTypes.UUID,
allowNull:false,
foreignKey:true
},
}, {
sequelize,
modelName: 'ClassStudent',
Expand Down
7 changes: 4 additions & 3 deletions src/db/models/classteacher.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ module.exports = (sequelize, DataTypes) => {
}
}
ClassTeacher.init({
id:{
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
allowNull:false,
primaryKey: true
defaultValue: DataTypes.UUIDV4
},
teacherId:{
type: DataTypes.UUID,
Expand Down
5 changes: 5 additions & 0 deletions src/db/models/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = (sequelize, DataTypes) => {
}
}
Notice.init({
id: {
allowNull: false,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
notice: {
type:DataTypes.STRING,
allowNull:false,
Expand Down
50 changes: 50 additions & 0 deletions src/db/seeders/20221117052621-User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
//import bcrypt from 'bcrypt'
module.exports = {
async up (queryInterface, Sequelize) {
/**
* Add seed commands here.
*
* Example:
* await queryInterface.bulkInsert('People', [{
* name: 'John Doe',
* isBetaMember: false
* }], {});
*/
await queryInterface.bulkInsert('Users', [{
id: "c7a9122e-6694-11ed-9022-0242ac120005",
first_name: 'John',
last_name: 'Doe',
second_name: 'Nok',
email: 'example@example2.com',
roleId:'c7a9122e-6694-11ed-9022-0242ac120001',
password: 'nok',
createdAt: new Date(),
updatedAt: new Date()
},
{
id: "c7a9122e-6694-11ed-9022-0242ac120006",
first_name: 'John',
last_name: 'Doe',
second_name: 'Nok',
email: 'example@example3.com',
roleId: 'c7a9122e-6694-11ed-9022-0242ac120003',
password: 'nok',
createdAt: new Date(),
updatedAt: new Date()
}], {});

},

async down (queryInterface, Sequelize) {
/**
* Add commands to revert seed here.
*
* Example:
* await queryInterface.bulkDelete('People', null, {});
*/
await queryInterface.bulkDelete('Users', null, {});
}
};
Loading