forked from Flex-Armenian-Fox/kanban-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
238 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
SECRET_KEY_JWT="BluePeriod" | ||
SECRET_KEY_JWT=BluePeriod | ||
|
||
DEV_USERNAME = "postgres" | ||
DEV_PASSWORD = | ||
DEV_SERVER = "localhost" | ||
DEV_DB = "kanban_db" | ||
DEV_USERNAME=postgres | ||
DEV_PASSWORD= | ||
DEV_SERVER=localhost | ||
DEV_DB=kanban_db | ||
|
||
DEV_G_CLIENT_ID = 982085477024-6n2tpq82aracq5krun8e705oj863h0q2.apps.googleusercontent.com | ||
DEV_G_CLIENT_ID=982085477024-6n2tpq82aracq5krun8e705oj863h0q2.apps.googleusercontent.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SECRET_KEY_JWT= | ||
|
||
DEV_USERNAME= | ||
DEV_PASSWORD= | ||
DEV_SERVER= | ||
DEV_DB= | ||
|
||
DEV_G_CLIENT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require("dotenv").config(); | ||
module.exports = { | ||
"development": { | ||
"username": process.env.DEV_USERNAME, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const {Task} = require('../models/index') | ||
const {jwtEncrypt, jwtDecrypt} = require('../helpers/jwt') | ||
const {compareHash} = require('../helpers/brcypt') | ||
|
||
class Controller{ | ||
static postTask(req, res, next){ | ||
let task = req.body | ||
task.UserId = req.currentUser.id | ||
task.deadline = new Date() | ||
task.deadline = task.deadline.toISOString() | ||
Task.create(task, {returning: true}) | ||
.then(r => { | ||
console.log(r) | ||
res.status(201).json({r}) | ||
}) | ||
.catch(err => {next(err)}) | ||
} | ||
|
||
static getTask(req, res, next){ | ||
Task.findAll() | ||
.then(taskData => { | ||
res.status(200).json(taskData) | ||
}) | ||
.catch(err => {next(err)}) | ||
} | ||
|
||
static deleteTask(req, res, next){ | ||
Task.destroy({where: {id:req.params.id}, returning:true}) | ||
.then(taskData => { | ||
res.status(200).json("delete success") | ||
}) | ||
.catch(err => {next(err)}) | ||
} | ||
|
||
static putTask(req, res, next){ | ||
|
||
} | ||
|
||
static patchTask(req, res, next){ | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { User} = require('../models/index') | ||
const {jwtEncrypt, jwtDecrypt} = require('../helpers/jwt') | ||
const {compareHash} = require('../helpers/brcypt') | ||
|
||
class Controller{ | ||
static postRegister(req, res, next){ | ||
if (!req.body.email || !req.body.password) throw {name: "FillEmailPassword"} | ||
User.create(req.body) | ||
.then(() => { | ||
res.status(200).json({message: "User Registered", email:req.body.email}) | ||
}) | ||
.catch((err) => { | ||
next(err) | ||
}) | ||
} | ||
|
||
static postLogin(req, res, next){ | ||
if (!req.body.email || !req.body.password) throw {name: "FillEmailPassword"} | ||
User.findOne({where:{email: req.body.email.toLowerCase()}}) | ||
.then(user => { | ||
if (!user) throw {name: "noEmail"} | ||
if(compareHash(req.body.password, user.password)){ | ||
const token = jwtEncrypt({id: user.id, email: user.email}) | ||
res.status(200).json({message: "login successful", access_token: token}) | ||
} | ||
else throw {name: "wrongPassword"} | ||
}) | ||
.catch((err) =>{ | ||
next(err) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
await queryInterface.createTable('Tasks', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
name: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
description: { | ||
type: Sequelize.STRING | ||
}, | ||
deadline: { | ||
type: Sequelize.DATE | ||
}, | ||
category: { | ||
allowNull: false, | ||
type: Sequelize.STRING | ||
}, | ||
UserId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: 'Users', | ||
Key: 'id' | ||
} | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: async (queryInterface, Sequelize) => { | ||
await queryInterface.dropTable('Tasks'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const {hash} = require('../helpers/brcypt') | ||
const { | ||
Model | ||
} = require('sequelize'); | ||
module.exports = (sequelize, DataTypes) => { | ||
class User extends Model { | ||
/** | ||
* Helper method for defining associations. | ||
* This method is not a part of Sequelize lifecycle. | ||
* The `models/index` file will call this method automatically. | ||
*/ | ||
static associate(models) { | ||
// define association here | ||
} | ||
}; | ||
User.init({ | ||
email: { | ||
type: DataTypes.STRING, | ||
unique: { | ||
msg: 'email is already taken' | ||
}, | ||
validate: { | ||
notEmpty: {msg: "Email cannot be empty"}, | ||
isEmail: {msg: "Please use proper email format"} | ||
}, | ||
}, | ||
password: { | ||
type: DataTypes.STRING, | ||
validate: { | ||
notEmpty: {msg: "Password cannot be empty"}, | ||
len: { | ||
args: [4, 32], | ||
msg: "Password must be between 4 to 32 characters" | ||
} | ||
} | ||
}, | ||
}, { | ||
hooks:{ | ||
beforeCreate: user =>{ | ||
user.password = hash(user.password) | ||
user.email = user.email.toLowerCase() | ||
} | ||
}, | ||
sequelize, | ||
modelName: 'User', | ||
}); | ||
return User; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const todoRoute = require('./todos-route') | ||
const userRoute = require('./users-route') | ||
const {authentication} = require('../middlewares/auth') | ||
const taskRoute = require('./tasks-route') | ||
const {authentication, authorization} = require('../middlewares/auth') | ||
const userC = require('../controllers/userController') | ||
|
||
router.use('/todos', authentication, todoRoute) | ||
router.use('/users', userRoute) | ||
router.post('/register', userC.postRegister) | ||
router.post('/login', userC.postLogin) | ||
router.use('/tasks', authentication, authorization, taskRoute) | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const taskC = require('../controllers/taskController') | ||
const {authorization} = require('../middlewares/auth') | ||
|
||
router.put('/', taskC.putTask) | ||
router.post('/', taskC.postTask) | ||
router.get('/', taskC.getTask) | ||
router.delete('/', taskC.deleteTask) | ||
router.patch('/', taskC.patchTask) | ||
|
||
module.exports = router; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.