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

coba push #23

Open
wants to merge 2 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": "12345",
"database": "database_development",
"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"
}
}
240 changes: 240 additions & 0 deletions controller/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
const models = require('../models')
const views = require('../view')
class Controller{
constructor(input2,input3,input4,input5){
this.input2=input2
this.input3=input3
this.input4=input4
this.input5=input5

}
showData(){
if(this.input2==='help'){
console.log('=== documentation ============================================================');
console.log('author add -> add<space> "data yang ingin dimasukan"');
console.log('author read_one -> read_one<space> "masukan id author"');
console.log('author read_all -> read_all');
console.log('author update -> update <spce> "masukkan data yang ingin di update dan idnya"');
console.log('athor delete -> delete<space> "masukan id author"');
console.log('tag add -> add<space> "data yang ingin dimasukan"');
console.log('tag read_one -> read_one<space> "masukkan id tag"');
console.log('tag readl_all -> read_all');
console.log('tag update -> update<space> "masukkan data yang ingin di update dan idnya"');
console.log('tag delete -> delete<space> "masukkan id author"');
console.log('article add -> add<space> "data yang ingin dimasukan"');
console.log('article read_one -> read_one<space> "masukan id article"');
console.log('article read_all -> read_all');
console.log('article update -> update<space> "masukkan data yang ingin di update dan idnya"');
console.log('article delete -> delete<space> "masukkan id author"');
console.log('===============================================================================');
}
else if(this.input3==='add'){
var obj={};
var newData=this.input4
var pisah= newData.split(',')

if(seconds==='author'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='first_name'){
obj.first_name=titikDua[1]
}
else if (titikDua[0]==='last_name') {
obj.last_name=titikDua[1]
}
else if (titikDua[0]==='religion') {
obj.religion=titikDua[1]
}
else if (titikDua[0]==='gender') {
obj.age=titikDua[1]
}
}
models.authors.create(obj);
}
else if(this.input2==='article'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='title'){
obj.title=titikDua[1]
}
else if (titikDua[0]==='body') {
obj.body=titikDua[1]
}
else if (titikDua[0]==='id_author') {
obj.id_author=titikDua[1]
}
else if (titikDua[0]==='id_tag') {
obj.id_tag=titikDua[1]
}
}
models.articles.create(obj);
}
else if(this.input2==='tag'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='name'){
obj.name=titikDua[1]
}
}
models.tags.create(obj);
}
}
else if(this.input3==='read_one'){
if(this.input2==='author'){
models.authors.findAll({
raw:true,
where: {
id: this.input4
}
}).then(articlesData => {
views.printView(articlesData)
// console.log(articlesData)
});
}
else if(input2==='article'){
models.articles.findAll({
raw:true,
where: {
id: this.input4
}
}).then(articlesData => {
console.log(articlesData)
});
}
else if(this.input2==='tag'){
models.tags.findAll({
raw:true,
where: {
id: this.input4
}
}).then(articlesData => {
console.log(articlesData)
});
}
}
else if(this.input3==='read_all'){
if(this.input2==='author'){
models.authors.findAll({
raw:true,
}).then(articlesData => {
console.log(articlesData)
});
}
else if(this.input2==='article'){
models.articles.findAll({
raw:true,
}).then(articlesData => {
console.log(articlesData)
});
}
else if(this.input2==='tag'){
models.tags.findAll({
raw:true,
}).then(articlesData => {
console.log(articlesData)
});
}
}

else if(this.input3==='update'){
var obj={};
var newData=input5
var pisah= newData.split(',')

if(this.input2==='author'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='first_name'){
obj.first_name=titikDua[1]
}
else if (titikDua[0]==='last_name') {
obj.last_name=titikDua[1]
}
else if (titikDua[0]==='religion') {
obj.religion=titikDua[1]
}
else if (titikDua[0]==='gender') {
obj.age=titikDua[1]
}
}
models.authors.update(
obj, {
where: {
id: this.input3
}
});
}
else if(this.input2==='article'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='title'){
obj.title=titikDua[1]
}
else if (titikDua[0]==='body') {
obj.body=titikDua[1]
}
else if (titikDua[0]==='id_author') {
obj.id_author=titikDua[1]
}
else if (titikDua[0]==='id_tag') {
obj.id_tag=titikDua[1]
}
}
models.articles.update(
obj, {
where: {
id: this.input4
}
});
}
else if(this.input2==='tag'){
for(let i=0;i<pisah.length;i++){
var titikDua=pisah[i].toString().split(':')
if(titikDua[0]==='name'){
obj.name=titikDua[1]
}
}
models.tags.update(
obj, {
where: {
id: this.input4
}
});
}
}


else if(this.input3==='delete'){
if(this.input2==='author'){
models.authors.destroy({
where: {
id: this.input4
}
});
}
else if(this.input2==='article'){
models.articles.destroy({
where: {
id: this.input4
}
});
}
else if(this.input2==='tag'){
models.tags.destroy({
where: {
id: this.input4
}
});
}
}

}
}


module.exports = Controller


// models.articles.findAll({raw:true}).then(articlesData => {
// console.log(articlesData)
// })

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

6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const argv = process.argv;
var sequelize = require('sequelize');
const Controller = require('./controller')

var controller = new Controller(argv[2],argv[3],argv[4],argv[5]);
controller.showData()
36 changes: 36 additions & 0 deletions migrations/20180221080806-create-articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Articles', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
title: {
type: Sequelize.STRING
},
body: {
type: Sequelize.STRING
},
id_author: {
type: Sequelize.INTEGER
},
id_tag: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Articles');
}
};
39 changes: 39 additions & 0 deletions migrations/20180221080837-create-authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Authors', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
first_name: {
type: Sequelize.STRING
},
last_name: {
type: Sequelize.STRING
},
religion: {
type: Sequelize.STRING
},
gender: {
type: Sequelize.STRING
},
age: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Authors');
}
};
27 changes: 27 additions & 0 deletions migrations/20180221080855-create-tags.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('Tags', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Tags');
}
};
Loading