-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sharing-article): users should be able to share an article
- create the endpoints of social networks sharing with validation as middleware - unit test and swagger documention [Finishes #166789890]
- Loading branch information
Showing
6 changed files
with
304 additions
and
0 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,66 @@ | ||
import open from 'open'; | ||
|
||
/** | ||
* share article controller | ||
*/ | ||
class ShareArticleManager { | ||
/** | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns{object} object of response with open new email window | ||
*/ | ||
static async shareOnEmail(req, res) { | ||
const { title, link } = req.article; | ||
res.status(200).send({ | ||
message: 'Article shared on E-mail', | ||
link | ||
}); | ||
open(`mailto:?subject=${title}&body=${link}`); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns{object} object of response with open new twitter window | ||
*/ | ||
static async shareOnTwitter(req, res) { | ||
const { link } = req.article; | ||
res.status(200).send({ | ||
message: 'Article shared on Twitter', | ||
link | ||
}); | ||
open(`https://twitter.com/intent/tweet?url=${link}`); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns{object} object of response with open new facebook window | ||
*/ | ||
static async shareOnFacebook(req, res) { | ||
const { link: shareLink } = req.article; | ||
res.status(200).send({ | ||
message: 'Post shared on Facebook', | ||
shareLink | ||
}); | ||
open(`https:www.facebook.com/sharer/sharer.php?u=${shareLink}`); | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} req | ||
* @param {object} res | ||
* @returns{object} object of response with open new Whatsapp window | ||
*/ | ||
static async shareOnWhatsapp(req, res) { | ||
res.status(200).send({ | ||
message: 'Article shared on Whatsapp', | ||
whatsapp: req.article.link | ||
}); | ||
open(`https://wa.me/?text=${req.article.link}`); | ||
} | ||
} | ||
export default ShareArticleManager; |
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