From 3388d97c5268b47c01e1e214f46bd10453fb982e Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 10:44:50 +0530 Subject: [PATCH 1/7] added sprintCheckin to user model --- .../20240507131015_add_sprint_checkin_for_user/migration.sql | 2 ++ prisma/migrations/20240507131253_minor_edit/migration.sql | 2 ++ prisma/schema.prisma | 1 + 3 files changed, 5 insertions(+) create mode 100644 prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql create mode 100644 prisma/migrations/20240507131253_minor_edit/migration.sql diff --git a/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql b/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql new file mode 100644 index 00000000..497de993 --- /dev/null +++ b/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ADD COLUMN "sprintCheckin" INTEGER[]; diff --git a/prisma/migrations/20240507131253_minor_edit/migration.sql b/prisma/migrations/20240507131253_minor_edit/migration.sql new file mode 100644 index 00000000..40373627 --- /dev/null +++ b/prisma/migrations/20240507131253_minor_edit/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "User" ALTER COLUMN "sprintCheckin" SET DEFAULT ARRAY[]::INTEGER[]; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8a5c5197..4a3d4999 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -64,6 +64,7 @@ model User { resetToken ResetToken? emailVerificationToken EmailVerificationToken? roles UserRole[] + sprintCheckin Int[] @default([]) } model Role { From 03b617ae2bec955d13bd16f9c2a625d26ab62c77 Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 10:49:29 +0530 Subject: [PATCH 2/7] updated checkinform responses in seed --- .../seed/responses/checkinform-responses.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/prisma/seed/responses/checkinform-responses.ts b/prisma/seed/responses/checkinform-responses.ts index 1e478aba..9e33a382 100644 --- a/prisma/seed/responses/checkinform-responses.ts +++ b/prisma/seed/responses/checkinform-responses.ts @@ -19,6 +19,7 @@ export const populateCheckinFormResponse = async () => { }, }, }, + userId: true, }, }); @@ -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, + }, + }); }; From 93ac56ac7d6b76ac0a1e3f4e2d09b9c6918c14f8 Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 10:52:57 +0530 Subject: [PATCH 3/7] added sprintcheckin in user.select, users.response, user.entity --- src/global/selects/users.select.ts | 2 ++ src/users/entities/user.entity.ts | 3 +++ src/users/users.response.ts | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/global/selects/users.select.ts b/src/global/selects/users.select.ts index 2cb85d67..5b0a487a 100644 --- a/src/global/selects/users.select.ts +++ b/src/global/selects/users.select.ts @@ -55,6 +55,7 @@ export const fullUserDetailSelect = { hrPerSprint: true, }, }, + sprintCheckin: true, }; export const privateUserDetailSelect = { @@ -104,6 +105,7 @@ export const privateUserDetailSelect = { }, }, }, + sprintCheckin: true, }; export const publicUserDetailSelect = { diff --git a/src/users/entities/user.entity.ts b/src/users/entities/user.entity.ts index 5d0dbe1f..34a78d4c 100644 --- a/src/users/entities/user.entity.ts +++ b/src/users/entities/user.entity.ts @@ -58,4 +58,7 @@ export class UserEntity implements User { @ApiProperty() updatedAt: Date; + + @ApiProperty() + sprintCheckin: number[]; } diff --git a/src/users/users.response.ts b/src/users/users.response.ts index ee61f55f..b5c2604b 100644 --- a/src/users/users.response.ts +++ b/src/users/users.response.ts @@ -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; } From 9632d7646e384c2d1be6eb61fd4e9c974ad1fa20 Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 10:56:24 +0530 Subject: [PATCH 4/7] added sprintCheckin during checkin submit and userId to addCheckinFormResponse --- src/sprints/sprints.controller.ts | 4 ++++ src/sprints/sprints.service.ts | 31 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/sprints/sprints.controller.ts b/src/sprints/sprints.controller.ts index 471b5e60..09c14cef 100644 --- a/src/sprints/sprints.controller.ts +++ b/src/sprints/sprints.controller.ts @@ -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"; @@ -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") @@ -477,9 +479,11 @@ export class SprintsController { addCheckinFormResponse( @Body(new FormInputValidationPipe()) createCheckinFormResponse: CreateCheckinFormDto, + @Request() req: CustomRequest, ) { return this.sprintsService.addCheckinFormResponse( createCheckinFormResponse, + req.user.userId, ); } } diff --git a/src/sprints/sprints.service.ts b/src/sprints/sprints.service.ts index e63daabc..0d35b6e7 100644 --- a/src/sprints/sprints.service.ts +++ b/src/sprints/sprints.service.ts @@ -550,7 +550,10 @@ export class SprintsService { ); } - async addCheckinFormResponse(createCheckinForm: CreateCheckinFormDto) { + async addCheckinFormResponse( + createCheckinForm: CreateCheckinFormDto, + userId: string, + ) { const responsesArray = this.globalServices.responseDtoToArray(createCheckinForm); @@ -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: From 6ad33f6315e78e666d46aeecebdb0e6e0a9df5ca Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 11:25:15 +0530 Subject: [PATCH 5/7] updated changelog.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88a94ffe..7181adb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 20fdf5b7c82c243eecee89e5184d605a91cae1d2 Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Wed, 8 May 2024 12:27:45 +0530 Subject: [PATCH 6/7] updated user/me endpoint and removed sprintCheckin from user table --- .../migration.sql | 8 ++++ prisma/schema.prisma | 1 - .../seed/responses/checkinform-responses.ts | 44 ------------------- src/global/selects/users.select.ts | 2 - src/sprints/sprints.controller.ts | 4 -- src/sprints/sprints.service.ts | 30 +------------ src/users/users.response.ts | 6 +-- src/users/users.service.ts | 35 ++++++++++++++- 8 files changed, 46 insertions(+), 84 deletions(-) create mode 100644 prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql diff --git a/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql b/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql new file mode 100644 index 00000000..6efccb3a --- /dev/null +++ b/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - You are about to drop the column `sprintCheckin` on the `User` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "User" DROP COLUMN "sprintCheckin"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4a3d4999..8a5c5197 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -64,7 +64,6 @@ model User { resetToken ResetToken? emailVerificationToken EmailVerificationToken? roles UserRole[] - sprintCheckin Int[] @default([]) } model Role { diff --git a/prisma/seed/responses/checkinform-responses.ts b/prisma/seed/responses/checkinform-responses.ts index 9e33a382..90798be1 100644 --- a/prisma/seed/responses/checkinform-responses.ts +++ b/prisma/seed/responses/checkinform-responses.ts @@ -43,48 +43,4 @@ 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, - }, - }); }; diff --git a/src/global/selects/users.select.ts b/src/global/selects/users.select.ts index 5b0a487a..2cb85d67 100644 --- a/src/global/selects/users.select.ts +++ b/src/global/selects/users.select.ts @@ -55,7 +55,6 @@ export const fullUserDetailSelect = { hrPerSprint: true, }, }, - sprintCheckin: true, }; export const privateUserDetailSelect = { @@ -105,7 +104,6 @@ export const privateUserDetailSelect = { }, }, }, - sprintCheckin: true, }; export const publicUserDetailSelect = { diff --git a/src/sprints/sprints.controller.ts b/src/sprints/sprints.controller.ts index 09c14cef..471b5e60 100644 --- a/src/sprints/sprints.controller.ts +++ b/src/sprints/sprints.controller.ts @@ -9,7 +9,6 @@ import { Delete, ValidationPipe, HttpStatus, - Request, } from "@nestjs/common"; import { SprintsService } from "./sprints.service"; import { UpdateTeamMeetingDto } from "./dto/update-team-meeting.dto"; @@ -36,7 +35,6 @@ 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") @@ -479,11 +477,9 @@ export class SprintsController { addCheckinFormResponse( @Body(new FormInputValidationPipe()) createCheckinFormResponse: CreateCheckinFormDto, - @Request() req: CustomRequest, ) { return this.sprintsService.addCheckinFormResponse( createCheckinFormResponse, - req.user.userId, ); } } diff --git a/src/sprints/sprints.service.ts b/src/sprints/sprints.service.ts index 0d35b6e7..6e33b16d 100644 --- a/src/sprints/sprints.service.ts +++ b/src/sprints/sprints.service.ts @@ -550,10 +550,7 @@ export class SprintsService { ); } - async addCheckinFormResponse( - createCheckinForm: CreateCheckinFormDto, - userId: string, - ) { + async addCheckinFormResponse(createCheckinForm: CreateCheckinFormDto) { const responsesArray = this.globalServices.responseDtoToArray(createCheckinForm); @@ -577,31 +574,6 @@ 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: diff --git a/src/users/users.response.ts b/src/users/users.response.ts index b5c2604b..7c5e8e45 100644 --- a/src/users/users.response.ts +++ b/src/users/users.response.ts @@ -122,9 +122,6 @@ export class UserResponse { @ApiProperty({ isArray: true, example: ["admin", "voyager"] }) roles: string; - @ApiProperty({ isArray: true, example: [1, 2] }) - sprintCheckIn: number[]; - createdAt: Date; updatedAt: Date; } @@ -148,4 +145,7 @@ export class PublicUserResponse extends OmitType(UserResponse, [ export class FullUserResponse extends UserResponse { @ApiProperty({ isArray: true }) voyageTeamMembers: VoyageTeamWithoutMember; + + @ApiProperty({ isArray: true }) + sprintCheckIn: number[]; } diff --git a/src/users/users.service.ts b/src/users/users.service.ts index 25d7a710..dd8e7991 100644 --- a/src/users/users.service.ts +++ b/src/users/users.service.ts @@ -76,9 +76,42 @@ export class UsersService { }, select: privateUserDetailSelect, }); + // get voyageTeamMemberIds + const teamMemberId: number[] = ( + await this.prisma.user.findUnique({ + where: { + id: userId, + }, + select: { + voyageTeamMembers: { + select: { + id: true, + }, + }, + }, + }) + ).voyageTeamMembers.map((teamMemberId) => teamMemberId.id); + + // get sprint checkin Ids + const sprintCheckInIds = ( + await this.prisma.formResponseCheckin.findMany({ + where: { + voyageTeamMemberId: { + in: teamMemberId, + }, + }, + select: { + sprintId: true, + }, + }) + ).map((sprintCheckInId) => sprintCheckInId.sprintId); + + // update user object with sprintCheckInIds + + const updatedUser = { ...user, sprintCheckIn: sprintCheckInIds }; if (!user) throw new NotFoundException("User not found"); - return this.formatUser(user); + return this.formatUser(updatedUser); } // full user detail, for dev purpose From d3cf81f64a1b63cee749eff61febfe082eb4a7b2 Mon Sep 17 00:00:00 2001 From: Arman Kumar Jena Date: Sat, 11 May 2024 09:56:02 +0530 Subject: [PATCH 7/7] removed the migration folders --- .../migration.sql | 2 -- prisma/migrations/20240507131253_minor_edit/migration.sql | 2 -- .../migration.sql | 8 -------- 3 files changed, 12 deletions(-) delete mode 100644 prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql delete mode 100644 prisma/migrations/20240507131253_minor_edit/migration.sql delete mode 100644 prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql diff --git a/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql b/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql deleted file mode 100644 index 497de993..00000000 --- a/prisma/migrations/20240507131015_add_sprint_checkin_for_user/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "User" ADD COLUMN "sprintCheckin" INTEGER[]; diff --git a/prisma/migrations/20240507131253_minor_edit/migration.sql b/prisma/migrations/20240507131253_minor_edit/migration.sql deleted file mode 100644 index 40373627..00000000 --- a/prisma/migrations/20240507131253_minor_edit/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "User" ALTER COLUMN "sprintCheckin" SET DEFAULT ARRAY[]::INTEGER[]; diff --git a/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql b/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql deleted file mode 100644 index 6efccb3a..00000000 --- a/prisma/migrations/20240508063043_removed_sprint_checkin_column_from_user/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `sprintCheckin` on the `User` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "User" DROP COLUMN "sprintCheckin";