Skip to content

Commit

Permalink
feat(users): add support for projectSubmitted field in VoyageTeam ent…
Browse files Browse the repository at this point in the history
…ity and response

fix(users): update user object with sprintCheckInIds and projectStatus
The migration.sql file adds a new column "projectSubmitted" to the VoyageTeam table in the database. This column is set to a default value of false. The schema.prisma file is updated to include the new "projectSubmitted" field in the VoyageTeam model. The users.select.ts file is modified to include the "projectSubmitted" field in the select query for private user details. The team.entity.ts file is updated to include the "projectSubmitted" field in the VoyageTeamEntity class. The users.response.ts file is modified to include the "projectSubmitted" field in the VoyageTeam class. The users.service.ts file is updated to fetch the "projectSubmitted" field from the database and update the user object with the sprintCheckInIds and projectStatus.

These changes are done to support the functionality of tracking whether a project has been submitted by a VoyageTeam. The "projectSubmitted" field allows for easy retrieval of this information and the updated user object provides the necessary data for displaying the project status to the user.
  • Loading branch information
timDeHof committed May 24, 2024
1 parent 010170d commit 8f68cb6
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 35 deletions.
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

0 comments on commit 8f68cb6

Please sign in to comment.