Skip to content

Commit

Permalink
Back-end:
Browse files Browse the repository at this point in the history
- Added PATCH /apartments/:id/groups/sign to sign a group
- Added new error - groupInvalidSigner
issues: #586 #151
  • Loading branch information
alonttal committed Jun 16, 2018
1 parent c58431a commit 8b00ec4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const GROUP_CREATION_FAILURE = 160001;
const GROUP_NOT_FOUND = 160002;
const GROUP_MEMBER_NOT_FOUND = 160003;
const GROUP_SIGN_FAILURE = 160004;
const GROUP_INVALID_SINGER = 160005;

const USER_NOT_FOUND = 170000;
const USER_UPDATE_FAILURE = 170001;
Expand All @@ -39,6 +40,7 @@ module.exports = {
groupNotFound: Error(GROUP_NOT_FOUND, 'The group was not found.'),
groupMemberNotFound: Error(GROUP_MEMBER_NOT_FOUND, 'The group member was not found.'),
groupSignFailure: Error(GROUP_SIGN_FAILURE, 'Group cannot be signed.'),
groupInvalidSigner: Error(GROUP_INVALID_SINGER, 'Group must be signed by the apartment\'s owner.'),
userNotFound: Error(USER_NOT_FOUND, 'The user was not found.'),
userUpdateFailure: Error(USER_UPDATE_FAILURE, 'Failed to update user.')
};
30 changes: 27 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ app.get('/apartments/:id/groups', async (req, res) => {

/**
* @author: Alon Talmor
* @date: 6/5/18
* @date: 5/6/18
*
* Create a new group.
* The request should include:
Expand Down Expand Up @@ -1448,13 +1448,13 @@ app.post('/apartments/:id/groups', authenticate, async (req, res) => {

/**
* @author: Alon Talmor
* @date: 6/5/18
* @date: 5/6/18
*
* Update a group.
* The initial version of this route will only support updating of the member status.
* The body should include the id of the group and the new status in the
* following way: {id, status}. A user is allowed to update ONLY his own status.
* Returns the updated apartment.
* Returns the updated apartment as a response.
*/
app.patch('/apartments/:id/groups', authenticate, async (req, res) => {
const body = _.pick(req.body, ['id', 'status']);
Expand All @@ -1469,6 +1469,30 @@ app.patch('/apartments/:id/groups', authenticate, async (req, res) => {
return res.status(BAD_REQUEST).send(error);
}
});

/**
* @author: Alon Talmor
* @date: 16/6/18
*
* change group status to COMPLETED which symbolize "Closing a Deal".
* The route may fail if the group does not hold the required criteria.
* the body of the request should contain the id of the group.
* returns the updated apartment as a response.
*/
app.patch('/apartments/:id/groups/sign', authenticate, async (req, res) => {
const body = _.pick(req.body, ['id']);
try {
let apartment = await Apartment.findById(req.params.id);
if (!apartment) {
return res.status(BAD_REQUEST).send(errors.apartmentNotFound);
}
apartment = await apartment.signGroup(body.id);
return res.send({ apartment });
} catch (error) {
return res.status(BAD_REQUEST).send(error);
}
});

/**
* @author: Alon Talmor
* @date: 28/3/18
Expand Down

0 comments on commit 8b00ec4

Please sign in to comment.