-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ class DocumentController { | |
}); | ||
}) | ||
.catch((error) => { | ||
res.status(400).json(error); | ||
res.status(500).json({ message: 'An Error Ocurred', error }); | ||
}); | ||
} | ||
|
||
|
@@ -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 })); | ||
} | ||
|
||
/** | ||
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 152 exceeds the maximum line length of 80 max-len |
||
} | ||
|
||
/** | ||
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 32 exceeds the maximum line length of 80 max-len |
||
} | ||
|
||
/** | ||
|
@@ -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)); | ||
} | ||
|
||
/** | ||
|
@@ -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)); | ||
} | ||
|
||
/** | ||
|
@@ -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)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 139 exceeds the maximum line length of 80 max-len |
||
} | ||
|
||
/** | ||
|
@@ -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 }], | ||
|
@@ -198,7 +199,7 @@ class UserController { | |
}); | ||
}) | ||
.catch((error) => { | ||
res.status(400).json(error); | ||
res.status(500).json({ message: 'An Error Ocurred', error }); | ||
}); | ||
} | ||
|
||
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 223 exceeds the maximum line length of 80 max-len |
||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
|
@@ -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 }) | ||
); | ||
}); | ||
} | ||
|
||
|
@@ -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 }) | ||
); | ||
}); | ||
} | ||
|
||
|
@@ -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, | ||
|
@@ -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 })); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 355 exceeds the maximum line length of 80 max-len |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
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