-
Notifications
You must be signed in to change notification settings - Fork 5
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
11 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import { likeDislike } from '../utils/comment'; | ||
import { LikeComment } from '../models'; | ||
import { responseFormat, errorResponseFormat } from '../utils'; | ||
|
||
export const likeComment = async (req, res) => { | ||
const { id: userId } = req.user; | ||
const { id: commentId } = req.params; | ||
const condition = { userId, commentId }; | ||
try { | ||
const likeCommentResult = await likeDislike(LikeComment, condition); | ||
const { like, likeCount } = likeCommentResult; | ||
if (like) { | ||
return res.status(200).json( | ||
responseFormat({ | ||
status: 'success', | ||
data: { message: 'you successfully liked the comment', Like: likeCount }, | ||
}), | ||
); | ||
} | ||
return res.status(200).json( | ||
responseFormat({ | ||
status: 'success', | ||
data: { message: 'you successfully un-liked the comment', Like: likeCount }, | ||
}), | ||
); | ||
} catch (error) { | ||
if (error.parent.constraint === 'like_comments_commentId_fkey') { | ||
return res | ||
.status(400) | ||
.json(errorResponseFormat({ message: 'commentId is not on comment Table' })); | ||
} | ||
} | ||
}; |
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,30 @@ | ||
import { Comment } from '../models'; | ||
import { validateComment } from '../utils/comment'; | ||
import { parseErrorResponse, responseHandler } from '../utils'; | ||
import { findById } from '../utils/query'; | ||
|
||
export const commentValidation = async (req, res, next) => { | ||
const validate = await validateComment(req.body); | ||
if (validate.fails()) { | ||
const validationErrors = validate.errors.all(); | ||
const errorMessages = parseErrorResponse(validationErrors); | ||
return res.status(400).json({ | ||
status: 'fail', | ||
data: errorMessages, | ||
}); | ||
} | ||
next(); | ||
}; | ||
|
||
export const verifyComment = async (req, res, next) => { | ||
const { id } = req.params; | ||
const comment = await findById(Comment, id); | ||
if (!comment) { | ||
return responseHandler(res, 404, { status: 'fail', message: 'Comment not found!' }); | ||
} | ||
const { | ||
dataValues: { userId: authorId }, | ||
} = comment; | ||
req.authorId = authorId; | ||
next(); | ||
}; |
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,7 @@ | ||
import { LikeComment } from '../models'; | ||
|
||
export default { | ||
up: queryInterface => queryInterface.createTable(LikeComment.tableName, | ||
LikeComment.rawAttributes), | ||
down: queryInterface => queryInterface.dropTable('like_comments'), | ||
}; |
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,43 @@ | ||
/** | ||
* @name init | ||
* @param {sequelize} sequelize | ||
* @param {DataTypes} DataTypes | ||
* @returns {Model} Returns LikeArticle model | ||
*/ | ||
export default (sequelize, DataTypes) => { | ||
const LikeComment = sequelize.define( | ||
'LikeComment', | ||
{ | ||
id: { | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
allowNull: false, | ||
primaryKey: true, | ||
}, | ||
userId: { | ||
type: DataTypes.UUID, | ||
allowNull: false, | ||
}, | ||
commentId: { | ||
type: DataTypes.UUID, | ||
allowNull: false, | ||
}, | ||
}, | ||
{ | ||
tableName: 'like_comments', | ||
}, | ||
); | ||
LikeComment.associate = (models) => { | ||
LikeComment.belongsTo(models.Comment, { | ||
foreignKey: 'commentId', | ||
as: 'comment', | ||
onDelete: 'CASCADE', | ||
}); | ||
LikeComment.belongsTo(models.User, { | ||
foreignKey: 'userId', | ||
as: 'user', | ||
onDelete: 'CASCADE', | ||
}); | ||
}; | ||
return LikeComment; | ||
}; |
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,12 +1,10 @@ | ||
import baseUrl from '../../config/emailConfig'; | ||
|
||
export const subject = 'Password Reset Instruction'; | ||
|
||
export const content = resetToken => ` | ||
<div> | ||
<p>Hi, </p> | ||
<p>You requested for password reset for your account</p> | ||
<p>Please click on the following link, or paste the link in your browser to complete this process within four hours of receiving this email.</p> | ||
<p>${baseUrl}/api/v1/password-reset/${resetToken}</p> | ||
<p>${process.env.BASE_URL}/password-reset/${resetToken}</p> | ||
<p>If you did not request for this, please ignore this email.</p> | ||
</div>`; |
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,10 +1,9 @@ | ||
import baseUrl from '../../config/emailConfig'; | ||
|
||
export const subject = 'Welcome to Authors\' Haven'; | ||
|
||
export const content = (fullName, id, verificationToken) => ` | ||
<div> | ||
<p>Hi ${fullName},</p> | ||
<p>Welcome to Authors Haven, a place to be inspired! Your account was successfully created.</p> | ||
<p>Please click this ${baseUrl}/api/v1/verify/${id}/${verificationToken} to confirm your account.</p> | ||
<p>Please click this ${process.env.BASE_URL}/verify/${id}/${verificationToken} to confirm your account.</p> | ||
</div>`; |
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