Skip to content

Commit

Permalink
feat(notification): Send notification to users
Browse files Browse the repository at this point in the history
- write unit test
- send email notification to users
- create database on firebase
- set up firebase configuration
- populate database with user notifications

[Delivers #159206059]
  • Loading branch information
Olumide Ogundele authored and anneKay committed Sep 2, 2018
1 parent 1dd2cba commit ef41cd2
Show file tree
Hide file tree
Showing 29 changed files with 3,042 additions and 468 deletions.
13 changes: 13 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,16 @@ GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
FACEBOOK_APP_ID=
FACEBOOK_APP_SECRET=
PROJECT_ID=
CLIENT_EMAIL=
PRIVATE_KEY=
DB_URL=
PROJECT_KEY_ID=
AUTH_URI=
TOKEN_URI=
AUTH_PROVIDER_X509_CERT_URL=
CLIENT_X509_CERT_URL=
SECRETE_KEY=
VERIFYTOKEN_EXPIRY=
URL_HOST=
NO_REPLY_MAIL=
1 change: 0 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { } from 'dotenv/config';
module.exports = {
development: {
username: process.env.DB_USER,
Expand Down
12 changes: 12 additions & 0 deletions config/serviceAccount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
type: 'service_account',
project_id: process.env.PROJECT_ID,
private_key_id: process.env.PRIVATE_KEY_ID,
private_key: process.env.PRIVATE_KEY.replace(/\\n/g, '\n'),
client_email: process.env.CLIENT_EMAIL,
client_id: process.env.CLIENT_ID,
auth_uri: process.env.AUTH_URI,
token_uri: process.env.TOKEN_URI,
auth_provider_x509_cert_url: process.env.AUTH_PROVIDER_X509_CERT_URL,
client_x509_cert_url: process.env.CLIENT_X509_CERT_URL
};
1 change: 0 additions & 1 deletion controllers/ArticleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ArticleController {
.catch(() => createArticleHelper(res, articleObject));
}

// if there no image was provided go ahead to create the article
return createArticleHelper(res, articleObject);
}

Expand Down
138 changes: 94 additions & 44 deletions controllers/UsersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,28 @@ export default class UsersController {
}
User.find({
where: {
[Op.or]: [{ email }, { username }]
[Op.or]: [{ email }, { username }],
},
}).then((user) => {
if (!user) {
User.create({
email,
username,
hashedPassword: hash,
}).then((registeredUser) => {
const token = utils.signToken({ id: registeredUser.id });
sendVerificationEmail.sendEmail(registeredUser);
res.status(200).json(utils.userToJson(registeredUser, token));
}).catch(next);
} else {
res.status(409).json({
success: false,
errors: {
body: ['Username or email already exists'],
}
});
}
})
.then((user) => {
if (!user) {
User.create({
email,
username,
hashedPassword: hash
})
.then((registeredUser) => {
const token = utils.signToken({ id: registeredUser.id });
sendVerificationEmail.sendEmail(registeredUser);
res.status(200).json(utils.userToJson(registeredUser, token));
})
.catch(next);
} else {
res.status(409).json({
success: false,
errors: {
body: ['Username or email already exists']
}
});
}
})
.catch(next);
});
}
Expand Down Expand Up @@ -96,14 +93,14 @@ export default class UsersController {
}

/**
* @function editProfile
* @summary Returns a user's details for their profile
* @param {object} req - Request object
* @param {object} res - Response object
* @param {*} next - Incase of errors
* @returns {object} An object containing all the data related to the user
*/
static getProfile(req, res, next) {
* @function getProfile
* @summary Returns a user's details for their profile
* @param {object} req - Request object
* @param {object} res - Response object
* @param {*} next - Incase of errors
* @returns {object} An object containing all the data related to the user
*/
static getProfile(req, res) {
User.findOne({ where: { username: req.params.username } })
.then((user) => {
if (!user) {
Expand All @@ -115,8 +112,7 @@ export default class UsersController {
});
}
return res.status(200).json(utils.userToJson(user));
})
.catch(next);
});
}

/**
Expand All @@ -140,17 +136,14 @@ export default class UsersController {
});
}
if (req.userId === user.id) {
User.update(
{
username,
image,
bio
},
{
returning: true,
where: { id: user.id }
}
)
User.update({
username,
image,
bio,
}, {
returning: true,
where: { id: user.id }
})
.then(([rows, [updatedUser]]) => {
if (rows === 0) {
return res.status(401).json({
Expand All @@ -168,6 +161,63 @@ export default class UsersController {
.catch(next);
}

/**
* Handles the unfollow feature
* @param {*} req
* @param {*} res
* @param {*} next
* @returns {string} - String
*/
static getAllFollowingMe(req, res, next) {
User.findAll({
attributes: ['id'],
// where: { followId: req.userId },
include: [{
model: Follow,
as: 'followingMe',
where: {
userId: req.userId
},
attributes: ['followId'],
}],
}).then((user) => {
// const following = user[0].followings;
res.status(200).json({
user,
});
}).catch((next));
}


/**
* Handles the unfollow feature
* @param {*} req
* @param {*} res
* @param {*} next
* @returns {string} - String
*/
static getAllMyFollower(req, res, next) {
Follow.findAll({
where: { followId: req.userId },
include: [{
model: User,
as: 'myFollowers',
attributes: ['id', 'email', 'username'],
}],
attributes: { exclude: ['id', 'userId', 'followId', 'createdAt', 'updatedAt'] }
}).then((user) => {
if (user.length === 0) {
return res.status(200).json({
message: 'No followers yet'
});
}
res.status(200).json({
user
});
}).catch((next));
}


/**
* Verify the email sent to the newly registered user
* @param {*} req - request object
Expand Down
Loading

0 comments on commit ef41cd2

Please sign in to comment.