-
Notifications
You must be signed in to change notification settings - Fork 9
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
Jeplind Morico #3
Open
jeplindm
wants to merge
25
commits into
kgd-05-eclipse-fox:master
Choose a base branch
from
jeplindm:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
aad797e
Jeplind Morico
064b5f9
POST, GET, PUT, PATCH, DELETE
41bfa7b
rev. post
a137772
rev. documentation
f636ff1
rev. perbaikan + register,login
b8bad8d
authtics,authorize,error-handler
c64ae31
Jeplind Morico
997d1dc
Jeplind Morico
cd048a5
Jeplind Morico
839696e
deploy to heroku
1b6b71b
fix port and package.json
f3a5d3f
add database production in config.json
5a8d93c
rev app.js
6011a00
rev. app.js
bbc81bc
trial config.json
8ea037d
trial config.json
80a10ce
remove file .env from server
1b15d3a
trial config and .env
dd40041
trial config.json
5fbf773
rev. user controller
34be628
try fix jwt and user controller
b632acb
fix config.json production
4920502
fix app.js
73363e8
fix main.js client
359f811
deploy heroku + deploy firebase
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
const express = require('express'); | ||
const app = express(); | ||
const port = 3000; | ||
const routes = require('./routes/index'); | ||
|
||
app.use(express.urlencoded({extended: false})) | ||
|
||
app.use(express.json()) | ||
|
||
app.use(routes) | ||
|
||
|
||
app.listen(port, ()=> { | ||
console.log(`Listen to this http://localhost:${port}`); | ||
}) |
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,23 @@ | ||
{ | ||
"development": { | ||
"username": "postgres", | ||
"password": "saragih21!", | ||
"database": "database_development_todoapps", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"test": { | ||
"username": "postgres", | ||
"password": "saragih21!", | ||
"database": "database_test_todoapps", | ||
"host": "127.0.0.1", | ||
"dialect": "postgres" | ||
}, | ||
"production": { | ||
"username": "root", | ||
"password": null, | ||
"database": "database_production", | ||
"host": "127.0.0.1", | ||
"dialect": "mysql" | ||
} | ||
} |
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,93 @@ | ||
const { Todo } = require('../models') | ||
|
||
class Controller { | ||
static postTodo (req,res) { | ||
const value = { | ||
title: req.body.title, | ||
description: req.body.description, | ||
due_date: req.body.due_date | ||
} | ||
|
||
Todo | ||
.create(value) | ||
.then((todo) => { | ||
res.status(201).json(todo) | ||
}).catch((err) => { | ||
res.status(500).json({error: err.errors[0]}) | ||
}); | ||
} | ||
|
||
static findAll(req,res) { | ||
Todo | ||
.findAll() | ||
.then((todo) => { | ||
res.status(200).json(todo) | ||
}).catch((err) => { | ||
res.status(500).json(err) | ||
}); | ||
} | ||
|
||
static putEditTodo(req,res) { | ||
const id = +req.params.id; | ||
const {title, description, status, due_date} = req.body | ||
|
||
Todo | ||
.update({ | ||
title, | ||
description, | ||
status, | ||
due_date | ||
}, | ||
{ | ||
where: { | ||
id | ||
}, | ||
returning:true | ||
}) | ||
.then((update) => { | ||
res.status(200).json(update[1][0]) | ||
}).catch((err) => { | ||
res.status(500).json(err) | ||
}); | ||
} | ||
|
||
static patchIdTodo(req,res) { | ||
const id = +req.params.id | ||
const { status } = req.body; | ||
|
||
Todo | ||
.update({ | ||
status | ||
}, | ||
{ | ||
where: { | ||
id | ||
}, | ||
returning: true | ||
}) | ||
.then((todo) => { | ||
res.status(200).json(todo[1][0]) | ||
}).catch((err) => { | ||
res.status(500).json(err) | ||
}); | ||
} | ||
|
||
static deleteById(req,res) { | ||
const id = +req.params.id | ||
|
||
Todo | ||
.destroy({ | ||
where: { | ||
id | ||
} | ||
}) | ||
.then((data) => { | ||
res.status(200).json("message: todo success to delete") | ||
}).catch((err) => { | ||
res.status(500).json(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('Todos', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
title: { | ||
type: Sequelize.STRING | ||
}, | ||
description: { | ||
type: Sequelize.STRING | ||
}, | ||
status: { | ||
type: Sequelize.STRING | ||
}, | ||
due_date: { | ||
type: Sequelize.DATE | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('Todos'); | ||
} | ||
}; |
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,37 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Sequelize = require('sequelize'); | ||
const basename = path.basename(__filename); | ||
const env = process.env.NODE_ENV || 'development'; | ||
const config = require(__dirname + '/../config/config.json')[env]; | ||
const db = {}; | ||
|
||
let sequelize; | ||
if (config.use_env_variable) { | ||
sequelize = new Sequelize(process.env[config.use_env_variable], config); | ||
} else { | ||
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 => { | ||
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes); | ||
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; |
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,41 @@ | ||
'use strict'; | ||
const { | ||
Model | ||
} = require('sequelize'); | ||
module.exports = (sequelize, DataTypes) => { | ||
class Todo 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 | ||
} | ||
}; | ||
Todo.init({ | ||
title: DataTypes.STRING, | ||
description: DataTypes.STRING, | ||
status: DataTypes.STRING, | ||
due_date: { | ||
type: DataTypes.DATE, | ||
validate: { | ||
isDate: { | ||
args: true, | ||
msg: "must be in date format" | ||
}, | ||
isAfter: { | ||
args: `${new Date()}`, | ||
msg: "must be greater than today" | ||
} | ||
} | ||
} | ||
}, { | ||
sequelize, | ||
modelName: 'Todo', | ||
}); | ||
Todo.addHook('beforeCreate', (instance) => { | ||
instance.status = "not finished" | ||
}) | ||
return Todo; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
untuk validasi tanggal tidak bisa menggunakan isAfter karena argsnya jalan ketika server dijalankan, misal server nyala di 17 agustus , di 19 agustus kita masih bisa bikin todo untuk 18 agustus (karena new date nya dibuat saat 17 agustus)