-
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.
feat: implement share highlights across several platforms
- Loading branch information
Mireille Niwemuhuza
authored and
Mireille Niwemuhuza
committed
Jul 16, 2019
1 parent
ab95184
commit a71ad68
Showing
8 changed files
with
269 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @Author - Mireille Niwemuhuza | ||
*/ | ||
class shareHighlightController { | ||
/** | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns {object} Object representing the response returned | ||
*/ | ||
|
||
// eslint-disable-next-line require-jsdoc | ||
static async shareHighlights(req, res) { | ||
// const { id } = req.user; | ||
return res.status(200).json({ | ||
message: 'Highlight shared!', | ||
}); | ||
} | ||
} | ||
|
||
export default shareHighlightController; |
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,41 @@ | ||
import models from '../sequelize/models'; | ||
|
||
const { Article, Highlights } = models; | ||
|
||
/** | ||
* @class checkHighlight | ||
* @description a class to check if a highlight belongs to an article | ||
*/ | ||
export default class checkHighlight { | ||
/** | ||
* Verify if a highlight belongs to an article | ||
* @param {Object} req - Request | ||
* @param {Object} res - Response | ||
* @param {Function} next -Next | ||
* @returns {Object} The response object | ||
*/ | ||
static async highlights(req, res, next) { | ||
const { slug, highlightId } = req.params; | ||
const checkHighlights = await Highlights.findAll({ | ||
where: { | ||
id: highlightId | ||
} | ||
}); | ||
const getArticleId = await Article.findAll({ | ||
where: { | ||
slug | ||
} | ||
}); | ||
if (!checkHighlights[0]) { | ||
return res.status(400).json({ | ||
message: 'This higlight does not exist!' | ||
}); | ||
} | ||
if (checkHighlights[0].dataValues.articleId !== getArticleId[0].dataValues.id) { | ||
return res.status(400).json({ | ||
message: 'This higlight does not belong to that article!' | ||
}); | ||
} | ||
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,40 @@ | ||
import open from 'open'; | ||
import dotenv from 'dotenv'; | ||
import share from 'social-share'; | ||
import db from '../sequelize/models'; | ||
|
||
dotenv.config(); | ||
const { Article, Highlights, User } = db; | ||
const { APP_URL_FRONTEND } = process.env; | ||
|
||
export default async (req, res, next) => { | ||
const { slug, highlightId } = req.params; | ||
const { title, authorId, gallery } = await Article.findOne({ where: { slug } }); | ||
const { firstName, lastName } = await User.findOne({ where: { id: authorId } }); | ||
const { highlightText } = await Highlights.findOne({ where: { id: highlightId } }); | ||
if (gallery) { | ||
const image = gallery[0]; | ||
if (req.url.search(/\/twitter/g) > 0) { | ||
const url = share('twitter', { | ||
url: `${APP_URL_FRONTEND}/api/articles/${slug}`, | ||
title: `${highlightText} - written by ${firstName} ${lastName} ${gallery[0]}` | ||
}); | ||
await open(`${url}`, `${title}`, { wait: false }); | ||
} else if (req.url.search(/\/facebook/g) > 0) { | ||
const url = share('facebook', { | ||
url: `${APP_URL_FRONTEND}/api/articles/${slug}`, | ||
title: `${highlightText} - written by ${firstName} ${lastName} ${image}` | ||
}); | ||
await open(`${url}`, `${title}`, { wait: false }); | ||
} else if (req.url.search(/\/email/g) > 0) { | ||
const highTitle = `${highlightText} - written by ${firstName} ${lastName} ${image}`; | ||
await open( | ||
`mailto:?subject=${title}&body=${highTitle} ${APP_URL_FRONTEND}/articles/${slug}`, | ||
{ | ||
wait: false | ||
} | ||
); | ||
} | ||
} | ||
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
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