Skip to content

Commit

Permalink
fixing icm ticket (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
polatengin authored Nov 19, 2024
1 parent df9ea34 commit 1adf071
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/frontend/dal/itemDataService.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WorkItem } from 'azure-devops-extension-api/WorkItemTracking/WorkItemTracking';
import { IFeedbackBoardDocument, IFeedbackItemDocument, ITeamEffectivenessMeasurementVoteCollection } from '../interfaces/feedback';
import { appInsights, TelemetryExceptions } from '../utilities/telemetryClient';
import { getUserIdentity } from '../utilities/userIdentityHelper';
import { encrypt, getUserIdentity } from '../utilities/userIdentityHelper';
import { workItemService } from './azureDevOpsWorkItemService';
import { createDocument, deleteDocument, readDocument, readDocuments, updateDocument } from './dataService';
import { generateUUID } from '../utilities/random';
Expand Down Expand Up @@ -235,6 +235,8 @@ class ItemDataService {
public updateVote = async (boardId: string, teamId: string, userId: string, feedbackItemId: string, decrement: boolean = false): Promise<IFeedbackItemDocument> => {
const feedbackItem: IFeedbackItemDocument = await this.getFeedbackItem(boardId, feedbackItemId);

const encryptedUserId = encrypt(userId);

if (!feedbackItem) {
return undefined;
}
Expand All @@ -245,39 +247,39 @@ class ItemDataService {
}

if (decrement) {
if (!boardItem.boardVoteCollection?.[userId] ||
boardItem.boardVoteCollection[userId] <= 0) {
if (!boardItem.boardVoteCollection?.[encryptedUserId] ||
boardItem.boardVoteCollection[encryptedUserId] <= 0) {
return undefined;
}
if (feedbackItem.upvotes <= 0) {
return undefined;
} else if (feedbackItem.voteCollection[userId] === null || feedbackItem.voteCollection[userId] === 0) {
} else if (feedbackItem.voteCollection[encryptedUserId] === null || feedbackItem.voteCollection[encryptedUserId] === 0) {
return undefined;
}
else {
feedbackItem.voteCollection[userId]--;
feedbackItem.voteCollection[encryptedUserId]--;
feedbackItem.upvotes--;
boardItem.boardVoteCollection[userId]--;
boardItem.boardVoteCollection[encryptedUserId]--;
}
} else {
if (feedbackItem.voteCollection === undefined) {
feedbackItem.voteCollection = {};
}
if (feedbackItem.voteCollection[userId] === undefined || feedbackItem.voteCollection[userId] === null) {
feedbackItem.voteCollection[userId] = 0;
if (feedbackItem.voteCollection[encryptedUserId] === undefined || feedbackItem.voteCollection[encryptedUserId] === null) {
feedbackItem.voteCollection[encryptedUserId] = 0;
}
if (boardItem.boardVoteCollection === undefined) {
boardItem.boardVoteCollection = {};
}
if (boardItem.boardVoteCollection[userId] === undefined || boardItem.boardVoteCollection[userId] === null) {
boardItem.boardVoteCollection[userId] = 0;
if (boardItem.boardVoteCollection[encryptedUserId] === undefined || boardItem.boardVoteCollection[encryptedUserId] === null) {
boardItem.boardVoteCollection[encryptedUserId] = 0;
}
if (boardItem.boardVoteCollection[userId] >= boardItem.maxVotesPerUser) {
if (boardItem.boardVoteCollection[encryptedUserId] >= boardItem.maxVotesPerUser) {
return undefined;
}

boardItem.boardVoteCollection[userId]++;
feedbackItem.voteCollection[userId]++;
boardItem.boardVoteCollection[encryptedUserId]++;
feedbackItem.voteCollection[encryptedUserId]++;
feedbackItem.upvotes++;
}

Expand All @@ -289,7 +291,7 @@ class ItemDataService {

const updatedBoardItem = await this.updateBoardItem(teamId, boardItem);
if (!updatedBoardItem) {
updatedFeedbackItem.voteCollection[userId] = decrement ? updatedFeedbackItem.voteCollection[userId]++ : updatedFeedbackItem.voteCollection[userId]--;
updatedFeedbackItem.voteCollection[encryptedUserId] = decrement ? updatedFeedbackItem.voteCollection[encryptedUserId]++ : updatedFeedbackItem.voteCollection[encryptedUserId]--;
updatedFeedbackItem.upvotes = decrement ? updatedFeedbackItem.upvotes++ : updatedFeedbackItem.upvotes--;

const feedbackItemWithOriginalVotes = await this.updateFeedbackItem(boardId, updatedFeedbackItem);
Expand Down

0 comments on commit 1adf071

Please sign in to comment.