Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:
- You are about to drop the column `isAIReviewer` on the `DefaultChallengeReviewer` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "DefaultChallengeReviewer" DROP COLUMN "isAIReviewer",
ADD COLUMN "aiWorkflowId" VARCHAR(14),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ performance]
Consider using CHAR(14) instead of VARCHAR(14) if the aiWorkflowId is always expected to be exactly 14 characters long. This can improve performance slightly and ensure data consistency.

ALTER COLUMN "scorecardId" DROP NOT NULL;
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ model DefaultChallengeReviewer {
trackId String
timelineTemplateId String?
// Reviewer configuration (mirrors ChallengeReviewer)
scorecardId String
scorecardId String?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkartunov @jmgasper fyi, I am making scorecardId field nullable as default AI reviewers can be created without a scorecard.

isMemberReview Boolean
memberReviewerCount Int?
phaseName String
Expand All @@ -659,7 +659,7 @@ model DefaultChallengeReviewer {
baseCoefficient Float?
incrementalCoefficient Float?
opportunityType ReviewOpportunityTypeEnum?
isAIReviewer Boolean?
aiWorkflowId String? @db.VarChar(14)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The @db.VarChar(14) annotation specifies a maximum length for the aiWorkflowId field. Ensure that this length is sufficient for all potential values, as truncation could lead to data loss or errors when storing longer IDs.

shouldOpenOpportunity Boolean @default(true)

// Relations
Expand Down Expand Up @@ -724,4 +724,4 @@ model TimelineTemplatePhase {

@@index([timelineTemplateId])
@@index([timelineTemplateId, phaseId])
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 style]
The lack of a newline at the end of the file can cause issues with some tools and version control systems. Consider adding a newline to improve compatibility.

9 changes: 1 addition & 8 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ async function getDefaultReviewers(currentUser, criteria) {
incrementalCoefficient: r.incrementalCoefficient,
type: r.opportunityType,
aiWorkflowId: r.aiWorkflowId,
isAIReviewer: r.isAIReviewer,
shouldOpenOpportunity: _.isBoolean(r.shouldOpenOpportunity) ? r.shouldOpenOpportunity : true,
}));
}
Expand All @@ -322,7 +321,6 @@ async function setDefaultReviewers(currentUser, data) {
Joi.object().keys({
scorecardId: Joi.string().required(),
isMemberReview: Joi.boolean().required(),
isAIReviewer: Joi.boolean().default(false),
shouldOpenOpportunity: Joi.boolean().default(true),
memberReviewerCount: Joi.when("isMemberReview", {
is: true,
Expand Down Expand Up @@ -403,7 +401,7 @@ async function setDefaultReviewers(currentUser, data) {
timelineTemplateId: _.isNil(value.timelineTemplateId) ? null : value.timelineTemplateId,
scorecardId: String(r.scorecardId),
isMemberReview: !!r.isMemberReview,
isAIReviewer: !!r.isAIReviewer,
aiWorkflowId:_.isNil(r.aiWorkflowId) ? null : r.aiWorkflowId,
memberReviewerCount: _.isNil(r.memberReviewerCount)
? null
: Number(r.memberReviewerCount),
Expand All @@ -414,7 +412,6 @@ async function setDefaultReviewers(currentUser, data) {
? null
: Number(r.incrementalCoefficient),
opportunityType: r.type ? _.toUpper(r.type) : null,
aiWorkflowId: r.aiWorkflowId,
shouldOpenOpportunity: _.isNil(r.shouldOpenOpportunity)
? true
: !!r.shouldOpenOpportunity,
Expand Down Expand Up @@ -1712,7 +1709,6 @@ async function createChallenge(currentUser, challenge, userToken) {
incrementalCoefficient: r.incrementalCoefficient,
type: r.opportunityType,
aiWorkflowId: r.aiWorkflowId,
isAIReviewer: r.isAIReviewer ?? false,
shouldOpenOpportunity: _.isBoolean(r.shouldOpenOpportunity)
? r.shouldOpenOpportunity
: true,
Expand Down Expand Up @@ -1880,7 +1876,6 @@ createChallenge.schema = {
Joi.object().keys({
scorecardId: Joi.string().required(),
isMemberReview: Joi.boolean().required(),
isAIReviewer: Joi.boolean().default(false),
shouldOpenOpportunity: Joi.boolean().default(true),
memberReviewerCount: Joi.when("isMemberReview", {
is: true,
Expand Down Expand Up @@ -3075,7 +3070,6 @@ updateChallenge.schema = {
Joi.object().keys({
scorecardId: Joi.string().required(),
isMemberReview: Joi.boolean().required(),
isAIReviewer: Joi.boolean().default(false),
shouldOpenOpportunity: Joi.boolean().default(true),
memberReviewerCount: Joi.when("isMemberReview", {
is: true,
Expand Down Expand Up @@ -3555,7 +3549,6 @@ function sanitizeChallenge(challenge) {
_.pick(rv, [
"scorecardId",
"isMemberReview",
"isAIReviewer",
"memberReviewerCount",
"phaseId",
"fixedAmount",
Expand Down
22 changes: 15 additions & 7 deletions src/services/DefaultChallengeReviewerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ function normalizePayload(data = {}, isPartial = false) {
} else if (!isPartial && _.isNil(data.opportunityType)) {
normalized.opportunityType = null;
}
if (shouldAssign(data.isAIReviewer)) {
normalized.isAIReviewer = data.isAIReviewer;
if (shouldAssign(data.aiWorkflowId)) {
normalized.aiWorkflowId = data.aiWorkflowId;
}
if (shouldAssign(data.shouldOpenOpportunity)) {
normalized.shouldOpenOpportunity = data.shouldOpenOpportunity;
Expand Down Expand Up @@ -325,7 +325,7 @@ createDefaultChallengeReviewer.schema = {
typeId: Joi.id().required(),
trackId: Joi.id().required(),
timelineTemplateId: Joi.optionalId().allow(null),
scorecardId: Joi.string().required(),
scorecardId: Joi.string().optional(),
isMemberReview: Joi.boolean().required(),
memberReviewerCount: Joi.when("isMemberReview", {
is: true,
Expand All @@ -338,7 +338,11 @@ createDefaultChallengeReviewer.schema = {
baseCoefficient: Joi.number().min(0).max(1).allow(null),
incrementalCoefficient: Joi.number().min(0).max(1).allow(null),
opportunityType: Joi.string().valid(..._.values(ReviewOpportunityTypeEnum)).insensitive(),
isAIReviewer: Joi.boolean().required(),
aiWorkflowId: Joi.when("isMemberReview", {
is: false,
then: Joi.string().required(),
otherwise: Joi.valid(null),
}),
shouldOpenOpportunity: Joi.boolean().required(),
})
.required(),
Expand Down Expand Up @@ -404,7 +408,7 @@ fullyUpdateDefaultChallengeReviewer.schema = {
typeId: Joi.id().required(),
trackId: Joi.id().required(),
timelineTemplateId: Joi.optionalId().allow(null),
scorecardId: Joi.string().required(),
scorecardId: Joi.string().optional(),
isMemberReview: Joi.boolean().required(),
memberReviewerCount: Joi.when("isMemberReview", {
is: true,
Expand All @@ -417,7 +421,11 @@ fullyUpdateDefaultChallengeReviewer.schema = {
baseCoefficient: Joi.number().min(0).max(1).allow(null),
incrementalCoefficient: Joi.number().min(0).max(1).allow(null),
opportunityType: Joi.string().valid(..._.values(ReviewOpportunityTypeEnum)).insensitive(),
isAIReviewer: Joi.boolean().required(),
aiWorkflowId: Joi.when("isMemberReview", {
is: false,
then: Joi.string().required(),
otherwise: Joi.valid(null),
}),
shouldOpenOpportunity: Joi.boolean().required(),
})
.required(),
Expand Down Expand Up @@ -516,7 +524,7 @@ partiallyUpdateDefaultChallengeReviewer.schema = {
.valid(..._.values(ReviewOpportunityTypeEnum))
.insensitive()
.allow(null),
isAIReviewer: Joi.boolean(),
aiWorkflowId: Joi.string(),
shouldOpenOpportunity: Joi.boolean(),
})
.required(),
Expand Down