-
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
15 changed files
with
283 additions
and
35 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './checkToken'; | ||
export * from './checkDb'; | ||
export * from './validations/highlightsValidations'; |
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,34 @@ | ||
import db from '../../models'; | ||
|
||
const { | ||
articles | ||
} = db; | ||
|
||
export const checkHighlightAndComment = async (req, res, next) => { | ||
const { | ||
highlight, startIndex, stopIndex, comment | ||
} = req.body; | ||
const { articleSlug } = req.params; | ||
const article = await articles.findOne({ | ||
where: { slug: articleSlug } | ||
}); | ||
if (!article) { | ||
return res.status(404).json({ error: 'failed to find article' }); | ||
} | ||
switch (true) { | ||
case highlight === null || highlight === undefined | ||
|| highlight === '' || startIndex === null | ||
|| startIndex === undefined || startIndex === '' | ||
|| stopIndex === null || stopIndex === undefined | ||
|| stopIndex === '' || comment === null | ||
|| comment === undefined || comment === '': | ||
return res.status(400).json({ error: 'highlight, startIndex, stopIndex and comment cannot be left empty' }); | ||
case typeof startIndex === 'string' || stopIndex === 'string': | ||
return res.status(400).json({ error: 'startIndex and stopIndex can only be number' }); | ||
case stopIndex > article.body.length: | ||
return res.status(400).json({ error: 'stopIndex is invalid' }); | ||
case startIndex < 0: | ||
return res.status(400).json({ error: 'startIndex is invalid' }); | ||
} | ||
next(); | ||
}; |
File renamed without changes.
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,52 @@ | ||
export const up = (queryInterface, Sequelize) => queryInterface.createTable('highlightArticleComments', { | ||
id: { | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
allowNull: false, | ||
primaryKey: true | ||
}, | ||
startIndex: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false | ||
}, | ||
stopIndex: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false | ||
}, | ||
highlight: { | ||
type: Sequelize.TEXT, | ||
allowNull: false | ||
}, | ||
comment: { | ||
type: Sequelize.TEXT, | ||
allowNull: false | ||
}, | ||
articleSlug: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
references: { | ||
model: 'articles', | ||
key: 'slug' | ||
} | ||
}, | ||
authorId: { | ||
type: Sequelize.UUID, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
references: { | ||
model: 'users', | ||
key: 'id' | ||
} | ||
}, | ||
createdAt: { | ||
type: Sequelize.DATE, | ||
default: true | ||
}, | ||
updatedAt: { | ||
type: Sequelize.DATE, | ||
default: true | ||
} | ||
}); | ||
|
||
export const down = queryInterface => queryInterface.dropTable('highlightArticleComments'); |
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,58 @@ | ||
export default (sequelize, DataTypes) => { | ||
const highlightArticleComments = sequelize.define('highlightArticleComments', { | ||
id: { | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
allowNull: false, | ||
primaryKey: true | ||
}, | ||
startIndex: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
stopIndex: { | ||
type: DataTypes.INTEGER, | ||
allowNull: false | ||
}, | ||
highlight: { | ||
type: DataTypes.TEXT, | ||
allowNull: false | ||
}, | ||
comment: { | ||
type: DataTypes.TEXT, | ||
allowNull: false | ||
}, | ||
articleSlug: { | ||
type: DataTypes.STRING, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
references: { | ||
model: 'articles', | ||
key: 'slug' | ||
} | ||
}, | ||
authorId: { | ||
type: DataTypes.UUID, | ||
allowNull: false, | ||
onDelete: 'CASCADE', | ||
references: { | ||
model: 'users', | ||
key: 'id' | ||
} | ||
}, | ||
createdAt: { | ||
type: DataTypes.DATE, | ||
default: true | ||
}, | ||
updatedAt: { | ||
type: DataTypes.DATE, | ||
default: true | ||
} | ||
}, | ||
{}); | ||
highlightArticleComments.associate = (models) => { | ||
highlightArticleComments.belongsTo(models.users, { as: 'author', foreignKey: 'authorId' }); | ||
highlightArticleComments.belongsTo(models.articles, { foreignKey: 'articleSlug' }); | ||
}; | ||
return highlightArticleComments; | ||
}; |
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
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
Oops, something went wrong.