Skip to content

Commit f1021bf

Browse files
committed
fix: review comments
1 parent 7315143 commit f1021bf

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

docs/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ paths:
244244
description: Internal Server Error
245245
schema:
246246
$ref: "#/definitions/ErrorModel"
247-
"/projects/{projectId}/copilot-request":
247+
"/projects/{projectId}/copilots/request":
248248
post:
249249
tags:
250250
- projects copilot request

src/models/copilotRequest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module.exports = function defineCopilotRequest(sequelize, DataTypes) {
22
const CopliotRequest = sequelize.define('CopilotRequest', {
33
id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
4-
status: { type: DataTypes.STRING, defaultValue: 'new' },
5-
data: { type: DataTypes.JSON, defaultValue: {} },
4+
status: { type: DataTypes.STRING(16), defaultValue: 'new', allowNull: false },
5+
data: { type: DataTypes.JSON, defaultValue: {}, allowNull: false },
66

77
createdAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
88
updatedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },

src/routes/copilotRequest/create.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import models from '../../models';
66
import util from '../../util';
77
import { COPILOT_REQUEST_STATUS } from '../../constants';
88
import { PERMISSION } from '../../permissions/constants';
9+
import { Op } from 'sequelize';
910

1011
const addCopilotRequestValidations = {
1112
body: Joi.object().keys({
@@ -21,7 +22,7 @@ module.exports = [
2122
const err = new Error('Unable to create copilot request');
2223
_.assign(err, {
2324
details: JSON.stringify({ message: 'You do not have permission to create copilot request' }),
24-
status: 400,
25+
status: 403,
2526
});
2627
return Promise.reject(err);
2728
}
@@ -35,7 +36,7 @@ module.exports = [
3536
});
3637

3738
models.sequelize.transaction((transaction) => {
38-
req.log.debug('Create Copilot request transaction');
39+
req.log.debug('Create Copilot request transaction', data);
3940
return models.Project.findOne({
4041
where: { id: projectId, deletedAt: { $eq: null } },
4142
})
@@ -49,6 +50,9 @@ module.exports = [
4950
where: {
5051
createdBy: req.authUser.userId,
5152
projectId: projectId,
53+
status: {
54+
[Op.in] : [COPILOT_REQUEST_STATUS.NEW, COPILOT_REQUEST_STATUS.APPROVED, COPILOT_REQUEST_STATUS.SEEKING],
55+
}
5256
},
5357
}).then((existingCopilotRequest) => {
5458
if (existingCopilotRequest) {

src/routes/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ router.get(`/${apiVersion}/projects/health`, (req, res) => {
2828
const jwtAuth = require('tc-core-library-js').middleware.jwtAuthenticator;
2929

3030
router.all(
31-
RegExp(`\\/${apiVersion}\\/(copilot-request|projects|timelines|orgConfig|customer-payments)(?!\\/health).*`), (req, res, next) => (
31+
RegExp(`\\/${apiVersion}\\/(copilots|projects|timelines|orgConfig|customer-payments)(?!\\/health).*`), (req, res, next) => (
3232
// JWT authentication
3333
jwtAuth(config)(req, res, next)
3434
),
@@ -379,7 +379,7 @@ router.route('/v5/projects/:projectId(\\d+)/settings')
379379
.post(require('./projectSettings/create'));
380380

381381
// Project Copilot Request
382-
router.route('/v5/projects/:projectId(\\d+)/copilot-request')
382+
router.route('/v5/projects/:projectId(\\d+)/copilots/request')
383383
.post(require('./copilotRequest/create'));
384384

385385
// Project Estimation Items

0 commit comments

Comments
 (0)