-
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
226 changed files
with
1,699 additions
and
1,179 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,2 +1,2 @@ | ||
|
||
|
||
/node_modules |
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,19 @@ | ||
FROM node:8 | ||
|
||
# Create app directory | ||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
# Install app dependencies | ||
COPY package*.json ./ | ||
|
||
|
||
# Copy app source code | ||
COPY . . | ||
|
||
# Expose port and start application | ||
EXPOSE 3000 | ||
CMD [ "npm", "start" ] | ||
|
||
RUN chmod +x startup.sh | ||
RUN npm install -g nodemon |
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,96 +1,96 @@ | ||
const sequelize = require('sequelize'); | ||
const multer = require('multer'); // up file | ||
|
||
const Book = require('../../models').Book; | ||
const Catalog = require('../../models').Catalog; | ||
const User = require('../../models').User; | ||
const Love = require('../../models').Love; | ||
|
||
// get all book | ||
exports.getAllBook = function (req, res){ | ||
Book.findAll({raw: true}).then(arrBook => { | ||
res.json(arrBook) | ||
}) | ||
}; | ||
|
||
// get a book | ||
exports.getBook = function(req, res){ | ||
Book.findOne({ | ||
where: { | ||
id: req.params.book_id | ||
}, | ||
raw: true | ||
}).then(book => res.json(book)) | ||
}; | ||
|
||
// create a book | ||
exports.createBook = function(req, res){ | ||
console.log(req.file); | ||
Book.create({ | ||
book_name: req.body.book_name, | ||
author: req.body.author, | ||
price: req.body.price, | ||
description: req.body.description, | ||
image: req.file.path, | ||
quatity: req.body.quatity, | ||
catalog_id: req.body.catalog_id | ||
}).then(book => res.json(book)) | ||
}; | ||
|
||
// get all book by catalog_id | ||
exports.getBookByCatalogId = function(req, res){ | ||
Book.findAll({ | ||
where: { | ||
catalog_id: req.params.catalog_id | ||
}, | ||
raw: true | ||
}).then(arrBook => res.json(arrBook)) | ||
}; | ||
|
||
// search book | ||
exports.searchBook = function(req, res){ | ||
Book.findAll({ | ||
include: [Catalog], | ||
raw: true | ||
}).then(arrBook => res.json(arrBook)) | ||
}; | ||
|
||
//update book | ||
exports.updateBook = function(req, res){ | ||
Book.update({ | ||
book_name: req.body.book_name, | ||
author: req.body.author, | ||
price: req.body.price, | ||
description: req.body.description, | ||
image: req.file.path, | ||
quatity: req.body.quatity, | ||
catalog_id: req.body.catalog_id | ||
}, | ||
{ | ||
where:{ | ||
book_id: req.params.book_id | ||
} | ||
}).then(row => console.log(row)) | ||
}; | ||
|
||
// get bookLove of user | ||
exports.getBookLove = function(req, res){ | ||
Love.findAll({ | ||
where: { | ||
user_id: req.params.user_id | ||
}, | ||
include: [Book], | ||
raw: true | ||
}).then(arrBook => { | ||
let books = []; | ||
for(var i=0; i<arrBook.length; i++){ | ||
var b = { | ||
user_id : arrBook[i].user_id, | ||
book_id: arrBook[i].book_id, | ||
book_name: arrBook[i]["Book.book_name"] | ||
}; | ||
books.push(b); | ||
} | ||
res.json(arrBook); | ||
}) | ||
const sequelize = require('sequelize'); | ||
const multer = require('multer'); // up file | ||
|
||
const Book = require('../../models').Book; | ||
const Catalog = require('../../models').Catalog; | ||
const User = require('../../models').User; | ||
const Love = require('../../models').Love; | ||
|
||
// get all book | ||
exports.getAllBook = function (req, res){ | ||
Book.findAll({raw: true}).then(arrBook => { | ||
res.json(arrBook) | ||
}) | ||
}; | ||
|
||
// get a book | ||
exports.getBook = function(req, res){ | ||
Book.findOne({ | ||
where: { | ||
id: req.params.book_id | ||
}, | ||
raw: true | ||
}).then(book => res.json(book)) | ||
}; | ||
|
||
// create a book | ||
exports.createBook = function(req, res){ | ||
console.log(req.file); | ||
Book.create({ | ||
book_name: req.body.book_name, | ||
author: req.body.author, | ||
price: req.body.price, | ||
description: req.body.description, | ||
image: req.file.path, | ||
quatity: req.body.quatity, | ||
catalog_id: req.body.catalog_id | ||
}).then(book => res.json(book)) | ||
}; | ||
|
||
// get all book by catalog_id | ||
exports.getBookByCatalogId = function(req, res){ | ||
Book.findAll({ | ||
where: { | ||
catalog_id: req.params.catalog_id | ||
}, | ||
raw: true | ||
}).then(arrBook => res.json(arrBook)) | ||
}; | ||
|
||
// search book | ||
exports.searchBook = function(req, res){ | ||
Book.findAll({ | ||
include: [Catalog], | ||
raw: true | ||
}).then(arrBook => res.json(arrBook)) | ||
}; | ||
|
||
//update book | ||
exports.updateBook = function(req, res){ | ||
Book.update({ | ||
book_name: req.body.book_name, | ||
author: req.body.author, | ||
price: req.body.price, | ||
description: req.body.description, | ||
image: req.file.path, | ||
quatity: req.body.quatity, | ||
catalog_id: req.body.catalog_id | ||
}, | ||
{ | ||
where:{ | ||
book_id: req.params.book_id | ||
} | ||
}).then(row => console.log(row)) | ||
}; | ||
|
||
// get bookLove of user | ||
exports.getBookLove = function(req, res){ | ||
Love.findAll({ | ||
where: { | ||
user_id: req.params.user_id | ||
}, | ||
include: [Book], | ||
raw: true | ||
}).then(arrBook => { | ||
let books = []; | ||
for(var i=0; i<arrBook.length; i++){ | ||
var b = { | ||
user_id : arrBook[i].user_id, | ||
book_id: arrBook[i].book_id, | ||
book_name: arrBook[i]["Book.book_name"] | ||
}; | ||
books.push(b); | ||
} | ||
res.json(arrBook); | ||
}) | ||
}; |
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,22 +1,22 @@ | ||
const sequelize = require('sequelize'); | ||
const Comment = require('../../models').Comment; | ||
|
||
|
||
// get all comment by book id | ||
exports.getAllComment = function(req, res){ | ||
Comment.findAll({ | ||
where: {book_id: req.params.book_id}, | ||
raw: true | ||
}).then(comments => res.json(comments)) | ||
}; | ||
|
||
// get comment by cmt_id and book_id | ||
exports.getComment = function(req, res){ | ||
Comment.findOne({ | ||
where: { | ||
book_id: req.params.book_id, | ||
id: req.params.cmt_id | ||
}, | ||
raw: true | ||
}).then(comment => res.json(comment)) | ||
const sequelize = require('sequelize'); | ||
const Comment = require('../../models').Comment; | ||
|
||
|
||
// get all comment by book id | ||
exports.getAllComment = function(req, res){ | ||
Comment.findAll({ | ||
where: {book_id: req.params.book_id}, | ||
raw: true | ||
}).then(comments => res.json(comments)) | ||
}; | ||
|
||
// get comment by cmt_id and book_id | ||
exports.getComment = function(req, res){ | ||
Comment.findOne({ | ||
where: { | ||
book_id: req.params.book_id, | ||
id: req.params.cmt_id | ||
}, | ||
raw: true | ||
}).then(comment => res.json(comment)) | ||
}; |
Oops, something went wrong.