-
Notifications
You must be signed in to change notification settings - Fork 6
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
24 changed files
with
842 additions
and
182 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,3 +1,4 @@ | ||
{ | ||
"plugins": ["transform-es2015-destructuring", "transform-object-rest-spread"], | ||
"presets": [ "es2015" ] | ||
} |
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,47 @@ | ||
import dotenv from 'dotenv'; | ||
import { Category } from '../models'; | ||
|
||
dotenv.config(); | ||
|
||
/** | ||
* @class CategoryController | ||
* @override | ||
* @export | ||
*/ | ||
export default class CategoryController { | ||
/** | ||
* @description - Creates a new category | ||
* @static | ||
* @param {object} req - HTTP Request | ||
* @param {object} res - HTTP Response | ||
* @memberof CategoryController | ||
* @returns {object} Class instance | ||
*/ | ||
static async addNew(req, res) { | ||
const { | ||
body: { | ||
category | ||
} | ||
} = req; | ||
try { | ||
const returnValue = await Category.create({ categoryName: category }); | ||
const { dataValues: { categoryName } } = returnValue; | ||
return res.status(201).json({ | ||
success: true, | ||
message: 'Category successfully added.', | ||
categoryName | ||
}); | ||
} catch (error) { | ||
if (error.errors[0].type === 'unique violation') { | ||
return res.status(409).json({ | ||
success: false, | ||
errors: [error.errors[0].message] | ||
}); | ||
} | ||
return res.status(500).json({ | ||
success: false, | ||
errors: ['Internal server error'] | ||
}); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ module.exports = { | |
'userId' | ||
); | ||
}, | ||
}; | ||
}; |
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,24 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('Categories', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
categoryName: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
unique: true | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: queryInterface => queryInterface.dropTable('Categories') | ||
}; |
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,18 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.addColumn( | ||
'Articles', | ||
'categoryId', | ||
{ | ||
type: Sequelize.INTEGER, | ||
allowNull: true, | ||
unique: false | ||
} | ||
), | ||
|
||
down(queryInterface) { | ||
return queryInterface.removeColumn( | ||
'Articles', | ||
'categoryId' | ||
); | ||
}, | ||
}; |
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,21 @@ | ||
module.exports = { | ||
up: queryInterface => queryInterface.bulkInsert( | ||
'Categories', | ||
[ | ||
{ | ||
categoryName: 'Uncategorized', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
] | ||
), | ||
|
||
down: queryInterface => queryInterface.bulkDelete( | ||
'Categories', | ||
[ | ||
{ | ||
categoryName: 'Uncategorized' | ||
} | ||
] | ||
), | ||
}; |
Oops, something went wrong.