Skip to content

Commit 406ff27

Browse files
authored
Merge pull request #726 from Shubham4026/user-service
Kakfa Fix for Center and User Data
2 parents 2e0196e + 7f535c2 commit 406ff27

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/user/user.service.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,7 +3506,7 @@ export class UserService {
35063506
// Enhanced query to fetch batch, parent cohort, and academic year details
35073507
const cohortQuery = `
35083508
WITH BatchData AS (
3509-
SELECT
3509+
SELECT
35103510
cm."cohortId" as "batchId",
35113511
cm."createdAt" as "joinedAt",
35123512
cm."status" as "cohortMemberStatus",
@@ -3518,17 +3518,22 @@ export class UserService {
35183518
batch."parentId" as "cohortId"
35193519
FROM public."CohortMembers" cm
35203520
JOIN public."Cohort" batch ON cm."cohortId" = batch."cohortId"
3521-
WHERE cm."userId" = $1 AND batch."type" = 'BATCH'
3521+
WHERE cm."userId" = $1 AND batch."type" IN ('BATCH', 'COHORT')
35223522
)
3523-
SELECT
3523+
SELECT
35243524
bd.*,
3525-
cohort."name" as "cohortName",
3526-
cohort."type" as "cohortType",
3525+
COALESCE(
3526+
parent_cohort."name",
3527+
CASE WHEN bd."batchType" = 'COHORT' THEN bd."batchName" END
3528+
) as "cohortName",
3529+
COALESCE(parent_cohort."type", CASE WHEN bd."batchType" = 'COHORT' THEN 'COHORT' END) as "cohortType",
35273530
cay."academicYearId",
35283531
ay."session" as "academicYearSession"
35293532
FROM BatchData bd
3530-
LEFT JOIN public."Cohort" cohort ON bd."cohortId":: UUID = cohort."cohortId" AND cohort."type" = 'COHORT'
3531-
LEFT JOIN public."CohortAcademicYear" cay ON bd."cohortId":: UUID = cay."cohortId"
3533+
LEFT JOIN public."Cohort" parent_cohort ON bd."cohortId"::uuid = parent_cohort."cohortId" AND parent_cohort."type" = 'COHORT'
3534+
LEFT JOIN public."CohortAcademicYear" cay ON (
3535+
CASE WHEN bd."batchType" = 'BATCH' THEN bd."cohortId"::uuid ELSE bd."batchId"::uuid END
3536+
) = cay."cohortId"
35323537
LEFT JOIN public."AcademicYears" ay ON cay."academicYearId" = ay."id"
35333538
`;
35343539

0 commit comments

Comments
 (0)