Skip to content

Commit eb903fd

Browse files
authored
Merge pull request #172 from topcoder-platform/pm-2177_user_detais
fix(PM-2177): Send comment creator details and changes comments structure
2 parents 89e5652 + 461787c commit eb903fd

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ workflows:
7878
- pm-1955_2
7979
- re-try-failed-jobs
8080
- pm-2539
81+
- pm-2177_user_detais
8182

8283

8384
- 'build-prod':

src/api/ai-workflow/ai-workflow.service.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { UserRole } from 'src/shared/enums/userRole.enum';
2727
import { ChallengeStatus } from 'src/shared/enums/challengeStatus.enum';
2828
import { LoggerService } from 'src/shared/modules/global/logger.service';
2929
import { GiteaService } from 'src/shared/modules/global/gitea.service';
30+
import { MemberPrismaService } from 'src/shared/modules/global/member-prisma.service';
3031
import { VoteType } from '@prisma/client';
3132

3233
@Injectable()
@@ -35,6 +36,7 @@ export class AiWorkflowService {
3536

3637
constructor(
3738
private readonly prisma: PrismaService,
39+
private readonly memberPrisma: MemberPrismaService,
3840
private readonly challengeApiService: ChallengeApiService,
3941
private readonly resourceApiService: ResourceApiService,
4042
private readonly giteaService: GiteaService,
@@ -824,7 +826,73 @@ export class AiWorkflowService {
824826
},
825827
});
826828

827-
return items;
829+
const createdByList = items
830+
.map((item) => item.comments)
831+
.flat()
832+
.map((item) => item.createdBy as string);
833+
834+
const members = await this.memberPrisma.member.findMany({
835+
where: { userId: { in: createdByList.map((id) => BigInt(id)) } },
836+
select: {
837+
userId: true,
838+
handle: true,
839+
maxRating: { select: { ratingColor: true } },
840+
},
841+
});
842+
843+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
844+
const normalized = members.map((m: any) => ({
845+
...m,
846+
userId: m.userId.toString(),
847+
ratingColor: m.maxRating?.ratingColor,
848+
}));
849+
850+
const membersMap = normalized.reduce(
851+
(acc, item) => {
852+
if (item.userId) {
853+
acc[item.userId] = item;
854+
}
855+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
856+
return acc;
857+
},
858+
{} as Record<string, (typeof members)[0]>,
859+
);
860+
861+
// Reconstruct comments with child comments nested in parent's "comments" property
862+
const commentsById: Record<string, any> = {};
863+
864+
for (const item of items) {
865+
for (const comment of item.comments) {
866+
commentsById[comment.id] = {
867+
...comment,
868+
createdUser: membersMap[comment.createdBy as string],
869+
comments: [],
870+
};
871+
}
872+
}
873+
874+
for (const item of items) {
875+
for (const comment of item.comments) {
876+
if (comment.parentId) {
877+
const parent = commentsById[comment.parentId];
878+
if (parent) {
879+
parent.comments.push(commentsById[comment.id]);
880+
}
881+
}
882+
}
883+
}
884+
885+
for (const item of items) {
886+
item.comments = item.comments
887+
.filter((comment) => !comment.parentId)
888+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
889+
.map((comment) => commentsById[comment.id]);
890+
}
891+
892+
return items.map((item) => ({
893+
...item,
894+
comments: item.comments,
895+
}));
828896
}
829897

830898
async updateRunItem(

0 commit comments

Comments
 (0)