Skip to content

Commit

Permalink
fix(join requests): backwards compatible status
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Apr 16, 2020
1 parent e052c79 commit e359c47
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions middlewares/join-requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports.changeRequestStatus = async (req, res) => {
return errors.makeForbiddenError(res, 'Permission process:join_request is required, but not present.');
}

if (!['accepted', 'rejected'].includes(req.body.status)) {
if (!['approved', 'rejected'].includes(req.body.status)) {
return errors.makeBadRequestError(res, 'The status is invalid.');
}

Expand All @@ -103,14 +103,15 @@ exports.changeRequestStatus = async (req, res) => {
}

await sequelize.transaction(async (t) => {
// if a join request is accepted, then create a new body membership
// if a join request is approved, then create a new body membership
// but store the join request (for history)
// if a join request is rejected, just delete it so a person can reapply.
if (req.body.status === 'accepted') {
if (req.body.status === 'approved') {
await BodyMembership.create({
user_id: req.currentJoinRequest.user_id,
body_id: req.currentBody.id
}, { transaction: t });
await req.currentJoinRequest.update({ status: req.body.status });
} else {
await req.currentJoinRequest.destroy();
}
Expand Down
6 changes: 3 additions & 3 deletions models/JoinRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const JoinRequest = sequelize.define('join_request', {
allowNull: true
},
status: {
type: Sequelize.ENUM('pending', 'accepted'),
type: Sequelize.ENUM('pending', 'approved'),
allowNull: false,
defaultValue: 'pending',
validate: {
isIn: {
args: [['pending', 'accepted']],
msg: 'Status should be one of these: "pending", "accepted".'
args: [['pending', 'approved']],
msg: 'Status should be one of these: "pending", "approved".'
}
}
},
Expand Down

0 comments on commit e359c47

Please sign in to comment.