Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement feedback #28

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions server/controllers/DocumentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DocumentController {
});
})
.catch((error) => {
res.status(400).json(error);
res.status(500).json({ message: 'An Error Ocurred', error });
});
}

Expand All @@ -129,7 +129,7 @@ class DocumentController {
});
}
return res.status(200).json(document);
}).catch(error => res.status(400).json(error));
}).catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 132 exceeds the maximum line length of 80 max-len

}

/**
Expand All @@ -140,11 +140,16 @@ class DocumentController {
*/
static update(req, res) {
return Document.findById(req.params.documentId).then((document) => {
if (!document) {
return res.status(404).json({
message: 'Document Not Found'
});
}
return document
.update(req.body)
.then(() => res.status(200).json(document))
.catch(error => res.status(400).json(error));
});
}).catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 152 exceeds the maximum line length of 80 max-len

}

/**
Expand All @@ -155,10 +160,15 @@ class DocumentController {
*/
static delete(req, res) {
return Document.findById(req.params.documentId).then((document) => {
if (!document) {
return res.status(404).json({
message: 'Document Not Found'
});
}
return document.destroy()
.then(() => res.send(200))
.catch(error => res.status(400).json(error));
});
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 170 exceeds the maximum line length of 80 max-len

}).catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 171 exceeds the maximum line length of 80 max-len

}
}
export default DocumentController;
11 changes: 6 additions & 5 deletions server/controllers/RoleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RoleController {
static list(req, res) {
return Role.all()
.then(roles => res.status(200).json(roles))
.catch(error => res.status(400).json(error));
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 32 exceeds the maximum line length of 80 max-len

}

/**
Expand All @@ -48,7 +48,7 @@ class RoleController {
}
return res.status(200).json(roles);
})
.catch(error => res.status(400).json(error));
.catch(error => res.status(500).json(error));
}

/**
Expand All @@ -72,7 +72,7 @@ class RoleController {
.then(() => res.status(200).json(roles))
.catch(error => res.status(400).json(error));
})
.catch(error => res.status(400).json(error));
.catch(error => res.status(500).json(error));
}

/**
Expand All @@ -91,9 +91,10 @@ class RoleController {
}
return roles
.destroy()
.then(() => res.send(200));
.then(() => res.send(200))
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));
})
.catch(error => res.status(400).json(error));
.catch(error => res.status(500).json(error));
}
}

Expand Down
94 changes: 65 additions & 29 deletions server/controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class UserController {
return res.status(401).json({ message: 'Wrong Password' });
}
})
.catch(error => res.status(400).json(error));
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 139 exceeds the maximum line length of 80 max-len

}

/**
Expand Down Expand Up @@ -168,7 +168,8 @@ class UserController {
$or: [
{ username: { $iLike: `%${search}%` } },
{ firstname: { $iLike: `%${search}%` } },
{ lastname: { $iLike: `%${search}%` } }],
{ lastname: { $iLike: `%${search}%` } }
],
$not: [{ id: req.decoded.id }]
},
include: [{ model: Role }],
Expand Down Expand Up @@ -198,7 +199,7 @@ class UserController {
});
})
.catch((error) => {
res.status(400).json(error);
res.status(500).json({ message: 'An Error Ocurred', error });
});
}

Expand All @@ -212,9 +213,14 @@ class UserController {
* @memberof UserController
*/
static find(req, res) {
return User.findById(req.params.id).then((user) => {
return res.status(200).json(userInfo(user));
}).catch(error => res.status(400).json(error));
return User.findById(req.params.id)
.then((user) => {
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
return res.status(200).json(userInfo(user));
})
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 223 exceeds the maximum line length of 80 max-len

}

/**
Expand All @@ -229,6 +235,20 @@ class UserController {
*/
static update(req, res) {
return User.findById(req.params.id).then((user) => {
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
if (req.body.email || req.body.username) {
User.findOne({
where: {
$or: [{ username: req.body.username }, { email: req.body.email }]
}
}).then((existingUser) => {
if (existingUser) {
return res.status(409).send({ message: 'Email already Exist' });
}
});
}
if (req.body.password) {
req.body.password = user.encryptUpdatePassword(req.body.password);
}
Expand All @@ -237,7 +257,9 @@ class UserController {
.then((user) => {
res.status(200).json(userInfo(user));
})
.catch(error => res.status(400).json(error));
.catch(error =>
res.status(500).json({ message: 'An Error Ocurred', error })
);
});
}

Expand All @@ -252,8 +274,15 @@ class UserController {
*/
static delete(req, res) {
return User.findById(req.params.id).then((user) => {
return user.destroy().then(() => res.send(200))
.catch(error => res.status(400).json(error));
if (!user) {
return res.status(404).json({ message: 'User not found' });
}
return user
.destroy()
.then(() => res.send(200))
.catch(error =>
res.status(500).json({ message: 'An Error Ocurred', error })
);
});
}

Expand All @@ -274,12 +303,17 @@ class UserController {
let query;
if (req.decoded) {
query = req.decoded.roleId === 2
? { title: { $iLike: search },
? {
title: { $iLike: search },
$or: [
{ $and: [{ access: 'private' }, { userId: req.decoded.id }] },
{ userId: req.params.id,
{
userId: req.params.id,
$or: [{ access: 'public' }, { access: 'role' }]
}] } : { userId: req.params.id, title: { $iLike: search } };
}
]
}
: { userId: req.params.id, title: { $iLike: search } };
}
Document.findAndCountAll({
where: query,
Expand All @@ -300,23 +334,25 @@ class UserController {
limit: req.query.limit || 15,
offset: req.query.offset || 0,
order: [['createdAt', 'DESC']]
}).then((document) => {
const limit = req.query.limit || 15;
const offset = req.query.offset || 0;
const totalCount = document.count;
const pageCount = Math.ceil(totalCount / limit);
const currentPage = Math.floor(offset / limit) + 1;
return res.status(200).json({
document: document.rows,
pagination: {
totalCount,
limit,
offset,
pageCount,
currentPage
}
});
}).catch(error => res.status(400).json(error));
})
.then((document) => {
const limit = req.query.limit || 15;
const offset = req.query.offset || 0;
const totalCount = document.count;
const pageCount = Math.ceil(totalCount / limit);
const currentPage = Math.floor(offset / limit) + 1;
return res.status(200).json({
document: document.rows,
pagination: {
totalCount,
limit,
offset,
pageCount,
currentPage
}
});
})
.catch(error => res.status(500).json({ message: 'An Error Ocurred', error }));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 355 exceeds the maximum line length of 80 max-len

}
}

Expand Down
6 changes: 3 additions & 3 deletions server/test/api/role.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('Role', () => {
.get('/roles/3000000000')
.set({ authorization: adminToken })
.end((err, res) => {
expect(res.status).to.equal(400);
expect(res.status).to.equal(500);
expect(res.body).to.be.a('object');
expect(res.body.message).to.eql(
'value "3000000000" is out of range for type integer'
Expand Down Expand Up @@ -212,7 +212,7 @@ describe('Role', () => {
.set({ authorization: adminToken })
.send({ name: 'team7' })
.end((err, res) => {
expect(res.status).to.equal(400);
expect(res.status).to.equal(500);
expect(res.body).to.be.a('object');
expect(res.body.message).to.eql(
'value "3000000000" is out of range for type integer'
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('Role', () => {
.delete('/roles/3000000000')
.set({ authorization: adminToken })
.end((err, res) => {
expect(res.status).to.equal(400);
expect(res.status).to.equal(500);
expect(res.body).to.be.a('object');
expect(res.body.message).to.eql(
'value "3000000000" is out of range for type integer'
Expand Down
4 changes: 2 additions & 2 deletions server/test/api/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ describe('User', () => {
.set({ authorization: regularToken })
.send({ email: TestUser3.email })
.end((err, res) => {
expect(res.status).to.equal(400);
expect(res.status).to.equal(409);
expect(res.body).to.be.a('object');
expect(res.body.message).to.eql('Email already exist');
expect(res.body.message).to.eql('Email already Exist');
done();
});
});
Expand Down