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

Feature: sprint checkin form submission status for user #149

Merged
merged 8 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Another example [here](https://co-pilot.dev/changelog)
- Add voyage project submission controller, service, e2e tests, responses seed ([#133](https://github.com/chingu-x/chingu-dashboard-be/pull/133))
- Add new endpoints to select/reset team project ideation ([#136](https://github.com/chingu-x/chingu-dashboard-be/pull/136))
- 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))

### Changed

Expand Down
Ajen07 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "sprintCheckin" INTEGER[];
2 changes: 2 additions & 0 deletions prisma/migrations/20240507131253_minor_edit/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ALTER COLUMN "sprintCheckin" SET DEFAULT ARRAY[]::INTEGER[];
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ model User {
resetToken ResetToken?
emailVerificationToken EmailVerificationToken?
roles UserRole[]
sprintCheckin Int[] @default([])
}

model Role {
Expand Down
45 changes: 45 additions & 0 deletions prisma/seed/responses/checkinform-responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const populateCheckinFormResponse = async () => {
},
},
},
userId: true,
},
});

Expand All @@ -42,4 +43,48 @@ export const populateCheckinFormResponse = async () => {
responseGroupId: responseGroup.id,
},
});

// find voyageTeamMemberIds from user table
const teamMemberIds: number[] = (
await prisma.user.findUnique({
where: {
id: teamMember.userId,
},
select: {
voyageTeamMembers: {
select: {
id: true,
},
},
},
})
).voyageTeamMembers.map((teamMember) => teamMember.id);

// get all the checkins for the user
const sprintCheckinIds: number[] = (
await Promise.all(
teamMemberIds.map((teamMemberId: number) => {
return prisma.formResponseCheckin.findMany({
where: {
voyageTeamMemberId: teamMemberId,
},
select: {
id: true,
},
});
}),
)
)
.flat()
.map((checkin) => checkin.id);

// add the sprintCheckin to the user
await prisma.user.update({
where: {
id: teamMember.userId,
},
data: {
sprintCheckin: sprintCheckinIds,
},
});
};
2 changes: 2 additions & 0 deletions src/global/selects/users.select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const fullUserDetailSelect = {
hrPerSprint: true,
},
},
sprintCheckin: true,
};

export const privateUserDetailSelect = {
Expand Down Expand Up @@ -104,6 +105,7 @@ export const privateUserDetailSelect = {
},
},
},
sprintCheckin: true,
};

export const publicUserDetailSelect = {
Expand Down
4 changes: 4 additions & 0 deletions src/sprints/sprints.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Delete,
ValidationPipe,
HttpStatus,
Request,
} from "@nestjs/common";
import { SprintsService } from "./sprints.service";
import { UpdateTeamMeetingDto } from "./dto/update-team-meeting.dto";
Expand All @@ -35,6 +36,7 @@ import {
} from "../global/responses/errors";
import { FormResponse, ResponseResponse } from "../forms/forms.response";
import { CreateCheckinFormDto } from "./dto/create-checkin-form.dto";
import { CustomRequest } from "../../src/global/types/CustomRequest";

@Controller()
@ApiTags("Voyage - Sprints")
Expand Down Expand Up @@ -477,9 +479,11 @@ export class SprintsController {
addCheckinFormResponse(
@Body(new FormInputValidationPipe())
createCheckinFormResponse: CreateCheckinFormDto,
@Request() req: CustomRequest,
) {
return this.sprintsService.addCheckinFormResponse(
createCheckinFormResponse,
req.user.userId,
);
}
}
31 changes: 30 additions & 1 deletion src/sprints/sprints.service.ts
Ajen07 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,10 @@ export class SprintsService {
);
}

async addCheckinFormResponse(createCheckinForm: CreateCheckinFormDto) {
async addCheckinFormResponse(
createCheckinForm: CreateCheckinFormDto,
userId: string,
) {
const responsesArray =
this.globalServices.responseDtoToArray(createCheckinForm);

Expand All @@ -573,6 +576,32 @@ export class SprintsService {
},
},
});

// find the user and extract its current sprintCheckin Ids
const checkinFormIds = await tx.user.findUnique({
where: {
id: userId,
},
select: {
sprintCheckin: true,
},
});

//updated array of sprintCheckin Ids
const updatedCheckinFormIds: number[] = [
...checkinFormIds.sprintCheckin,
createCheckinForm.sprintId,
];

// update the user with the updated sprintCheckin Ids
await tx.user.update({
where: {
id: userId,
},
data: {
sprintCheckin: updatedCheckinFormIds,
},
});
return tx.formResponseCheckin.create({
data: {
voyageTeamMemberId:
Expand Down
3 changes: 3 additions & 0 deletions src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ export class UserEntity implements User {

@ApiProperty()
updatedAt: Date;

@ApiProperty()
sprintCheckin: number[];
}
3 changes: 3 additions & 0 deletions src/users/users.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export class UserResponse {
@ApiProperty({ isArray: true, example: ["admin", "voyager"] })
roles: string;

@ApiProperty({ isArray: true, example: [1, 2] })
sprintCheckIn: number[];

createdAt: Date;
updatedAt: Date;
}
Expand Down
Loading