Skip to content

Commit

Permalink
Merge 6765e8d into 343d9d6
Browse files Browse the repository at this point in the history
  • Loading branch information
kleva-j committed Apr 22, 2019
2 parents 343d9d6 + 6765e8d commit 3842e34
Show file tree
Hide file tree
Showing 13 changed files with 689 additions and 774 deletions.
10 changes: 7 additions & 3 deletions controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ export default class ProfileController {
});

const {
email, username, name, bio, createdAt, updatedAt
email, username, name, bio, createdAt, updatedAt, interests, image
} = foundUser;
const userProfile = {
id,
email,
username,
name,
bio,
interests,
image,
createdAt,
updatedAt
};
Expand Down Expand Up @@ -71,10 +73,12 @@ export default class ProfileController {
*/
static async editProfile(req, res) {
const { id } = req.user;
const { bio, firstname, lastname } = req.body;
const {
bio, firstname, lastname, interests
} = req.body;
const name = `${firstname} ${lastname}`;
try {
const [, [updatedProfile]] = await User.update({ bio, name }, {
const [, [updatedProfile]] = await User.update({ bio, name, interests }, {
returning: true,
raw: true,
where: { id }
Expand Down
11 changes: 6 additions & 5 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import sendMail from '../helpers/emails';
import getName from '../helpers/user';
import { User } from '../models';

const { HOST_URL_FRONTEND } = process.env;

dotenv.config();
const { JWT_SECRET } = process.env;

const { HOST_URL_FRONTEND, JWT_SECRET } = process.env;

const generateToken = (id, expiresIn = '24h') => jwt.sign({ id }, JWT_SECRET, { expiresIn });

/**
Expand All @@ -30,14 +30,15 @@ export default class UserController {
static registerUser(req, res) {
const {
body: {
email, username, password, name
email, username, password, name, interests
}
} = req;
User.create({
email,
username,
password,
name
name,
interests
})
.then((newUser) => {
const {
Expand Down
11 changes: 10 additions & 1 deletion middleware/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export const validateCommentExist = async (req, res, next) => {
}
};


export const validateArticleExist = async (req, res, next) => {
const { slug } = req.params;
try {
Expand Down Expand Up @@ -306,3 +305,13 @@ export const validateImages = [
.exists()
.withMessage('An image file should be uploaded to complete this request')
];

export const validateInterest = (req, res, next) => {
const { body: { interests } } = req;
if (interests) {
req.body.interests = interests
.split(',')
.map(interest => interest.replace(/(\[|\])/, '').trim().toLowerCase());
}
return next();
};
19 changes: 19 additions & 0 deletions migrations/20190417100155-interest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'Users',
'interests',
{
type: Sequelize.ARRAY(Sequelize.STRING),
allowNull: true,
unique: false,
defaultValue: [],
}
),

down(queryInterface) {
return queryInterface.removeColumn(
'Users',
'interests'
);
},
};
6 changes: 6 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ module.exports = (sequelize, DataTypes) => {
type: DataTypes.STRING,
allowNull: false,
defaultValue: 'https://img.icons8.com/ios-glyphs/30/000000/user-male.png'
},
interests: {
type: DataTypes.ARRAY(DataTypes.STRING),
allowNull: true,
unique: false,
defaultValue: [],
}
};

Expand Down
Loading

0 comments on commit 3842e34

Please sign in to comment.