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

done... #21

Open
wants to merge 4 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
23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "admin",
"password": "@dmin1234",
"database": "demo",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "root",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "mysql"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "mysql"
}
}
173 changes: 173 additions & 0 deletions controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
const models = require('./models/')
const view = require('./view.js')



class Controller{
constructor(){

}

static command(syntax, option, option2){
if(syntax == 'help'){
let result = [
'=============== documentation =================================================',
'$ node index.js author add -> add<space> "data yang ingin dimasukan"',
'$ node index.js author read_one -> read_one<space> "masukan id author"',
'$ node index.js author read_all -> read_all',
'$ node index.js author update -> update <space> "first_name last_name religion gender age" <space> id',
'$ node index.js athor delete -> delete<space> "masukan id author"',
'$ node index.js tag add -> add<space> "data yang ingin dimasukan"',
'$ node index.js tag read_one -> read_one<space> "masukkan id tag"',
'$ node index.js tag readl_all -> read_all',
'$ node index.js tag update -> update<space> "name" <space> id',
'$ node index.js tag delete -> delete<space> "masukkan id author"',
'$ node index.js article add -> add<space> "data yang ingin dimasukan"',
'$ node index.js article read_one -> read_one<space> "masukan id article"',
'$ node index.js article read_all -> read_all',
'$ node index.js article update -> update<space> "title body id_author id_tag" <space> id',
'$ node index.js article delete -> delete<space> "masukkan id author"',
'================================================================================'
]
result = result.join('\n')
return console.log(result)
}
else if(syntax == 'author' && option == 'add'){
models.authors.create({
first_name:option2[0],
last_name:option2[1],
religion:option2[2],
gender:option2[3],
age:option2[4]
}).then(authors => {
console.log(authors.get({
plain: true
}))
})
}
else if(syntax == 'author' && option == 'read_one'){
models.authors.findOne({
where:{
id:option2[0]
},raw:true
}).then(authorsData => {
view.viewAuthorOne(authorsData)
})
}
else if(syntax == 'author' && option == 'read_all'){
models.authors.findAll({raw:true}).then(authorsData => {
view.viewAuthor(authorsData)
})
}
else if(syntax == 'author' && option == 'update'){
models.authors.update({
first_name:option2[0],
last_name:option2[1],
religion:option2[2],
gender:option2[3],
age:option2[4]
}, {where:{
id:option2[5]
}}).then(() => {

})
}
else if(syntax == 'author' && option == 'delete'){
models.authors.destroy({
where:{
id:option2[0]
}
})
}
else if(syntax == 'tag' && option == 'add'){
models.tags.create({
name:option2[0],
}).then(tags => {
console.log(tags.get({
plain: true
}))
})
}
else if(syntax == 'tag' && option == 'read_one'){
models.tags.findOne({
where:{
id:option2[0]
},raw:true
}).then(tagsData => {
view.viewTagOne(tagsData)
})
}
else if(syntax == 'tag' && option == 'read_all'){
models.tags.findAll({raw:true}).then(tagsData => {
view.viewTag(tagsData)
})
}
else if(syntax == 'tag' && option == 'update'){
models.tags.update({
name:option2[0],
}, {where:{
id:option2[1]
}}).then(() => {

})
}
else if(syntax == 'tag' && option == 'delete'){
models.tags.destroy({
where:{
id:option2[0]
}
})
}
else if(syntax == 'article' && option == 'add'){
models.articles.create({
title:option2[0],
body:option2[1],
id_author:option2[2],
id_tag:option2[3]
}).then(articles => {
console.log(articles.get({
plain: true
}))
})
}
else if(syntax == 'article' && option == 'read_one'){
models.articles.findOne({
where:{
id:option2[0]
},raw:true
}).then(articlesData => {
view.viewArticleOne(articlesData)
})
}
else if(syntax == 'article' && option == 'read_all'){
models.articles.findAll({raw:true}).then(articlesData => {
view.viewArticle(articlesData)
})
}
else if(syntax == 'article' && option == 'update'){
models.articles.update({
title:option2[0],
body:option2[1],
id_author:option2[2],
id_tag:option2[3]
}, {where:{
id:option2[4]
}}).then(() => {

})
}
else if(syntax == 'article' && option == 'delete'){
models.articles.destroy({
where:{
id:option2[0]
}
})
}
else{
console.log('you will call "help"')
}
}

}

module.exports = Controller
Loading