Skip to content

Commit

Permalink
fix(conflict): fix merge conflicts in branch
Browse files Browse the repository at this point in the history
  • Loading branch information
abejide001 committed Feb 6, 2019
2 parents 1f85942 + 7230890 commit 9a644b4
Show file tree
Hide file tree
Showing 24 changed files with 1,525 additions and 528 deletions.
File renamed without changes.
302 changes: 151 additions & 151 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/controllers/ArtsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,7 @@ class ArtsController {

const offset = limitDefault * (pageDefault - 1);

const allArticlesCount = await Art.findAndCountAll();

const pages = Math.ceil(allArticlesCount.count / limitDefault);
const articles = await Art.findAll({
const articles = await Art.findAndCountAll({
include: [
{
model: Category,
Expand Down Expand Up @@ -331,13 +328,14 @@ class ArtsController {
limit: limitDefault,
offset,
});
const pages = Math.ceil(articles.count / limitDefault);
const response = new Response(
'Ok',
200,
'All Articles',
{
articles,
articlesGrandTotal: allArticlesCount.count,
articles: articles.rows,
articlesGrandTotal: articles.count,
page: pageDefault,
pages
}
Expand Down
139 changes: 139 additions & 0 deletions src/controllers/BookmarkController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import bookmarkQuery from '../db/service/bookmark';
import Response from '../helpers/response';

/** Bookmark Controller Class */
class BookmarkController {
/**
* @static
* @desc POST /api/v1/bookmark/art/:item
* @param {object} req
* @param {object} res
* @memberof BookmarkController
* @returns {object} res
*/
static async addBookmark(req, res) {
const { artId } = req.params;
const { verifyUser } = req;

try {
const addBookmarkResponse = await bookmarkQuery
.addBookmark(artId, verifyUser.id);
/** check if bookmark was added successfully */
if (addBookmarkResponse) {
const response = new Response(
'Created',
201,
'Bookmark has been added',
addBookmarkResponse
);
return res.status(response.code).json(response);
}
/** Return response if bookmark has preoviously been added */
if (!addBookmarkResponse) {
const response = new Response(
'Conflict',
409,
`User has already bookmarked this Item : ${artId}`
);
return res.status(response.code).json(response);
}
} catch (error) {
const response = new Response(
'Internal Server Error',
500,
`${error}`
);
return res.status(response.code).json(response);
}
}

/**
* @static
* @desc DELETE /api/v1/bookmark/:bookmarkId
* @param {object} req
* @param {object} res
* @memberof BookmarkController
* @returns {object} res
*/
static async removeBookmark(req, res) {
const { bookmarkId } = req.params;
try {
const removebookmarkResponse = await bookmarkQuery
.removeBookmark(bookmarkId);

/** Check if bookmark was not deleted */
if (removebookmarkResponse === 0) {
const response = new Response(
'Not Found',
404,
'Bookmark does not exist or has previously been deleted',
);
return res.status(response.code).json(response);
}

/** Check if bookmark was deleted successfully */
if (removebookmarkResponse === 1) {
const response = new Response(
'Accepted',
202,
'Bookmark has successfully been deleted'
);
return res.status(response.code).json(response);
}
} catch (error) {
const response = new Response(
'Internal Server Error',
500,
`${error}`
);
return res.status(response.code).json(response);
}
}

/**
* @static
* @desc GET /api/v1/bookmark/
* @param {object} req
* @param {object} res
* @memberof BookmarkController
* @returns {object} res
*/
static async getUserBookmarks(req, res) {
const { verifyUser } = req;

try {
const userBookmarks = await bookmarkQuery
.getUserBookmarks(verifyUser.id);

/** Return Bookmarks found for User */
if (userBookmarks.length > 0) {
const response = new Response(
'Ok',
200,
`${userBookmarks.length} Bookmarks found for user`,
userBookmarks
);
return res.status(response.code).json(response);
}
/** Check if no bookmark found for user */
if (userBookmarks.length === 0) {
const response = new Response(
'Not Found',
404,
'No Bookmarks was found for User',
userBookmarks
);
return res.status(response.code).json(response);
}
} catch (error) {
const response = new Response(
'Internal Server Error',
500,
`${error}`
);
return res.status(response.code).json(response);
}
}
}

export default BookmarkController;
76 changes: 74 additions & 2 deletions src/controllers/CommentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,47 @@ class CommentsController {
* @static
* @param {Object} req
* @param {object} res
* @return {object} updated comment
* @return {object} comment
*/
static async getAllComments(req, res) {
const { lastId } = req.query;
const { artId } = req.params;
const { limit } = req.query;
try {
const getComments = await Comment.findAll({
order: [
['id', 'DESC'],
],
where: {
artId,
id: {
$lt: lastId
}
},
limit,
});
const response = new Response(
'Ok',
200,
'Success',
getComments
);
return res.status(response.code).json(response);
} catch (err) {
const response = new Response(
'Not ok',
500,
`${err}`,
);
return res.status(response.code).json(response);
}
}

/**
* @static
* @param {Object} req
* @param {object} res
* @return {object} comment
*/
static async updateComment(req, res) {
try {
Expand Down Expand Up @@ -96,7 +136,39 @@ class CommentsController {
* @static
* @param {Object} req
* @param {object} res
* @return {object} Edit history comment
* @return {object} deleted comment
*/
static async deleteComment(req, res) {
try {
const { commentId } = req.params;
await Comment.destroy(
{
where: {
id: commentId
}
}
);
const response = new Response(
'Ok',
200,
'Comment deleted successfully',
);
return res.status(response.code).json(response);
} catch (err) {
const response = new Response(
'Not ok',
500,
`${err}`,
);
return res.status(response.code).json(response);
}
}

/**
* @static
* @param {Object} req
* @param {object} res
* @return {object} comment
*/
static async getEditHistory(req, res) {
try {
Expand Down
38 changes: 38 additions & 0 deletions src/db/migrations/20190123113527-create-bookmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module.exports = {
up: (
queryInterface,
Sequelize
) => queryInterface.createTable('Bookmarks', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
artId: {
type: Sequelize.INTEGER,
references: {
model: 'Arts',
key: 'id',
as: 'artId',
}
},
userId: {
type: Sequelize.INTEGER,
references: {
model: 'Users',
key: 'id',
as: 'userId',
}
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}),
down: queryInterface => queryInterface.dropTable('Bookmarks')
};
5 changes: 5 additions & 0 deletions src/db/models/art.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ module.exports = (sequelize, DataTypes) => {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
Art.hasMany(models.Bookmark, {
foreignKey: 'artId',
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
Art.hasMany(models.Report, {
foreignKey: 'artId'
});
Expand Down
19 changes: 19 additions & 0 deletions src/db/models/bookmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = (sequelize, DataTypes) => {
const Bookmark = sequelize.define('Bookmark', {
artId: DataTypes.INTEGER,
userId: DataTypes.INTEGER
}, {});
Bookmark.associate = (models) => {
Bookmark.belongsTo(models.Art, {
foreignKey: 'artId',
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
Bookmark.belongsTo(models.User, {
foreignKey: 'userId',
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
});
};
return Bookmark;
};
3 changes: 3 additions & 0 deletions src/db/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module.exports = (sequelize, DataTypes) => {
User.hasMany(models.Comment, {
foreignKey: 'userId'
});
User.hasMany(models.Bookmark, {
foreignKey: 'userId'
});
User.hasMany(models.Report, {
foreignKey: 'userId'
});
Expand Down
37 changes: 0 additions & 37 deletions src/db/seeders/a_rateSeeder.js

This file was deleted.

Loading

0 comments on commit 9a644b4

Please sign in to comment.