-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from andela/bg-create-article-bug-167345040
##167345040 Fix non-existent category error
- Loading branch information
Showing
6 changed files
with
102 additions
and
48 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
85 changes: 42 additions & 43 deletions
85
src/db/migrations/20190716203009-create-comment-history.js
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,46 +1,45 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('CommentHistories', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
up: (queryInterface, Sequelize) => { | ||
return queryInterface.createTable('CommentHistories', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'CommentHistories', | ||
key: 'id', | ||
as: 'commentHistory' | ||
}, | ||
userId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'CommentHistories', | ||
key: 'id', | ||
as: 'commentHistory' | ||
}, | ||
}, | ||
commentId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'CommentHistories', | ||
key: 'id', | ||
as: 'commentHistory' | ||
}, | ||
commentId: { | ||
type: Sequelize.INTEGER, | ||
required: true, | ||
references: { | ||
model: 'CommentHistories', | ||
key: 'id', | ||
as: 'commentHistory' | ||
}, | ||
}, | ||
commentBody: { | ||
type: Sequelize.TEXT, | ||
required: true, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('CommentHistories'); | ||
} | ||
}; | ||
|
||
}, | ||
commentBody: { | ||
type: Sequelize.STRING, | ||
required: true, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}); | ||
}, | ||
down: (queryInterface, Sequelize) => { | ||
return queryInterface.dropTable('CommentHistories'); | ||
} | ||
}; |
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
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,26 @@ | ||
import FindItem from '../helpers/findItem'; | ||
|
||
const { findCategoryById } = FindItem; | ||
|
||
/** | ||
* @description - checks if the category of the article exists | ||
* @async | ||
* @param {object} req - request object | ||
* @param {object} res - response object | ||
* @param {function} next - the next function | ||
* @returns {object} error response object | ||
*/ | ||
const checkCategoryExists = async (req, res, next) => { | ||
const { catId } = req.body; | ||
const existingCategory = await findCategoryById(catId); | ||
|
||
if (!existingCategory) { | ||
return res.status(404).json({ | ||
status: 404, | ||
message: `The category does not exist` | ||
}); | ||
} | ||
next(); | ||
}; | ||
|
||
export default checkCategoryExists; |
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
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