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

fix: deleted not required userId and whoCreated params from the Folio API #214

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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
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 = '';
}
7 changes: 6 additions & 1 deletion frontend/src/app/features/folios/redux/FolioSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ 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 === 400 ||
midhun-aot marked this conversation as resolved.
Show resolved Hide resolved
action?.payload?.data?.addFolioItem?.httpStatusCode === 404
)
state.addRequestStatus = RequestStatus.failed;
else if (action?.payload?.errors?.length > 0)
state.addRequestStatus = RequestStatus.failed;
else state.addRequestStatus = RequestStatus.success;
})
Expand Down
Loading