Skip to content

Commit cc92278

Browse files
committed
fix: update copilot request based on the source of invite
1 parent 7c29993 commit cc92278

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const COPILOT_APPLICATION_STATUS = {
2222
PENDING: 'pending',
2323
INVITED: 'invited',
2424
ACCEPTED: 'accepted',
25+
CANCELED: 'canceled',
2526
};
2627

2728
export const COPILOT_OPPORTUNITY_STATUS = {
@@ -360,6 +361,11 @@ export const INVITE_STATUS = {
360361
CANCELED: 'canceled',
361362
};
362363

364+
export const INVITE_SOURCE = {
365+
WORK_MANAGER: "work_manager",
366+
COPILOT_PORTAL: "copilot_portal",
367+
};
368+
363369
export const SCOPE_CHANGE_REQ_STATUS = {
364370
PENDING: 'pending',
365371
APPROVED: 'approved',

src/routes/projectMemberInvites/update.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Joi from 'joi';
44
import { middleware as tcMiddleware } from 'tc-core-library-js';
55
import models from '../../models';
66
import util from '../../util';
7-
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS } from '../../constants';
7+
import { INVITE_STATUS, EVENT, RESOURCES, COPILOT_APPLICATION_STATUS, COPILOT_OPPORTUNITY_STATUS, COPILOT_REQUEST_STATUS, INVITE_SOURCE } from '../../constants';
88
import { PERMISSION } from '../../permissions/constants';
99

1010
/**
@@ -19,6 +19,9 @@ const updateMemberValidations = {
1919
status: Joi.any()
2020
.valid(_.values(INVITE_STATUS))
2121
.required(),
22+
source: Joi.any()
23+
.valid(_.values(INVITE_SOURCE))
24+
.default(INVITE_SOURCE.WORK_MANAGER),
2225
})
2326
.required(),
2427
};
@@ -29,6 +32,7 @@ module.exports = [
2932
permissions('projectMemberInvite.edit'),
3033
(req, res, next) => {
3134
const newStatus = req.body.status;
35+
const source = req.body.source;
3236
if (newStatus === INVITE_STATUS.CANCELED) {
3337
const err = new Error('Cannot change invite status to “canceled”. Please, delete the invite instead.');
3438
err.status = 400;
@@ -121,14 +125,23 @@ module.exports = [
121125
try {
122126
await util.addUserToProject(req, member, t);
123127
if (invite.applicationId) {
128+
let nextApplicationStatus = COPILOT_APPLICATION_STATUS.CANCELED;
129+
let nextOpportunityStatus = COPILOT_OPPORTUNITY_STATUS.CANCELED;
130+
let nextOpportunityRequestStatus = COPILOT_REQUEST_STATUS.CANCELED;
131+
if (source === 'copilot_portal') {
132+
nextApplicationStatus = COPILOT_APPLICATION_STATUS.ACCEPTED;
133+
nextOpportunityStatus = COPILOT_OPPORTUNITY_STATUS.COMPLETED;
134+
nextOpportunityRequestStatus = COPILOT_REQUEST_STATUS.FULFILLED;
135+
}
136+
124137
const application = await models.CopilotApplication.findOne({
125138
where: {
126139
id: invite.applicationId,
127140
},
128141
transaction: t,
129142
});
130143

131-
await application.update({ status: COPILOT_APPLICATION_STATUS.ACCEPTED }, {
144+
await application.update({ status: nextApplicationStatus }, {
132145
transaction: t
133146
});
134147

@@ -140,7 +153,7 @@ module.exports = [
140153
});
141154

142155
await opportunity.update({
143-
status: COPILOT_OPPORTUNITY_STATUS.COMPLETED
156+
status: nextOpportunityStatus,
144157
}, {
145158
transaction: t,
146159
});
@@ -153,7 +166,7 @@ module.exports = [
153166
});
154167

155168
await request.update({
156-
status: COPILOT_REQUEST_STATUS.FULFILLED
169+
status: nextOpportunityRequestStatus,
157170
}, {
158171
transaction: t,
159172
});

0 commit comments

Comments
 (0)