-
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.
ft(sharing-articles):user-can-share-articles-on-socialMedias
- Loading branch information
1 parent
306cab5
commit 783f72d
Showing
11 changed files
with
178 additions
and
38 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
env: | ||
global: | ||
- APP_URL_FRONTEND=http://localhost:3000/api | ||
language: node_js | ||
node_js: | ||
- 'stable' | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import open from 'open'; | ||
import dotenv from 'dotenv'; | ||
import share from 'social-share'; | ||
import db from '../sequelize/models'; | ||
|
||
dotenv.config(); | ||
const { Article } = db; | ||
const { APP_URL_FRONTEND } = process.env; | ||
|
||
export default async (req, res, next) => { | ||
const { slug } = req.params; | ||
const { title } = await Article.findOne({ where: { slug } }); | ||
if (req.url.search(/\/twitter/g) > 0) { | ||
const url = share('twitter', { url: `${APP_URL_FRONTEND}/api/articles/${slug}` }); | ||
await open(`${url}`, { wait: false }); | ||
} else if (req.url.search(/\/facebook/g) > 0) { | ||
const url = share('facebook', { url: `${APP_URL_FRONTEND}/api/articles/${slug}` }); | ||
await open(`${url}`, { wait: false }); | ||
} else if (req.url.search(/\/email/g) > 0) { | ||
await open( | ||
`mailto:?subject=${title}&body=${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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import models from '../sequelize/models'; | ||
|
||
const usernameAvailability = { | ||
async usernameExist(req, res, next) { | ||
const { username } = req.params; | ||
const user = await models.User.findAll({ | ||
where: { | ||
username | ||
} | ||
}); | ||
if (!user.length) { | ||
return res.status(404).json({ | ||
error: 'username does not exist' | ||
}); | ||
} | ||
|
||
next(); | ||
} | ||
}; | ||
|
||
export default usernameAvailability; |
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,39 +1,26 @@ | ||
module.exports = { | ||
up: queryInterface => queryInterface.bulkInsert('Articles', [ | ||
{ | ||
slug: '73H7812', | ||
title: 'How to survive at Andela', | ||
description: 'YoYo', | ||
body: | ||
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', | ||
image: '', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
readtime: '2 min' | ||
}, | ||
{ | ||
slug: '73H99992', | ||
title: 'Wow', | ||
description: 'YoYo', | ||
readtime: '2 min', | ||
body: | ||
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', | ||
image: '', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
{ | ||
slug: 'This_is_andela_2433546h34', | ||
title: 'Wow', | ||
description: 'YoYo', | ||
readtime: '2 min', | ||
body: | ||
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', | ||
image: '', | ||
createdAt: new Date(), | ||
updatedAt: new Date() | ||
} | ||
]), | ||
|
||
up: queryInterface => queryInterface.bulkInsert('Articles', [{ | ||
slug: '73H7812', | ||
title: 'How to survive at Andela', | ||
authorId: '1', | ||
description: 'YoYo', | ||
body: | ||
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', | ||
image: '', | ||
readtime: '1min', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, { | ||
slug: '73H99992', | ||
title: 'Wow', | ||
description: 'YoYo', | ||
authorId: '2', | ||
body: | ||
'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', | ||
image: '', | ||
readtime: '1min', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}]), | ||
down: queryInterface => queryInterface.bulkDelete('Articles', null, {}) | ||
}; |
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