Skip to content
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

Feat: add voyage project submission status to /me endpoint #158

Merged
merged 7 commits into from
May 29, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Another example [here](https://co-pilot.dev/changelog)
- Add CASL ability for Access control ([#141](https://github.com/chingu-x/chingu-dashboard-be/pull/141))
- Add sprint checkin form submission status for a user ([#149](https://github.com/chingu-x/chingu-dashboard-be/pull/149))
- new command to run both e2e and unit test ([#148](https://github.com/chingu-x/chingu-dashboard-be/pull/148))
- Add voyage project submission status to `/me` endpoint ([#158](https://github.com/chingu-x/chingu-dashboard-be/pull/158))

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "VoyageTeam" ADD COLUMN "projectSubmitted" BOOLEAN DEFAULT false;
29 changes: 15 additions & 14 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,20 @@ model VoyageRole {
}

model VoyageTeam {
id Int @id @default(autoincrement())
voyage Voyage? @relation(fields: [voyageId], references: [id], onUpdate: Cascade, onDelete: SetNull)
voyageId Int?
name String @unique
status VoyageStatus? @relation(fields: [statusId], references: [id], onUpdate: Cascade, onDelete: SetNull)
statusId Int?
repoUrl String
repoUrlBE String?
deployedUrl String?
deployedUrlBE String?
tier Tier? @relation(fields: [tierId], references: [id], onUpdate: Cascade, onDelete: SetNull)
tierId Int?
endDate DateTime
id Int @id @default(autoincrement())
voyage Voyage? @relation(fields: [voyageId], references: [id], onUpdate: Cascade, onDelete: SetNull)
voyageId Int?
name String @unique
projectSubmitted Boolean? @default(false)
status VoyageStatus? @relation(fields: [statusId], references: [id], onUpdate: Cascade, onDelete: SetNull)
statusId Int?
repoUrl String
repoUrlBE String?
deployedUrl String?
deployedUrlBE String?
tier Tier? @relation(fields: [tierId], references: [id], onUpdate: Cascade, onDelete: SetNull)
tierId Int?
endDate DateTime

createdAt DateTime @default(now()) @db.Timestamptz()
updatedAt DateTime @updatedAt
Expand Down Expand Up @@ -292,7 +293,7 @@ model ProjectIdea {
title String
description String
vision String
isSelected Boolean @default(false)
isSelected Boolean @default(false)

createdAt DateTime @default(now()) @db.Timestamptz()
updatedAt DateTime @updatedAt
Expand Down
1 change: 1 addition & 0 deletions src/global/selects/users.select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const privateUserDetailSelect = {
voyageTeam: {
select: {
name: true,
projectSubmitted: false,
voyage: {
select: {
number: true,
Expand Down
3 changes: 3 additions & 0 deletions src/teams/entities/team.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export class VoyageTeamEntity implements VoyageTeam {
@ApiProperty()
name: string;

@ApiProperty()
projectSubmitted: boolean;

@ApiProperty()
statusId: number;

Expand Down
3 changes: 3 additions & 0 deletions src/users/users.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class VoyageTeam {
@ApiProperty({ example: "v47-tier2-team-4" })
name: string;

@ApiProperty({ example: false })
projectSubmitted: boolean;

@ApiProperty()
voyage: Voyage;
}
Expand Down
69 changes: 48 additions & 21 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,32 @@ export class UsersService {
where: {
id: userId,
},
select: privateUserDetailSelect,
});
// get voyageTeamMemberIds
const teamMemberId: number[] = (
await this.prisma.user.findUnique({
where: {
id: userId,
},
select: {
voyageTeamMembers: {
select: {
id: true,
},
select: {
...privateUserDetailSelect,
voyageTeamMembers: {
select: {
id: true,
voyageTeamId: true,
voyageTeam: true,
},
},
})
).voyageTeamMembers.map((teamMemberId) => teamMemberId.id);

},
});
if (!user) throw new NotFoundException("User not found");
// get voyageTeamMemberIds
const teamMemberIds: number[] = user.voyageTeamMembers.map(
(teamMemberId) => teamMemberId.id,
);
// get voyageTeamId
const teamIds: number[] = user.voyageTeamMembers.map(
(voyageTeamId) => voyageTeamId.voyageTeamId,
);
// get sprint checkin Ids
const sprintCheckInIds = (
await this.prisma.formResponseCheckin.findMany({
where: {
voyageTeamMemberId: {
in: teamMemberId,
in: teamMemberIds,
},
},
select: {
Expand All @@ -106,11 +108,36 @@ export class UsersService {
})
).map((sprintCheckInId) => sprintCheckInId.sprintId);

// update user object with sprintCheckInIds

const updatedUser = { ...user, sprintCheckIn: sprintCheckInIds };
const projectStatusTeamIds: number[] = (
await this.prisma.formResponseVoyageProject.findMany({
where: {
voyageTeamId: {
in: teamIds,
},
},
select: {
voyageTeamId: true,
},
})
).map((projectStatusTeamId) => projectStatusTeamId.voyageTeamId);
// update user object with sprintCheckInIds and projectStatus
const updatedUser = {
...user,
sprintCheckIn: sprintCheckInIds,
voyageTeamMembers: user.voyageTeamMembers.map((teamMember) => {
if (projectStatusTeamIds.includes(teamMember.voyageTeamId)) {
return {
...teamMember,
voyageTeam: {
...teamMember.voyageTeam,
projectSubmitted: true,
},
};
}
return teamMember;
}),
};

if (!user) throw new NotFoundException("User not found");
return this.formatUser(updatedUser);
}

Expand Down
Loading