-
Notifications
You must be signed in to change notification settings - Fork 9
fix(PM-2177): Send comment creator details and changes comments structure #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
82450fe
f29a8a5
530f4c8
cbddab7
4981aab
d7633a3
ae957a7
0ea5871
8e8dee4
2a3423d
461787c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ workflows: | |
| - pm-1955_2 | ||
| - re-try-failed-jobs | ||
| - pm-2539 | ||
| - pm-2177_user_detais | ||
|
|
||
|
|
||
| - 'build-prod': | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import { UserRole } from 'src/shared/enums/userRole.enum'; | |
| import { ChallengeStatus } from 'src/shared/enums/challengeStatus.enum'; | ||
| import { LoggerService } from 'src/shared/modules/global/logger.service'; | ||
| import { GiteaService } from 'src/shared/modules/global/gitea.service'; | ||
| import { MemberPrismaService } from 'src/shared/modules/global/member-prisma.service'; | ||
| import { VoteType } from '@prisma/client'; | ||
|
|
||
| @Injectable() | ||
|
|
@@ -35,6 +36,7 @@ export class AiWorkflowService { | |
|
|
||
| constructor( | ||
| private readonly prisma: PrismaService, | ||
| private readonly memberPrisma: MemberPrismaService, | ||
| private readonly challengeApiService: ChallengeApiService, | ||
| private readonly resourceApiService: ResourceApiService, | ||
| private readonly giteaService: GiteaService, | ||
|
|
@@ -824,7 +826,73 @@ export class AiWorkflowService { | |
| }, | ||
| }); | ||
|
|
||
| return items; | ||
| const createdByList = items | ||
| .map((item) => item.comments) | ||
| .flat() | ||
| .map((item) => item.createdBy as string); | ||
|
|
||
| const members = await this.memberPrisma.member.findMany({ | ||
| where: { userId: { in: createdByList.map((id) => BigInt(id)) } }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| select: { | ||
| userId: true, | ||
| handle: true, | ||
| maxRating: { select: { ratingColor: true } }, | ||
| }, | ||
| }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| const normalized = members.map((m: any) => ({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| ...m, | ||
| userId: m.userId.toString(), | ||
| ratingColor: m.maxRating?.ratingColor, | ||
| })); | ||
|
|
||
| const membersMap = normalized.reduce( | ||
| (acc, item) => { | ||
| if (item.userId) { | ||
| acc[item.userId] = item; | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return acc; | ||
| }, | ||
| {} as Record<string, (typeof members)[0]>, | ||
| ); | ||
|
|
||
| // Reconstruct comments with child comments nested in parent's "comments" property | ||
| const commentsById: Record<string, any> = {}; | ||
|
|
||
| for (const item of items) { | ||
| for (const comment of item.comments) { | ||
| commentsById[comment.id] = { | ||
| ...comment, | ||
| createdUser: membersMap[comment.createdBy as string], | ||
| comments: [], | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| for (const item of items) { | ||
| for (const comment of item.comments) { | ||
| if (comment.parentId) { | ||
| const parent = commentsById[comment.parentId]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| if (parent) { | ||
| parent.comments.push(commentsById[comment.id]); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (const item of items) { | ||
| item.comments = item.comments | ||
| .filter((comment) => !comment.parentId) | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| .map((comment) => commentsById[comment.id]); | ||
| } | ||
|
|
||
| return items.map((item) => ({ | ||
| ...item, | ||
| comments: item.comments, | ||
| })); | ||
| } | ||
|
|
||
| async updateRunItem( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
correctness]There is a typo in the branch name
pm-2177_user_detais. It should likely bepm-2177_user_details. This could lead to confusion or errors when triggering workflows based on branch names.