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

author done #7

Open
wants to merge 3 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": "postgres",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "postgres",
"password": null,
"database": "database_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "postgres",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "postgres"
}
}
72 changes: 72 additions & 0 deletions controllers/cont_article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const sequelize = require('sequelize');
const {articles} = require('../models');
const View = require('../views/article.js');

class Author {
constructor() {

}
static add(){

}
static readAll(){
articles.findAll().then(data => {
let result = []
for(let i=0; i<data.length; i++){
result.push(data[i].dataValues)
}
View.showAll(result)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static readOne(input){
articles.findOne({where:{id : input}}).then(data => {
View.showAll([data])
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static add(input){
articles.create({
name : input[0]
}).then(data => {
View.addData(data)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static update(input){
articles.update({
name : input[1]
}, {
where : {
id : input[0]
}}).then(data => {
View.updateData(input)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static delete(input){
articles.destroy({where : {id : input}}).then(
data => {
View.deleteData(input)
process.exit()
}
).catch(error => {
console.log(error)
process.exit()
})
}
}

module.exports = Author;
80 changes: 80 additions & 0 deletions controllers/cont_author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const sequelize = require('sequelize');
const {authors} = require('../models');
const View = require('../views/author.js');

class Author {
constructor() {

}
static add(){

}
static readAll(){
authors.findAll().then(data => {
let result = []
for(let i=0; i<data.length; i++){
result.push(data[i].dataValues)
}
View.showAll(result)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static readOne(input){
authors.findOne({where:{id : input}}).then(data => {
View.showAll([data])
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static add(input){
authors.create({
first_name : input[0],
last_name : input[1],
religion : input[2],
gender : input[3],
age : input[4]
}).then(data => {
View.addData(data)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static update(input){
authors.update({
first_name : input[1],
last_name : input[2],
religion : input[3],
gender : input[4],
age : input[5]
}, {
where : {
id : input[0]
}}).then(data => {
View.updateData(input)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static delete(input){
authors.destroy({where : {id : input}}).then(
data => {
View.deleteData(input)
process.exit()
}
).catch(error => {
console.log(error)
process.exit()
})
}
}

module.exports = Author;
72 changes: 72 additions & 0 deletions controllers/cont_tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const sequelize = require('sequelize');
const {tags} = require('../models');
const View = require('../views/tag.js');

class Author {
constructor() {

}
static add(){

}
static readAll(){
tags.findAll().then(data => {
let result = []
for(let i=0; i<data.length; i++){
result.push(data[i].dataValues)
}
View.showAll(result)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static readOne(input){
tags.findOne({where:{id : input}}).then(data => {
View.showAll([data])
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static add(input){
tags.create({
name : input[0]
}).then(data => {
View.addData(data)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static update(input){
tags.update({
name : input[1]
}, {
where : {
id : input[0]
}}).then(data => {
View.updateData(input)
process.exit()
}).catch(error => {
console.log(error)
process.exit()
})
}
static delete(input){
tags.destroy({where : {id : input}}).then(
data => {
View.deleteData(input)
process.exit()
}
).catch(error => {
console.log(error)
process.exit()
})
}
}

module.exports = Author;
63 changes: 63 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const Author = require('./controllers/cont_author.js')
const Tag = require('./controllers/cont_tag.js')
const Article = require('./controllers/cont_article.js')
const View = require('./views');

const category = process.argv[2]
const task = process.argv[3]
const input = process.argv.splice(4)

if(category === 'author'){
if(task === 'read_all'){
Author.readAll()
}
else if(task === 'read_one'){
Author.readOne(input)
}
else if(task === 'add'){
Author.add(input)
}
else if(task === 'update'){
Author.update(input)
}
else if(task === 'delete'){
Author.delete(input)
}
}
else if(category === 'tag'){
if(task === 'read_all'){
Tag.readAll()
}
else if(task === 'read_one'){
Tag.readOne(input)
}
else if(task === 'add'){
Tag.add(input)
}
else if(task === 'update'){
Tag.update(input)
}
else if(task === 'delete'){
Tag.delete(input)
}
}
else if(category === 'article'){
if(task === 'read_all'){
Article.readAll()
}
else if(task === 'read_one'){
Article.readOne(input)
}
else if(task === 'add'){
Article.add(input)
}
else if(task === 'update'){
Article.update(input)
}
else if(task === 'delete'){
Article.delete(input)
}
}
else {
View.showHelp()
}
39 changes: 39 additions & 0 deletions migrations/20180221084115-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/20180221102540-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