Skip to content

Commit

Permalink
fix: deleted not required userId and whoCreated params from the Folio…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 9aa4139 commit 471e35e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
4 changes: 0 additions & 4 deletions backend/src/app/dto/folio.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export class FolioMinDTO {
@Field()
@IsNumber()
id: number;

@Field()
@IsString()
userId: string;
}

@ObjectType()
Expand Down
10 changes: 0 additions & 10 deletions backend/src/app/dto/folioContent.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ export class FolioContentDTO {
@Field()
@IsString()
folioId: string;

@Field()
@IsOptional()
@IsString()
userId: string;

@Field()
@IsOptional()
@IsString()
whoCreated: string;
}

@ObjectType()
Expand Down
5 changes: 1 addition & 4 deletions backend/src/app/services/folio/folio.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
6 changes: 6 additions & 0 deletions backend/src/app/services/folio/folio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/app/common/httpStatusCode.ts
Original file line number Diff line number Diff line change
@@ -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,
}
7 changes: 3 additions & 4 deletions frontend/src/app/features/folios/FolioContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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: '',
};
});

Expand Down
16 changes: 1 addition & 15 deletions frontend/src/app/features/folios/dto/Folio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
10 changes: 9 additions & 1 deletion frontend/src/app/features/folios/redux/FolioSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
updateFolioItemQL,
} from '../graphql/Folio';
import { print } from 'graphql';
import { HttpStatusCode } from '../../../common/httpStatusCode';

const initialState: FolioState = {
fetchRequestStatus: RequestStatus.idle,
Expand Down Expand Up @@ -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;
})
Expand Down

0 comments on commit 471e35e

Please sign in to comment.