From 471e35e7e0b97dbfee96ca2ea95d13939c2c9242 Mon Sep 17 00:00:00 2001 From: midhun-aot <105463561+midhun-aot@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:43:30 -0800 Subject: [PATCH] fix: deleted not required userId and whoCreated params from the Folio API (#214) * delete not required userId and whoCreated param from the API * fixed failing unit test case * Adding a HttpStatusCode Enum --------- Co-authored-by: nikhila-aot <38471389+nikhila-aot@users.noreply.github.com> Co-authored-by: Om Mishra <32200996+mishraomp@users.noreply.github.com> --- backend/src/app/dto/folio.dto.ts | 4 ---- backend/src/app/dto/folioContent.dto.ts | 10 ---------- .../app/services/folio/folio.service.spec.ts | 5 +---- backend/src/app/services/folio/folio.service.ts | 6 ++++++ frontend/src/app/common/httpStatusCode.ts | 17 +++++++++++++++++ .../src/app/features/folios/FolioContent.tsx | 7 +++---- frontend/src/app/features/folios/dto/Folio.ts | 16 +--------------- .../src/app/features/folios/redux/FolioSlice.ts | 10 +++++++++- 8 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 frontend/src/app/common/httpStatusCode.ts diff --git a/backend/src/app/dto/folio.dto.ts b/backend/src/app/dto/folio.dto.ts index 1f5f244b..d29ee90c 100644 --- a/backend/src/app/dto/folio.dto.ts +++ b/backend/src/app/dto/folio.dto.ts @@ -43,10 +43,6 @@ export class FolioMinDTO { @Field() @IsNumber() id: number; - - @Field() - @IsString() - userId: string; } @ObjectType() diff --git a/backend/src/app/dto/folioContent.dto.ts b/backend/src/app/dto/folioContent.dto.ts index 45209e64..92b25471 100644 --- a/backend/src/app/dto/folioContent.dto.ts +++ b/backend/src/app/dto/folioContent.dto.ts @@ -17,16 +17,6 @@ export class FolioContentDTO { @Field() @IsString() folioId: string; - - @Field() - @IsOptional() - @IsString() - userId: string; - - @Field() - @IsOptional() - @IsString() - whoCreated: string; } @ObjectType() diff --git a/backend/src/app/services/folio/folio.service.spec.ts b/backend/src/app/services/folio/folio.service.spec.ts index 8e133c11..2b9dd003 100644 --- a/backend/src/app/services/folio/folio.service.spec.ts +++ b/backend/src/app/services/folio/folio.service.spec.ts @@ -124,10 +124,7 @@ describe('FolioSerivce', () => { jest.spyOn(folioContentRepository, 'find').mockResolvedValue(folioContent); - const result = await folioSerivce.getSitesForFolio( - { id: 1, userId: '' }, - user, - ); + const result = await folioSerivce.getSitesForFolio({ id: 1 }, user); expect(result.length).toBeGreaterThan(0); }); diff --git a/backend/src/app/services/folio/folio.service.ts b/backend/src/app/services/folio/folio.service.ts index 81fe5876..fefce11a 100644 --- a/backend/src/app/services/folio/folio.service.ts +++ b/backend/src/app/services/folio/folio.service.ts @@ -83,6 +83,10 @@ export class FolioService { try { const { folioId } = inputDTO; + if (!userInfo) { + throw new Error('User Not Found'); + } + const userId = userInfo.sub; const existingRecord = await this.folioRepository.findOne({ @@ -93,6 +97,8 @@ export class FolioService { const folio = plainToInstance(Folio, inputDTO); folio.whenCreated = new Date(); folio.whenUpdated = new Date(); + folio.whoCreated = userInfo.givenName; + folio.userId = userInfo.sub; const result = await this.folioRepository.save(folio); if (result) { diff --git a/frontend/src/app/common/httpStatusCode.ts b/frontend/src/app/common/httpStatusCode.ts new file mode 100644 index 00000000..67e4d1b2 --- /dev/null +++ b/frontend/src/app/common/httpStatusCode.ts @@ -0,0 +1,17 @@ +export enum HttpStatusCode { + OK = 200, + CREATED = 201, + ACCEPTED = 202, + NO_CONTENT = 204, + BAD_REQUEST = 400, + UNAUTHORIZED = 401, + FORBIDDEN = 403, + NOT_FOUND = 404, + METHOD_NOT_ALLOWED = 405, + CONFLICT = 409, + INTERNAL_SERVER_ERROR = 500, + NOT_IMPLEMENTED = 501, + BAD_GATEWAY = 502, + SERVICE_UNAVAILABLE = 503, + GATEWAY_TIMEOUT = 504, +} diff --git a/frontend/src/app/features/folios/FolioContent.tsx b/frontend/src/app/features/folios/FolioContent.tsx index 624c8aec..b7332630 100644 --- a/frontend/src/app/features/folios/FolioContent.tsx +++ b/frontend/src/app/features/folios/FolioContent.tsx @@ -61,13 +61,13 @@ const FolioContents = () => { const [showDeleteConfirmModal, SetShowDeleteConfirmModal] = useState(false); useEffect(() => { - const dto = { id: parseInt(id ?? '0'), userId: user?.profile.sub ?? '' }; + const dto = { id: parseInt(id ?? '0') }; dispatch(getSiteForFolio(dto)).unwrap(); }, []); useEffect(() => { - const dto = { id: parseInt(id ?? '0'), userId: user?.profile.sub ?? '' }; + const dto = { id: parseInt(id ?? '0') }; dispatch(getSiteForFolio(dto)).unwrap(); showNotification( @@ -134,10 +134,9 @@ const FolioContents = () => { const sitesinFolio = selectedRows.map((folio) => { return { id: parseInt(id ?? ''), - userId: loggedInUser.profile.sub, + siteId: folio.siteId, folioId: id, - whoCreated: '', }; }); diff --git a/frontend/src/app/features/folios/dto/Folio.ts b/frontend/src/app/features/folios/dto/Folio.ts index a57d0fe2..9ebaa1f3 100644 --- a/frontend/src/app/features/folios/dto/Folio.ts +++ b/frontend/src/app/features/folios/dto/Folio.ts @@ -41,31 +41,17 @@ export class FolioContentDTO { folioId: string | undefined = ''; - userId: string = ''; - - whoCreated: string = ''; - site?: any = null; folio?: any = null; - constructor( - siteId: string, - userId: string, - folioId: string, - id: number, - whoCreated: string, - ) { - this.userId = userId; + constructor(siteId: string, folioId: string, id: number) { this.folioId = folioId; this.siteId = siteId; - this.whoCreated = whoCreated; this.id = id; } } export class FolioMinDTO { id: number = 0; - - userId: string = ''; } diff --git a/frontend/src/app/features/folios/redux/FolioSlice.ts b/frontend/src/app/features/folios/redux/FolioSlice.ts index 670b0130..fe477449 100644 --- a/frontend/src/app/features/folios/redux/FolioSlice.ts +++ b/frontend/src/app/features/folios/redux/FolioSlice.ts @@ -13,6 +13,7 @@ import { updateFolioItemQL, } from '../graphql/Folio'; import { print } from 'graphql'; +import { HttpStatusCode } from '../../../common/httpStatusCode'; const initialState: FolioState = { fetchRequestStatus: RequestStatus.idle, @@ -183,7 +184,14 @@ const folioSlice = createSlice({ state.fetchRequestStatus = RequestStatus.failed; }) .addCase(addFolioItem.fulfilled, (state, action) => { - if (action?.payload?.data?.addFolioItem?.httpStatusCode === 400) + if ( + action?.payload?.data?.addFolioItem?.httpStatusCode === + HttpStatusCode.NOT_FOUND || + action?.payload?.data?.addFolioItem?.httpStatusCode === + HttpStatusCode.BAD_REQUEST + ) + state.addRequestStatus = RequestStatus.failed; + else if (action?.payload?.errors?.length > 0) state.addRequestStatus = RequestStatus.failed; else state.addRequestStatus = RequestStatus.success; })