From 9d9dc56d84298409c86cacf73a5a03b5170b3133 Mon Sep 17 00:00:00 2001 From: Ha Minh Chien Date: Mon, 26 Feb 2024 17:28:52 +0700 Subject: [PATCH] update --- .../src/app/auth/use-case/populate-context.ts | 11 +- .../src/domain/entity/test/example.ts | 2 +- .../src/infra/mongo/test/schema.ts | 4 +- apps/hcdc-access-service/src/main.ts | 5 +- .../http/v1/test/dto/create.request-dto.ts | 3 +- apps/hcdc-web-app/package.json | 1 + .../src/components/layout/AppBar/index.tsx | 5 +- .../layout/AppDrawer/drawer-items.tsx | 54 ++++++-- .../src/components/layout/AppDrawer/index.tsx | 24 +--- apps/hcdc-web-app/src/features/auth/index.ts | 2 +- .../auth/pages/LoginPage/login-form.tsx | 8 +- .../src/features/auth/state/actions.ts | 6 + .../src/features/auth/state/index.ts | 2 +- .../src/features/auth/state/slice.ts | 10 +- .../components/BioProductTable/index.tsx | 2 +- .../components/DiagnosisTable}/columns.tsx | 6 +- .../components/DiagnosisTable/index.tsx | 70 +++++++++++ .../features/diagnosis/components/index.ts | 1 + .../src/features/diagnosis/index.ts | 1 + .../pages/ManageDiagnosisPage/index.tsx | 9 ++ .../doctor/components/DoctorTable/columns.tsx | 2 +- .../doctor/components/DoctorTable/index.tsx | 20 +-- .../hcdc-web-app/src/features/doctor/index.ts | 1 + .../homepage/pages/Homepage/index.tsx | 18 +-- .../components/IndicationTable/index.tsx | 72 ----------- .../pages/ManageIndicationPage/index.tsx | 9 -- .../components/PatientTypeTable/columns.tsx | 2 +- .../components/PatientTypeTable/index.tsx | 26 ++-- .../features/patient-type/components/index.ts | 1 + .../src/features/patient-type/index.ts | 1 + .../pages/ManagePatientTypePage/index.tsx | 2 +- .../components/PrintFormTable/columns.tsx | 4 +- .../components/PrintFormTable/index.tsx | 17 +-- .../features/print-form/components/index.ts | 1 + .../src/features/print-form/index.ts | 1 + .../pages/ManagePrintFormPage/index.tsx | 2 +- .../components/SampleOriginTable/columns.tsx | 22 ---- .../components/SampleOriginTable/index.tsx | 72 ----------- .../pages/ManageSampleOriginPage/index.tsx | 9 -- .../components/SampleTypeTable/columns.tsx | 2 +- .../components/SampleTypeTable/index.tsx | 26 ++-- .../features/sample-type/components/index.ts | 1 + .../src/features/sample-type/index.ts | 1 + .../pages/ManageSampleTypePage/index.tsx | 2 +- .../components/TestCategoryTable/columns.tsx | 2 +- .../components/TestCategoryTable/index.tsx | 28 ++--- .../test-category/components/index.ts | 1 + .../src/features/test-category/index.ts | 1 + .../pages/ManageTestCategoryPage/index.tsx | 2 +- .../components/TestComboTable/columns.tsx | 4 +- .../components/TestComboTable/index.tsx | 36 +++--- .../features/test-combo/components/index.ts | 1 + .../src/features/test-combo/index.ts | 1 + .../pages/ManageTestComboPage/index.tsx | 2 +- .../components/TestElementTable/columns.tsx | 2 +- .../components/TestElementTable/index.tsx | 4 +- .../pages/ManageTestElementPage/loader.ts | 8 +- .../components/TestSelector/TestSelector.tsx | 19 ++- .../test/components/TestTable/columns.tsx | 62 +++++----- .../test/components/TestTable/index.tsx | 70 +++-------- .../src/features/test/components/index.ts | 1 + apps/hcdc-web-app/src/features/test/index.ts | 1 + .../test/pages/ManageTestPage/index.tsx | 2 +- .../test/pages/ManageTestPage/loader.ts | 12 +- .../src/features/test/pages/index.ts | 0 .../src/infra/api/access-service/auth.ts | 5 +- .../src/infra/api/access-service/role.ts | 4 +- .../src/infra/api/access-service/sample.ts | 6 +- .../src/infra/api/access-service/slice.ts | 18 ++- .../infra/api/access-service/test-combo.ts | 2 +- .../infra/api/access-service/test-element.ts | 2 +- .../src/infra/api/access-service/test.ts | 6 +- .../src/infra/api/access-service/user.ts | 4 +- apps/hcdc-web-app/src/infra/router/routes.tsx | 115 ++++++++---------- apps/hcdc-web-app/vite.config.ts | 4 +- libs/hcdc/src/auth/action.ts | 3 +- libs/hcdc/src/entity/test/entity.ts | 2 +- libs/hcdc/src/entity/web-app/entity.ts | 1 + .../http/bootstrap/cors.bootstrap.ts | 26 +++- .../transport/http/dtos/paginated-response.ts | 5 + .../src/transport/http/dtos/search-request.ts | 1 + pnpm-lock.yaml | 12 ++ 82 files changed, 468 insertions(+), 547 deletions(-) create mode 100644 apps/hcdc-web-app/src/features/auth/state/actions.ts rename apps/hcdc-web-app/src/features/{indication/pages/ManageIndicationPage/components/IndicationTable => diagnosis/components/DiagnosisTable}/columns.tsx (63%) create mode 100644 apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/index.tsx create mode 100644 apps/hcdc-web-app/src/features/diagnosis/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/diagnosis/index.ts create mode 100644 apps/hcdc-web-app/src/features/diagnosis/pages/ManageDiagnosisPage/index.tsx create mode 100644 apps/hcdc-web-app/src/features/doctor/index.ts delete mode 100644 apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/index.tsx delete mode 100644 apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/index.tsx rename apps/hcdc-web-app/src/features/patient-type/{pages/ManagePatientTypePage => }/components/PatientTypeTable/columns.tsx (94%) rename apps/hcdc-web-app/src/features/patient-type/{pages/ManagePatientTypePage => }/components/PatientTypeTable/index.tsx (76%) create mode 100644 apps/hcdc-web-app/src/features/patient-type/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/patient-type/index.ts rename apps/hcdc-web-app/src/features/print-form/{pages/ManagePrintFormPage => }/components/PrintFormTable/columns.tsx (94%) rename apps/hcdc-web-app/src/features/print-form/{pages/ManagePrintFormPage => }/components/PrintFormTable/index.tsx (76%) create mode 100644 apps/hcdc-web-app/src/features/print-form/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/print-form/index.ts delete mode 100644 apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/columns.tsx delete mode 100644 apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/index.tsx delete mode 100644 apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/index.tsx rename apps/hcdc-web-app/src/features/sample-type/{pages/ManageSampleTypePage => }/components/SampleTypeTable/columns.tsx (94%) rename apps/hcdc-web-app/src/features/sample-type/{pages/ManageSampleTypePage => }/components/SampleTypeTable/index.tsx (76%) create mode 100644 apps/hcdc-web-app/src/features/sample-type/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/sample-type/index.ts rename apps/hcdc-web-app/src/features/test-category/{pages/ManageTestCategoryPage => }/components/TestCategoryTable/columns.tsx (95%) rename apps/hcdc-web-app/src/features/test-category/{pages/ManageTestCategoryPage => }/components/TestCategoryTable/index.tsx (76%) create mode 100644 apps/hcdc-web-app/src/features/test-category/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/test-category/index.ts rename apps/hcdc-web-app/src/features/test-combo/{pages/ManageTestComboPage => }/components/TestComboTable/columns.tsx (92%) rename apps/hcdc-web-app/src/features/test-combo/{pages/ManageTestComboPage => }/components/TestComboTable/index.tsx (75%) create mode 100644 apps/hcdc-web-app/src/features/test-combo/components/index.ts create mode 100644 apps/hcdc-web-app/src/features/test-combo/index.ts create mode 100644 apps/hcdc-web-app/src/features/test/index.ts delete mode 100644 apps/hcdc-web-app/src/features/test/pages/index.ts diff --git a/apps/hcdc-access-service/src/app/auth/use-case/populate-context.ts b/apps/hcdc-access-service/src/app/auth/use-case/populate-context.ts index 48283fe9..a2ef0d18 100644 --- a/apps/hcdc-access-service/src/app/auth/use-case/populate-context.ts +++ b/apps/hcdc-access-service/src/app/auth/use-case/populate-context.ts @@ -39,16 +39,7 @@ export class AuthPopulateContextUseCase { { user }, ) - // const ability = createAbility(compiledPermissions) - const ability = createAbility([ - { - subject: 'all', - action: 'manage', - // conditions: { - // name: { $ne: 'E2' }, - // }, - }, - ]) + const ability = createAbility(compiledPermissions) return { user, ability } } diff --git a/apps/hcdc-access-service/src/domain/entity/test/example.ts b/apps/hcdc-access-service/src/domain/entity/test/example.ts index 4e6c5d48..99a8fd0b 100644 --- a/apps/hcdc-access-service/src/domain/entity/test/example.ts +++ b/apps/hcdc-access-service/src/domain/entity/test/example.ts @@ -21,7 +21,7 @@ export const exampleTest = { required: false, nullable: true, }, - sampleTypeId: exampleMongoObjectId, + sampleTypeId: { ...exampleMongoObjectId, required: false }, sampleType: { required: false, nullable: true, diff --git a/apps/hcdc-access-service/src/infra/mongo/test/schema.ts b/apps/hcdc-access-service/src/infra/mongo/test/schema.ts index f991284c..2c9aa100 100644 --- a/apps/hcdc-access-service/src/infra/mongo/test/schema.ts +++ b/apps/hcdc-access-service/src/infra/mongo/test/schema.ts @@ -82,8 +82,8 @@ export class TestSchema extends BaseSchema { instrumentId?: string instrument?: InstrumentSchema | null - @Prop({ required: true, type: Types.ObjectId }) - sampleTypeId: string + @Prop({ required: false, type: Types.ObjectId }) + sampleTypeId?: string sampleType?: SampleTypeSchema | null @Prop({ required: true, type: Types.ObjectId }) diff --git a/apps/hcdc-access-service/src/main.ts b/apps/hcdc-access-service/src/main.ts index 1306ba69..0a147499 100644 --- a/apps/hcdc-access-service/src/main.ts +++ b/apps/hcdc-access-service/src/main.ts @@ -27,7 +27,10 @@ bootstrapApp( }, [ LogBootstrap, - CorsBootstrap, + CorsBootstrap({ + devOriginAllowList: ['http://localhost:5173'], + originAllowList: ['http://lab.hcdc.vn:8000'], + }), LifecycleBootstrap, PipeBootstrap, PrefixBootstrap, diff --git a/apps/hcdc-access-service/src/presentation/http/v1/test/dto/create.request-dto.ts b/apps/hcdc-access-service/src/presentation/http/v1/test/dto/create.request-dto.ts index 35e7401b..a1b34a78 100644 --- a/apps/hcdc-access-service/src/presentation/http/v1/test/dto/create.request-dto.ts +++ b/apps/hcdc-access-service/src/presentation/http/v1/test/dto/create.request-dto.ts @@ -44,8 +44,9 @@ export class TestCreateRequestDto { @Expose() @ApiProperty(exampleTest.sampleTypeId) + @IsOptional() @IsObjectId() - sampleTypeId: string + sampleTypeId?: string @Expose() @ApiProperty(exampleTest.testCategoryId) diff --git a/apps/hcdc-web-app/package.json b/apps/hcdc-web-app/package.json index 9221f57b..6729e13a 100644 --- a/apps/hcdc-web-app/package.json +++ b/apps/hcdc-web-app/package.json @@ -25,6 +25,7 @@ "@mui/material": "^5.15.10", "@mui/x-data-grid": "^6.19.4", "@reduxjs/toolkit": "^2.2.1", + "@vitejs/plugin-basic-ssl": "^1.1.0", "@vitejs/plugin-react": "^4.2.1", "date-fns": "^2.30.0", "lodash": "^4.17.21", diff --git a/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx b/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx index 39e186b2..4016e450 100644 --- a/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx +++ b/apps/hcdc-web-app/src/components/layout/AppBar/index.tsx @@ -17,6 +17,7 @@ import { useNavigation } from 'react-router-dom' import { useTypedDispatch, useTypedSelector } from 'src/infra/redux' import { ChangePassword, authSlice } from 'src/features/auth' import { ProgressBar } from 'src/components/ui' +import { userLogout } from 'src/features/auth/state/actions' interface AppBarProps { drawerWidth: number @@ -40,7 +41,7 @@ export function AppBar({ drawerWidth }: AppBarProps) { const handleLogout = () => { handleClose() - dispatch(authSlice.actions.handleLogout()) + dispatch(userLogout()) } const handleChangePassword = () => { @@ -56,7 +57,7 @@ export function AppBar({ drawerWidth }: AppBarProps) { > - Xin chào, {name} + {name}
, label: 'Nhập TT', @@ -97,6 +102,13 @@ export const drawerItems: DrawerItemGroup[] = [ icon: , label: 'Xuất báo cáo', destination: 'report/export', + isAuthorized: authOneOf([ + { + subject: AuthSubject.WebApp, + action: WebAppAction.View, + filterObj: { page: WebAppPage.XuatBaoCao } as WebApp, + }, + ]), }, ], }, @@ -107,61 +119,89 @@ export const drawerItems: DrawerItemGroup[] = [ icon: , label: 'Người dùng', destination: 'manage/users', - }, - { - icon: , - label: 'Đơn vị', - destination: 'manage/sample-origins', + isAuthorized: authOneOf([ + { subject: AuthSubject.User, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Bác sĩ', destination: 'manage/doctors', + isAuthorized: authOneOf([ + { subject: AuthSubject.Doctor, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Đối tượng', destination: 'manage/patient-types', + isAuthorized: authOneOf([ + { subject: AuthSubject.PatientType, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Chẩn đoán', - destination: 'manage/indications', + destination: 'manage/diagnoses', + isAuthorized: authOneOf([ + { subject: AuthSubject.Diagnosis, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Sinh phẩm', destination: 'manage/bio-products', + isAuthorized: authOneOf([ + { subject: AuthSubject.BioProduct, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Loại mẫu', destination: 'manage/sample-types', + isAuthorized: authOneOf([ + { subject: AuthSubject.SampleType, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Nhóm XN', destination: 'manage/test-categories', + isAuthorized: authOneOf([ + { subject: AuthSubject.TestCategory, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Tên XN', destination: 'manage/tests', + isAuthorized: authOneOf([ + { subject: AuthSubject.Test, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Thành phần XN', destination: 'manage/test-elements', + isAuthorized: authOneOf([ + { subject: AuthSubject.TestElement, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Bộ xét nghiệm', destination: 'manage/test-combos', + isAuthorized: authOneOf([ + { subject: AuthSubject.TestCombo, action: AUTH_ACTION_ALL }, + ]), }, { icon: , label: 'Form In', destination: 'manage/print-forms', + isAuthorized: authOneOf([ + { subject: AuthSubject.PrintForm, action: AUTH_ACTION_ALL }, + ]), }, ], }, diff --git a/apps/hcdc-web-app/src/components/layout/AppDrawer/index.tsx b/apps/hcdc-web-app/src/components/layout/AppDrawer/index.tsx index dbca1a28..47669e93 100644 --- a/apps/hcdc-web-app/src/components/layout/AppDrawer/index.tsx +++ b/apps/hcdc-web-app/src/components/layout/AppDrawer/index.tsx @@ -1,5 +1,4 @@ import { - Box, Divider, Drawer, List, @@ -12,7 +11,6 @@ import { import { Fragment } from 'react' import { matchPath, useLocation, useNavigate } from 'react-router-dom' -import { fullLogo } from 'src/assets/images' import { useDrawerItems } from './hooks' export function AppDrawer({ drawerWidth }: { drawerWidth: number }) { @@ -39,24 +37,6 @@ export function AppDrawer({ drawerWidth }: { drawerWidth: number }) { }, }} > - - - - {drawerItems.map((group, groupIndex) => ( - - {groupIndex > 0 && } + + {groupIndex > 0 && } {group.title} diff --git a/apps/hcdc-web-app/src/features/auth/index.ts b/apps/hcdc-web-app/src/features/auth/index.ts index 422005e0..408cf58b 100644 --- a/apps/hcdc-web-app/src/features/auth/index.ts +++ b/apps/hcdc-web-app/src/features/auth/index.ts @@ -1,2 +1,2 @@ -export * from './components' export * from './state' +export * from './components' diff --git a/apps/hcdc-web-app/src/features/auth/pages/LoginPage/login-form.tsx b/apps/hcdc-web-app/src/features/auth/pages/LoginPage/login-form.tsx index 69f813d9..4fac4767 100644 --- a/apps/hcdc-web-app/src/features/auth/pages/LoginPage/login-form.tsx +++ b/apps/hcdc-web-app/src/features/auth/pages/LoginPage/login-form.tsx @@ -7,7 +7,7 @@ import LoadingButton from '@mui/lab/LoadingButton' import { useForm } from 'react-hook-form' import { toast } from 'react-toastify' -import { fullLogo } from 'src/assets/images' +// import { fullLogo } from 'src/assets/images' import { formDefaultValues, formResolver, FormSchema } from './validation' import { FormTextField, FormContainer } from 'src/components/form' import { @@ -36,6 +36,8 @@ export function LoginForm({ reason }: LoginPageProps) { useEffect(() => { const response = (error as any)?.data as HttpErrorResponse + if (!response) return + const { errorCode } = response if (errorCode === DomainErrorCode.AUTHN_LOGIN_INVALID_USERNAME) { toast.dismiss() @@ -68,10 +70,10 @@ export function LoginForm({ reason }: LoginPageProps) { alignItems: 'center', }} > - + /> */} { + return { payload: null } +}) diff --git a/apps/hcdc-web-app/src/features/auth/state/index.ts b/apps/hcdc-web-app/src/features/auth/state/index.ts index 1f3c5a2e..d29409f1 100644 --- a/apps/hcdc-web-app/src/features/auth/state/index.ts +++ b/apps/hcdc-web-app/src/features/auth/state/index.ts @@ -1,2 +1,2 @@ -export * from './slice' export * from './types' +export * from './slice' diff --git a/apps/hcdc-web-app/src/features/auth/state/slice.ts b/apps/hcdc-web-app/src/features/auth/state/slice.ts index 5e25c8fd..9fac67d5 100644 --- a/apps/hcdc-web-app/src/features/auth/state/slice.ts +++ b/apps/hcdc-web-app/src/features/auth/state/slice.ts @@ -9,6 +9,7 @@ import { AuthStateAuthenticated, AuthStateUnauthenticated, } from './types' +import { userLogout } from './actions' export const authSlice = createSlice({ name: 'auth', @@ -30,17 +31,16 @@ export const authSlice = createSlice({ selectActiveBranchId: (state) => state.isAuthenticated === true ? state.data.activeBranchId : null, }, - reducers: { - handleLogout: (state) => { + reducers: {}, + extraReducers: (builder) => { + builder.addCase(userLogout, (state) => { if (state.isAuthenticated === false) return const unauthenticatedState = state as unknown as AuthStateUnauthenticated unauthenticatedState.isAuthenticated = false // @ts-ignore unauthenticatedState.data = undefined - }, - }, - extraReducers: (builder) => { + }) builder.addMatcher( authApi.endpoints.authLogin.matchFulfilled, (state, { payload }) => { diff --git a/apps/hcdc-web-app/src/features/bio-product/components/BioProductTable/index.tsx b/apps/hcdc-web-app/src/features/bio-product/components/BioProductTable/index.tsx index c71a36b9..db657951 100644 --- a/apps/hcdc-web-app/src/features/bio-product/components/BioProductTable/index.tsx +++ b/apps/hcdc-web-app/src/features/bio-product/components/BioProductTable/index.tsx @@ -16,7 +16,7 @@ import { bioProductColumns } from './columns' export function BioProductTable() { const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) diff --git a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/columns.tsx b/apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/columns.tsx similarity index 63% rename from apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/columns.tsx rename to apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/columns.tsx index 561f3dd5..ee3a75bd 100644 --- a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/columns.tsx @@ -1,10 +1,10 @@ import { GridColDef } from '@mui/x-data-grid' -import { IndicationResponseDto } from 'src/infra/api/access-service/indication' +import { DiagnosisResponseDto } from 'src/infra/api/access-service/diagnosis' -export const indicationColumns: GridColDef[] = [ +export const diagnosisColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', minWidth: 100, diff --git a/apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/index.tsx b/apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/index.tsx new file mode 100644 index 00000000..523a62df --- /dev/null +++ b/apps/hcdc-web-app/src/features/diagnosis/components/DiagnosisTable/index.tsx @@ -0,0 +1,70 @@ +import { Skeleton } from '@mui/material' + +import { + useDiagnosisCreateMutation, + useDiagnosisDeleteByIdMutation, + useDiagnosisSearchQuery, + useDiagnosisUpdateByIdMutation, + useLazyDiagnosisSearchQuery, +} from 'src/infra/api/access-service/diagnosis' +import { CrudTable } from 'src/components/table' +import { useCrudPagination } from 'src/shared/hooks' +import { diagnosisColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' + +export function DiagnosisTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! + const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ + sort: { displayIndex: 1 }, + offset: 0, + }) + + const { data, isFetching } = useDiagnosisSearchQuery(filterObj) + const [searchDiagnosiss] = useLazyDiagnosisSearchQuery() + + const [createDiagnosis, { isLoading: isCreating }] = + useDiagnosisCreateMutation() + const [updateDiagnosis, { isLoading: isUpdating }] = + useDiagnosisUpdateByIdMutation() + const [deleteDiagnosis, { isLoading: isDeleting }] = + useDiagnosisDeleteByIdMutation() + + return data?.items != undefined ? ( + { + await createDiagnosis({ + name: item.name, + displayIndex: item.displayIndex, + branchId, + }).unwrap() + }} + onItemUpdate={async (newItem) => { + await updateDiagnosis({ + id: newItem._id, + diagnosisUpdateRequestDto: { + name: newItem.name, + displayIndex: newItem.displayIndex, + }, + }).unwrap() + }} + onItemDelete={async (item) => { + await deleteDiagnosis(item._id).unwrap() + }} + onRefresh={async () => { + await searchDiagnosiss(filterObj).unwrap() + }} + /> + ) : ( + + ) +} diff --git a/apps/hcdc-web-app/src/features/diagnosis/components/index.ts b/apps/hcdc-web-app/src/features/diagnosis/components/index.ts new file mode 100644 index 00000000..c11294c8 --- /dev/null +++ b/apps/hcdc-web-app/src/features/diagnosis/components/index.ts @@ -0,0 +1 @@ +export * from './DiagnosisTable' diff --git a/apps/hcdc-web-app/src/features/diagnosis/index.ts b/apps/hcdc-web-app/src/features/diagnosis/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/diagnosis/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/diagnosis/pages/ManageDiagnosisPage/index.tsx b/apps/hcdc-web-app/src/features/diagnosis/pages/ManageDiagnosisPage/index.tsx new file mode 100644 index 00000000..02aebb9a --- /dev/null +++ b/apps/hcdc-web-app/src/features/diagnosis/pages/ManageDiagnosisPage/index.tsx @@ -0,0 +1,9 @@ +import { DiagnosisTable } from '../../components' + +export default function ManageDiagnosisPage() { + return ( + <> + + + ) +} diff --git a/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/columns.tsx b/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/columns.tsx index 409ce267..14f28f3b 100644 --- a/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/columns.tsx @@ -4,7 +4,7 @@ import { DoctorResponseDto } from 'src/infra/api/access-service/doctor' export const doctorColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', minWidth: 100, diff --git a/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/index.tsx b/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/index.tsx index fe5295a8..0a9708d4 100644 --- a/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/index.tsx +++ b/apps/hcdc-web-app/src/features/doctor/components/DoctorTable/index.tsx @@ -10,10 +10,13 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { doctorColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function DoctorTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -40,25 +43,24 @@ export function DoctorTable() { onItemCreate={async (item) => { await createDoctor({ name: item.name, - index: item.index, + displayIndex: item.displayIndex, + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updateDoctor({ id: newItem._id, - updateDoctorRequestDto: { + doctorUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, }, }).unwrap() }} onItemDelete={async (item) => { - await deleteDoctor({ - id: item._id, - }).unwrap() + await deleteDoctor(item._id).unwrap() }} onRefresh={async () => { - await searchDoctors({ searchDoctorRequestDto: filterObj }).unwrap() + await searchDoctors(filterObj).unwrap() }} /> ) : ( diff --git a/apps/hcdc-web-app/src/features/doctor/index.ts b/apps/hcdc-web-app/src/features/doctor/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/doctor/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/homepage/pages/Homepage/index.tsx b/apps/hcdc-web-app/src/features/homepage/pages/Homepage/index.tsx index 9e147b01..cdef6f5c 100644 --- a/apps/hcdc-web-app/src/features/homepage/pages/Homepage/index.tsx +++ b/apps/hcdc-web-app/src/features/homepage/pages/Homepage/index.tsx @@ -1,16 +1,10 @@ -// import { BATHANGHAI_COMMON } from '@diut/hcdc' -// import { COMMON_TEST } from '@diut/common' - export default function HomePage() { return ( - - //

- // {COMMON_TEST} - // {BATHANGHAI_COMMON} - //

+ // +

) } diff --git a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/index.tsx b/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/index.tsx deleted file mode 100644 index 4bc91ca0..00000000 --- a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/components/IndicationTable/index.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { Skeleton } from '@mui/material' - -import { - useIndicationCreateMutation, - useIndicationDeleteByIdMutation, - useIndicationSearchQuery, - useIndicationUpdateByIdMutation, - useLazyIndicationSearchQuery, -} from 'src/infra/api/access-service/indication' -import { CrudTable } from 'src/components/table' -import { useCrudPagination } from 'src/shared/hooks' -import { indicationColumns } from './columns' - -export function IndicationTable() { - const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, - offset: 0, - }) - - const { data, isFetching } = useIndicationSearchQuery(filterObj) - const [searchIndications] = useLazyIndicationSearchQuery() - - const [createIndication, { isLoading: isCreating }] = - useIndicationCreateMutation() - const [updateIndication, { isLoading: isUpdating }] = - useIndicationUpdateByIdMutation() - const [deleteIndication, { isLoading: isDeleting }] = - useIndicationDeleteByIdMutation() - - return data?.items != undefined ? ( - { - await createIndication({ - createIndicationRequestDto: { - name: item.name, - index: item.index, - }, - }).unwrap() - }} - onItemUpdate={async (newItem, oldItem) => { - await updateIndication({ - id: newItem._id, - updateIndicationRequestDto: { - name: newItem.name, - index: newItem.index, - }, - }).unwrap() - }} - onItemDelete={async (item) => { - await deleteIndication({ - id: item._id, - }).unwrap() - }} - onRefresh={async () => { - await searchIndications({ - searchIndicationRequestDto: filterObj, - }).unwrap() - }} - /> - ) : ( - - ) -} diff --git a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/index.tsx b/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/index.tsx deleted file mode 100644 index cdac811c..00000000 --- a/apps/hcdc-web-app/src/features/indication/pages/ManageIndicationPage/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { IndicationTable } from './components/IndicationTable' - -export default function ManageIndicationPage() { - return ( - <> - - - ) -} diff --git a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/columns.tsx b/apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/columns.tsx similarity index 94% rename from apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/columns.tsx rename to apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/columns.tsx index 42aacddc..04641599 100644 --- a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/columns.tsx @@ -4,7 +4,7 @@ import { PatientTypeResponseDto } from 'src/infra/api/access-service/patient-typ export const patientTypeColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', minWidth: 100, diff --git a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/index.tsx b/apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/index.tsx similarity index 76% rename from apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/index.tsx rename to apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/index.tsx index 360a41a2..ee043c9c 100644 --- a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/components/PatientTypeTable/index.tsx +++ b/apps/hcdc-web-app/src/features/patient-type/components/PatientTypeTable/index.tsx @@ -10,10 +10,13 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { patientTypeColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function PatientTypeTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -40,30 +43,25 @@ export function PatientTypeTable() { onPageSizeChange={onPageSizeChange} onItemCreate={async (item) => { await createPatientType({ - createPatientTypeRequestDto: { - name: item.name, - index: item.index, - }, + name: item.name, + displayIndex: item.displayIndex, + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updatePatientType({ id: newItem._id, - updatePatientTypeRequestDto: { + patientTypeUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, }, }).unwrap() }} onItemDelete={async (item) => { - await deletePatientType({ - id: item._id, - }).unwrap() + await deletePatientType(item._id).unwrap() }} onRefresh={async () => { - await searchPatientTypes({ - searchPatientTypeRequestDto: filterObj, - }).unwrap() + await searchPatientTypes(filterObj).unwrap() }} /> ) : ( diff --git a/apps/hcdc-web-app/src/features/patient-type/components/index.ts b/apps/hcdc-web-app/src/features/patient-type/components/index.ts new file mode 100644 index 00000000..977c8a1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/patient-type/components/index.ts @@ -0,0 +1 @@ +export * from './PatientTypeTable' diff --git a/apps/hcdc-web-app/src/features/patient-type/index.ts b/apps/hcdc-web-app/src/features/patient-type/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/patient-type/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/index.tsx b/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/index.tsx index 7acd0692..150f8ba8 100644 --- a/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/index.tsx +++ b/apps/hcdc-web-app/src/features/patient-type/pages/ManagePatientTypePage/index.tsx @@ -1,4 +1,4 @@ -import { PatientTypeTable } from './components/PatientTypeTable' +import { PatientTypeTable } from '../../components' export default function ManagePatientTypePage() { return ( diff --git a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/columns.tsx b/apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/columns.tsx similarity index 94% rename from apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/columns.tsx rename to apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/columns.tsx index c24dbb50..da5df143 100644 --- a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/columns.tsx @@ -4,7 +4,7 @@ import { PrintFormResponseDto } from 'src/infra/api/access-service/print-form' export const printFormColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', width: 100, @@ -27,7 +27,7 @@ export const printFormColumns: GridColDef[] = [ editable: true, }, { - field: 'authorPosition', + field: 'authorTitle', headerName: 'Chức vụ', width: 250, sortable: false, diff --git a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/index.tsx b/apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/index.tsx similarity index 76% rename from apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/index.tsx rename to apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/index.tsx index 43166474..1f2cb57d 100644 --- a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/components/PrintFormTable/index.tsx +++ b/apps/hcdc-web-app/src/features/print-form/components/PrintFormTable/index.tsx @@ -8,10 +8,13 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { printFormColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function PrintFormTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -32,23 +35,21 @@ export function PrintFormTable() { pageSize={data?.limit!} onPageChange={onPageChange} onPageSizeChange={onPageSizeChange} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updatePrintForm({ id: newItem._id, - updatePrintFormRequestDto: { + printFormUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, isAuthorLocked: newItem.isAuthorLocked, - authorPosition: newItem.authorPosition, + authorTitle: newItem.authorTitle, authorName: newItem.authorName, titleMargin: newItem.titleMargin, }, }).unwrap() }} onRefresh={async () => { - await searchPrintForms({ - searchPrintFormRequestDto: filterObj, - }).unwrap() + await searchPrintForms(filterObj).unwrap() }} /> ) : ( diff --git a/apps/hcdc-web-app/src/features/print-form/components/index.ts b/apps/hcdc-web-app/src/features/print-form/components/index.ts new file mode 100644 index 00000000..f4c6c2ab --- /dev/null +++ b/apps/hcdc-web-app/src/features/print-form/components/index.ts @@ -0,0 +1 @@ +export * from './PrintFormTable' diff --git a/apps/hcdc-web-app/src/features/print-form/index.ts b/apps/hcdc-web-app/src/features/print-form/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/print-form/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/index.tsx b/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/index.tsx index 0917af3a..f195fd02 100644 --- a/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/index.tsx +++ b/apps/hcdc-web-app/src/features/print-form/pages/ManagePrintFormPage/index.tsx @@ -1,4 +1,4 @@ -import { PrintFormTable } from './components/PrintFormTable' +import { PrintFormTable } from '../../components' export default function ManagePatientTypePage() { return ( diff --git a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/columns.tsx b/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/columns.tsx deleted file mode 100644 index e5140713..00000000 --- a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/columns.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { GridColDef } from '@mui/x-data-grid' - -import { SampleOriginResponseDto } from 'src/infra/api/access-service/sample-origin' - -export const sampleOriginColumns: GridColDef[] = [ - { - field: 'index', - headerName: 'Thứ tự', - type: 'number', - minWidth: 100, - sortable: false, - editable: true, - }, - { - field: 'name', - headerName: 'Tên đơn vị', - flex: 1, - minWidth: 300, - sortable: false, - editable: true, - }, -] diff --git a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/index.tsx b/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/index.tsx deleted file mode 100644 index 8a2e97cb..00000000 --- a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/components/SampleOriginTable/index.tsx +++ /dev/null @@ -1,72 +0,0 @@ -import { Skeleton } from '@mui/material' - -import { - useSampleOriginCreateMutation, - useSampleOriginDeleteByIdMutation, - useSampleOriginSearchQuery, - useSampleOriginUpdateByIdMutation, - useLazySampleOriginSearchQuery, -} from 'src/infra/api/access-service/sample-origin' -import { CrudTable } from 'src/components/table' -import { useCrudPagination } from 'src/shared/hooks' -import { sampleOriginColumns } from './columns' - -export function SampleOriginTable() { - const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, - offset: 0, - }) - - const { data, isFetching } = useSampleOriginSearchQuery(filterObj) - const [searchSampleOrigins] = useLazySampleOriginSearchQuery() - - const [createSampleOrigin, { isLoading: isCreating }] = - useSampleOriginCreateMutation() - const [updateSampleOrigin, { isLoading: isUpdating }] = - useSampleOriginUpdateByIdMutation() - const [deleteSampleOrigin, { isLoading: isDeleting }] = - useSampleOriginDeleteByIdMutation() - - return data?.items != undefined ? ( - { - await createSampleOrigin({ - createSampleOriginRequestDto: { - name: item.name, - index: item.index, - }, - }).unwrap() - }} - onItemUpdate={async (newItem, oldItem) => { - await updateSampleOrigin({ - id: newItem._id, - updateSampleOriginRequestDto: { - name: newItem.name, - index: newItem.index, - }, - }).unwrap() - }} - onItemDelete={async (item) => { - await deleteSampleOrigin({ - id: item._id, - }).unwrap() - }} - onRefresh={async () => { - await searchSampleOrigins({ - searchSampleOriginRequestDto: filterObj, - }).unwrap() - }} - /> - ) : ( - - ) -} diff --git a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/index.tsx b/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/index.tsx deleted file mode 100644 index de1e0514..00000000 --- a/apps/hcdc-web-app/src/features/sample-origin/pages/ManageSampleOriginPage/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { SampleOriginTable } from './components/SampleOriginTable' - -export default function ManageSampleOriginPage() { - return ( - <> - - - ) -} diff --git a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/columns.tsx b/apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/columns.tsx similarity index 94% rename from apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/columns.tsx rename to apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/columns.tsx index 55938bca..07933521 100644 --- a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/columns.tsx @@ -4,7 +4,7 @@ import { BioProductResponseDto } from 'src/infra/api/access-service/bio-product' export const sampleTypeColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', minWidth: 100, diff --git a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/index.tsx b/apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/index.tsx similarity index 76% rename from apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/index.tsx rename to apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/index.tsx index 3339a4ea..e421c677 100644 --- a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/components/SampleTypeTable/index.tsx +++ b/apps/hcdc-web-app/src/features/sample-type/components/SampleTypeTable/index.tsx @@ -10,10 +10,13 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { sampleTypeColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function SampleTypeTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -40,30 +43,25 @@ export function SampleTypeTable() { onPageSizeChange={onPageSizeChange} onItemCreate={async (item) => { await createSampleType({ - createSampleTypeRequestDto: { - name: item.name, - index: item.index, - }, + name: item.name, + displayIndex: item.displayIndex, + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updateSampleType({ id: newItem._id, - updateSampleTypeRequestDto: { + sampleTypeUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, }, }).unwrap() }} onItemDelete={async (item) => { - await deleteSampleType({ - id: item._id, - }).unwrap() + await deleteSampleType(item._id).unwrap() }} onRefresh={async () => { - await searchSampleTypes({ - searchSampleTypeRequestDto: filterObj, - }).unwrap() + await searchSampleTypes(filterObj).unwrap() }} /> ) : ( diff --git a/apps/hcdc-web-app/src/features/sample-type/components/index.ts b/apps/hcdc-web-app/src/features/sample-type/components/index.ts new file mode 100644 index 00000000..2802f404 --- /dev/null +++ b/apps/hcdc-web-app/src/features/sample-type/components/index.ts @@ -0,0 +1 @@ +export * from './SampleTypeTable' diff --git a/apps/hcdc-web-app/src/features/sample-type/index.ts b/apps/hcdc-web-app/src/features/sample-type/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/sample-type/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/index.tsx b/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/index.tsx index 06574be5..60d45770 100644 --- a/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/index.tsx +++ b/apps/hcdc-web-app/src/features/sample-type/pages/ManageSampleTypePage/index.tsx @@ -1,4 +1,4 @@ -import { SampleTypeTable } from './components/SampleTypeTable' +import { SampleTypeTable } from '../../components' export default function ManageSampleTypePage() { return ( diff --git a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/columns.tsx b/apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/columns.tsx similarity index 95% rename from apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/columns.tsx rename to apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/columns.tsx index 7b393ad5..cde675cc 100644 --- a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/columns.tsx @@ -4,7 +4,7 @@ import { TestCategoryResponseDto } from 'src/infra/api/access-service/test-categ export const testCategoryColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự nhập', type: 'number', width: 100, diff --git a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/index.tsx b/apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/index.tsx similarity index 76% rename from apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/index.tsx rename to apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/index.tsx index 749f547e..341d6c57 100644 --- a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/components/TestCategoryTable/index.tsx +++ b/apps/hcdc-web-app/src/features/test-category/components/TestCategoryTable/index.tsx @@ -10,10 +10,13 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { testCategoryColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function TestCategoryTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -40,32 +43,27 @@ export function TestCategoryTable() { onPageSizeChange={onPageSizeChange} onItemCreate={async (item) => { await createTestCategory({ - createTestCategoryRequestDto: { - name: item.name, - index: item.index, - reportIndex: item.reportIndex, - }, + name: item.name, + displayIndex: item.displayIndex, + reportIndex: item.reportIndex, + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updateTestCategory({ id: newItem._id, - updateTestCategoryRequestDto: { + testCategoryUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, reportIndex: newItem.reportIndex, }, }).unwrap() }} onItemDelete={async (item) => { - await deleteTestCategory({ - id: item._id, - }).unwrap() + await deleteTestCategory(item._id).unwrap() }} onRefresh={async () => { - await searchTestCategorys({ - searchTestCategoryRequestDto: filterObj, - }).unwrap() + await searchTestCategorys(filterObj).unwrap() }} /> ) : ( diff --git a/apps/hcdc-web-app/src/features/test-category/components/index.ts b/apps/hcdc-web-app/src/features/test-category/components/index.ts new file mode 100644 index 00000000..51331425 --- /dev/null +++ b/apps/hcdc-web-app/src/features/test-category/components/index.ts @@ -0,0 +1 @@ +export * from './TestCategoryTable' diff --git a/apps/hcdc-web-app/src/features/test-category/index.ts b/apps/hcdc-web-app/src/features/test-category/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/test-category/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/index.tsx b/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/index.tsx index 0d332da7..604bf7e8 100644 --- a/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/index.tsx +++ b/apps/hcdc-web-app/src/features/test-category/pages/ManageTestCategoryPage/index.tsx @@ -1,4 +1,4 @@ -import { TestCategoryTable } from './components/TestCategoryTable' +import { TestCategoryTable } from '../../components' export default function ManageTestCategoryPage() { return ( diff --git a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/columns.tsx b/apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/columns.tsx similarity index 92% rename from apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/columns.tsx rename to apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/columns.tsx index 4414fbaf..d88c274a 100644 --- a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/columns.tsx @@ -4,7 +4,7 @@ import { TestComboResponseDto } from 'src/infra/api/access-service/test-combo' export const testComboColumns: GridColDef[] = [ { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', minWidth: 100, @@ -20,7 +20,7 @@ export const testComboColumns: GridColDef[] = [ editable: true, }, { - field: 'children', + field: 'testIds', headerName: 'Số lượng XN', minWidth: 100, sortable: false, diff --git a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/index.tsx b/apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/index.tsx similarity index 75% rename from apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/index.tsx rename to apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/index.tsx index 4942ebf4..b5d12891 100644 --- a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/components/TestComboTable/index.tsx +++ b/apps/hcdc-web-app/src/features/test-combo/components/TestComboTable/index.tsx @@ -12,11 +12,14 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { testComboColumns } from './columns' -import { TestSelector } from 'src/features/test/components/TestSelector' +import { TestSelector } from 'src/features/test' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' export function TestComboTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { filterObj, onPageChange, onPageSizeChange } = useCrudPagination({ - sort: { index: 1 }, + sort: { displayIndex: 1 }, offset: 0, }) @@ -47,31 +50,26 @@ export function TestComboTable() { onPageSizeChange={onPageSizeChange} onItemCreate={async (item) => { await createTestCombo({ - createTestComboRequestDto: { - name: item.name, - index: item.index, - children: [], - }, + name: item.name, + displayIndex: item.displayIndex, + testIds: [], + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updateTestCombo({ id: newItem._id, - updateTestComboRequestDto: { + testComboUpdateRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, }, }).unwrap() }} onItemDelete={async (item) => { - await deleteTestCombo({ - id: item._id, - }).unwrap() + await deleteTestCombo(item._id).unwrap() }} onRefresh={async () => { - await searchTestCombos({ - searchTestComboRequestDto: filterObj, - }).unwrap() + await searchTestCombos(filterObj).unwrap() }} customRowActions={[ { @@ -84,15 +82,15 @@ export function TestComboTable() { /> { setSelectedCombo(null) }} onSubmit={(tests) => { updateTestCombo({ id: selectedCombo?._id!, - updateTestComboRequestDto: { - children: tests.map(({ _id }) => _id), + testComboUpdateRequestDto: { + testIds: tests.map(({ _id }) => _id), }, }) }} diff --git a/apps/hcdc-web-app/src/features/test-combo/components/index.ts b/apps/hcdc-web-app/src/features/test-combo/components/index.ts new file mode 100644 index 00000000..c9f154bd --- /dev/null +++ b/apps/hcdc-web-app/src/features/test-combo/components/index.ts @@ -0,0 +1 @@ +export * from './TestComboTable' diff --git a/apps/hcdc-web-app/src/features/test-combo/index.ts b/apps/hcdc-web-app/src/features/test-combo/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/test-combo/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/index.tsx b/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/index.tsx index 7239d89c..05a3420a 100644 --- a/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/index.tsx +++ b/apps/hcdc-web-app/src/features/test-combo/pages/ManageTestComboPage/index.tsx @@ -1,4 +1,4 @@ -import { TestComboTable } from './components/TestComboTable' +import { TestComboTable } from '../../components' export default function ManageTestComboPage() { return ( diff --git a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/columns.tsx b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/columns.tsx index 24e5368d..42d70dc2 100644 --- a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/columns.tsx +++ b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/columns.tsx @@ -30,7 +30,7 @@ export function useTestElementColumns( }, }, { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự nhập', type: 'number', minWidth: 70, diff --git a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/index.tsx b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/index.tsx index acc5e9d1..89e3d4e7 100644 --- a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/index.tsx +++ b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/components/TestElementTable/index.tsx @@ -127,7 +127,7 @@ export function TestElementTable() { await createTestElement({ createTestElementRequestDto: { name: item.name, - index: item.index, + displayIndex: item.displayIndex, printIndex: item.printIndex, reportOrder: item.reportOrder, test: tests.find((test) => test.name === (item.test as any)) @@ -143,7 +143,7 @@ export function TestElementTable() { id: newItem._id, updateTestElementRequestDto: { name: newItem.name, - index: newItem.index, + displayIndex: newItem.displayIndex, printIndex: newItem.printIndex, reportOrder: newItem.reportOrder, test: tests.find((test) => test.name === (newItem.test as any)) diff --git a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/loader.ts b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/loader.ts index 870295e9..47aeab62 100644 --- a/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/loader.ts +++ b/apps/hcdc-web-app/src/features/test-element/pages/ManageTestElementPage/loader.ts @@ -7,18 +7,14 @@ export const manageTestElemenentPageLoader = async () => { appStore .dispatch( testCategoryApi.endpoints.testCategorySearch.initiate({ - searchTestCategoryRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, }), ) .unwrap(), appStore .dispatch( testApi.endpoints.testSearch.initiate({ - searchTestRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, }), ) .unwrap(), diff --git a/apps/hcdc-web-app/src/features/test/components/TestSelector/TestSelector.tsx b/apps/hcdc-web-app/src/features/test/components/TestSelector/TestSelector.tsx index c432a0a1..f3b88d35 100644 --- a/apps/hcdc-web-app/src/features/test/components/TestSelector/TestSelector.tsx +++ b/apps/hcdc-web-app/src/features/test/components/TestSelector/TestSelector.tsx @@ -34,15 +34,12 @@ export function TestSelector({ showCombos = false, }: TestSelectorProps) { const { data, isFetching } = useTestSearchQuery({ - searchTestRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, + populates: [{ path: 'testCategory', fields: ['name', 'displayIndex'] }], }) const { data: combos, isFetching: isFetchingCombos } = - useTestComboSearchQuery({ - searchTestComboRequestDto: { sort: { index: 1 } }, - }) + useTestComboSearchQuery({ sort: { index: 1 } }) const [selectedIds, setSelectedIds] = React.useState([]) @@ -50,7 +47,7 @@ export function TestSelector({ if (isFetching === false) { setSelectedIds( previousState.filter((testId) => - data?.items.some((test) => test.category && test._id === testId), + data?.items.some((test) => test._id === testId), ), ) } @@ -58,8 +55,8 @@ export function TestSelector({ const categories: string[] = [] const groups = groupBy(data?.items ?? [], (test) => { - categories[test?.category?.index] = test?.category?.name - return test?.category?.name + categories[test?.testCategory?.displayIndex!] = test?.testCategory?.name! + return test?.testCategory?.name }) const handleSubmit = () => { @@ -110,7 +107,7 @@ export function TestSelector({ key={combo._id} variant="outlined" onClick={() => { - setSelectedIds(combo.children) + setSelectedIds(combo.testIds) }} > {combo.name} @@ -153,7 +150,7 @@ export function TestSelector({ [] { return [ { - field: 'category', + field: 'testCategoryId', headerName: 'Nhóm XN', type: 'singleSelect', width: 200, sortable: false, editable: true, - valueOptions: testCategories?.map((item) => ({ - value: item?.name, - label: item?.name, + valueOptions: testCategories.map((item) => ({ + value: item._id, + label: item.name, })), - valueGetter: ({ value }) => { - return value?.name ?? '' - }, }, { - field: 'index', + field: 'displayIndex', headerName: 'Thứ tự', type: 'number', width: 70, @@ -45,29 +43,23 @@ export function useTestColumns( editable: true, }, { - field: 'bioProduct', + field: 'bioProductId', headerName: 'Sinh phẩm', type: 'singleSelect', width: 200, sortable: false, editable: true, - valueOptions: [{ label: '-- không --', value: NO_BIOPRODUCT }].concat( - bioProducts?.map((item) => ({ - value: item?.name, - label: item?.name, + valueOptions: [ + { + label: NO_BIOPRODUCT, + value: undefined as unknown as string, + }, + ].concat( + bioProducts.map((item) => ({ + value: item._id, + label: item.name, })), ), - valueGetter: ({ value }) => { - return value?.name ?? '' - }, - }, - { - field: 'shouldNotPrint', - type: 'boolean', - headerName: 'Không In', - width: 80, - sortable: false, - editable: true, }, { field: 'shouldDisplayWithChildren', @@ -78,19 +70,23 @@ export function useTestColumns( editable: true, }, { - field: 'printForm', + field: 'printFormId', type: 'singleSelect', headerName: 'Form In KQ', width: 150, sortable: false, editable: true, - valueOptions: printForms.map(({ name }) => ({ - label: name, - value: name, - })), - valueGetter: ({ value }) => { - return printForms.find(({ _id }) => _id === value)?.name - }, + valueOptions: [ + { + label: NO_PRINTFORM, + value: undefined as unknown as string, + }, + ].concat( + printForms.map((printForm) => ({ + value: printForm._id, + label: printForm.name, + })), + ), }, ] } diff --git a/apps/hcdc-web-app/src/features/test/components/TestTable/index.tsx b/apps/hcdc-web-app/src/features/test/components/TestTable/index.tsx index 7becf063..effd33fc 100644 --- a/apps/hcdc-web-app/src/features/test/components/TestTable/index.tsx +++ b/apps/hcdc-web-app/src/features/test/components/TestTable/index.tsx @@ -1,4 +1,3 @@ -import { PrintForm } from '@diut/hcdc' import { FormControl, InputLabel, @@ -8,7 +7,6 @@ import { } from '@mui/material' import { useLoaderData } from 'react-router-dom' -import { BioProductResponseDto } from 'src/infra/api/access-service/bio-product' import { useTestCreateMutation, useTestDeleteByIdMutation, @@ -19,23 +17,14 @@ import { import { CrudTable } from 'src/components/table' import { useCrudPagination } from 'src/shared/hooks' import { manageTestPageLoader } from '../../pages/ManageTestPage/loader' -import { NO_BIOPRODUCT, useTestColumns } from './columns' +import { useTestColumns } from './columns' +import { authSlice } from 'src/features/auth' +import { useTypedSelector } from 'src/infra/redux' const ALL_CATEGORIES = 'ALL_CATEGORIES' -function setBioProductId( - bioProducts: BioProductResponseDto[], - bioProductId: string, -) { - if (bioProductId === NO_BIOPRODUCT) { - return null - } - return bioProducts.find( - (bioProduct) => bioProduct.name === (bioProductId as any), - )?._id! -} - export function TestTable() { + const branchId = useTypedSelector(authSlice.selectors.selectActiveBranchId)! const { testCategories, bioProducts, printForms } = useLoaderData() as Awaited> @@ -67,52 +56,33 @@ export function TestTable() { onPageSizeChange={onPageSizeChange} onItemCreate={async (item) => { await createTest({ - createTestRequestDto: { - name: item.name, - index: item.index, - category: testCategories.find( - (category) => category.name === (item.category as any), - )?._id!, - bioProduct: setBioProductId(bioProducts, item.bioProduct as any)!, - printForm: printForms.find( - (printForm) => printForm.name === item.printForm, - )?._id! as PrintForm, - shouldNotPrint: item.shouldNotPrint ?? false, - shouldDisplayWithChildren: item.shouldDisplayWithChildren ?? false, - }, + name: item.name, + displayIndex: item.displayIndex, + testCategoryId: item.testCategoryId, + bioProductId: item.bioProductId, + printFormId: item.printFormId, + shouldDisplayWithChildren: item.shouldDisplayWithChildren ?? false, + branchId, }).unwrap() }} - onItemUpdate={async (newItem, oldItem) => { + onItemUpdate={async (newItem) => { await updateTest({ id: newItem._id, - updateTestRequestDto: { + testUpdateRequestDto: { name: newItem.name, - index: newItem.index, - category: testCategories.find( - (category) => category.name === (newItem.category as any), - )?._id, - bioProduct: setBioProductId( - bioProducts, - newItem.bioProduct as any, - )!, - printForm: printForms.find( - (printForm) => printForm.name === newItem.printForm, - )?._id! as PrintForm, - shouldNotPrint: newItem.shouldNotPrint ?? false, - shouldDisplayWithChildren: - newItem.shouldDisplayWithChildren ?? false, + displayIndex: newItem.displayIndex, + testCategoryId: newItem.testCategoryId, + bioProductId: newItem.bioProductId, + printFormId: newItem.printFormId, + shouldDisplayWithChildren: newItem.shouldDisplayWithChildren, }, }).unwrap() }} onItemDelete={async (item) => { - await deleteTest({ - id: item._id, - }).unwrap() + await deleteTest(item._id).unwrap() }} onRefresh={async () => { - await searchTests({ - searchTestRequestDto: filterObj, - }).unwrap() + await searchTests(filterObj).unwrap() }} TopRightComponent={ diff --git a/apps/hcdc-web-app/src/features/test/components/index.ts b/apps/hcdc-web-app/src/features/test/components/index.ts index 3c1a0a60..755e4ad3 100644 --- a/apps/hcdc-web-app/src/features/test/components/index.ts +++ b/apps/hcdc-web-app/src/features/test/components/index.ts @@ -1 +1,2 @@ +export * from './TestSelector' export * from './TestTable' diff --git a/apps/hcdc-web-app/src/features/test/index.ts b/apps/hcdc-web-app/src/features/test/index.ts new file mode 100644 index 00000000..cb64ac1b --- /dev/null +++ b/apps/hcdc-web-app/src/features/test/index.ts @@ -0,0 +1 @@ +export * from './components' diff --git a/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/index.tsx b/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/index.tsx index da7aba47..31b18de8 100644 --- a/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/index.tsx +++ b/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/index.tsx @@ -1,4 +1,4 @@ -import { TestTable } from '../../components/TestTable' +import { TestTable } from '../../components' export default function ManageTestPage() { return ( diff --git a/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/loader.ts b/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/loader.ts index 8766a0a6..de3dc3ca 100644 --- a/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/loader.ts +++ b/apps/hcdc-web-app/src/features/test/pages/ManageTestPage/loader.ts @@ -8,27 +8,21 @@ export const manageTestPageLoader = async () => { appStore .dispatch( testCategoryApi.endpoints.testCategorySearch.initiate({ - searchTestCategoryRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, }), ) .unwrap(), appStore .dispatch( bioProductApi.endpoints.bioProductSearch.initiate({ - searchBioProductRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, }), ) .unwrap(), appStore .dispatch( printFormApi.endpoints.printFormSearch.initiate({ - searchPrintFormRequestDto: { - sort: { index: 1 }, - }, + sort: { displayIndex: 1 }, }), ) .unwrap(), diff --git a/apps/hcdc-web-app/src/features/test/pages/index.ts b/apps/hcdc-web-app/src/features/test/pages/index.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/apps/hcdc-web-app/src/infra/api/access-service/auth.ts b/apps/hcdc-web-app/src/infra/api/access-service/auth.ts index c7819899..b2855961 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/auth.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/auth.ts @@ -50,6 +50,7 @@ export type PermissionRuleRequestDto = { | 'Patient' | 'TestCombo' | 'Sample' + | 'WebApp' | 'all' action: | 'Create' @@ -62,8 +63,9 @@ export type PermissionRuleRequestDto = { | 'OverrideAuthor' | 'UpdateInfo' | 'UpdateResult' - | 'ExportReport' | 'PrintResult' + | 'ExportReport' + | 'View' | 'manage' inverted?: boolean conditions: object @@ -128,7 +130,6 @@ export type AuthLoginRequestDto = { } export type AuthMeResponseDto = { user: UserResponseDto - ability: object } export const { useAuthLoginMutation, diff --git a/apps/hcdc-web-app/src/infra/api/access-service/role.ts b/apps/hcdc-web-app/src/infra/api/access-service/role.ts index e112ab86..4fdcc556 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/role.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/role.ts @@ -85,6 +85,7 @@ export type PermissionRuleRequestDto = { | 'Patient' | 'TestCombo' | 'Sample' + | 'WebApp' | 'all' action: | 'Create' @@ -97,8 +98,9 @@ export type PermissionRuleRequestDto = { | 'OverrideAuthor' | 'UpdateInfo' | 'UpdateResult' - | 'ExportReport' | 'PrintResult' + | 'ExportReport' + | 'View' | 'manage' inverted?: boolean conditions: object diff --git a/apps/hcdc-web-app/src/infra/api/access-service/sample.ts b/apps/hcdc-web-app/src/infra/api/access-service/sample.ts index 51e0a8af..39487030 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/sample.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/sample.ts @@ -112,6 +112,7 @@ export type PermissionRuleRequestDto = { | 'Patient' | 'TestCombo' | 'Sample' + | 'WebApp' | 'all' action: | 'Create' @@ -124,8 +125,9 @@ export type PermissionRuleRequestDto = { | 'OverrideAuthor' | 'UpdateInfo' | 'UpdateResult' - | 'ExportReport' | 'PrintResult' + | 'ExportReport' + | 'View' | 'manage' inverted?: boolean conditions: object @@ -189,7 +191,7 @@ export type TestUnpopulatedResponseDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string diff --git a/apps/hcdc-web-app/src/infra/api/access-service/slice.ts b/apps/hcdc-web-app/src/infra/api/access-service/slice.ts index 9edaf14f..29b69895 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/slice.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/slice.ts @@ -1,8 +1,12 @@ -import { BaseQueryFn, createApi, fetchBaseQuery } from '@reduxjs/toolkit/query' +import { + BaseQueryFn, + createApi, + fetchBaseQuery, +} from '@reduxjs/toolkit/query/react' import { toast } from 'react-toastify' import { appConfig } from 'src/config' -// import { authSlice } from 'src/features/auth' +import { userLogout } from 'src/features/auth/state/actions' const authorizedBaseQuery = fetchBaseQuery({ baseUrl: appConfig.apiBaseUrl, @@ -19,18 +23,22 @@ const baseQueryWithErrorHandling: BaseQueryFn = async ( let result = await authorizedBaseQuery(args, api, extraOptions) if (result.error) { - const { message } = result?.data! as any + const { message } = result.error.data as any switch (result.error.status) { case 400: toast.error(`Thông tin không hợp lệ\n${message}`) + break case 401: toast.error(`Phiên đăng nhập hết hạn\n${message}`) - // api.dispatch(authSlice.actions.handleLogout()) + api.dispatch(userLogout()) + break case 403: toast.error(`Bạn không có quyền này\n${message}`) - default: + break + case 500: toast.error(`Lỗi hệ thống\n${message}`) + break } } diff --git a/apps/hcdc-web-app/src/infra/api/access-service/test-combo.ts b/apps/hcdc-web-app/src/infra/api/access-service/test-combo.ts index bbbdec66..1890b04f 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/test-combo.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/test-combo.ts @@ -85,7 +85,7 @@ export type TestUnpopulatedResponseDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string diff --git a/apps/hcdc-web-app/src/infra/api/access-service/test-element.ts b/apps/hcdc-web-app/src/infra/api/access-service/test-element.ts index 1861b920..c31531d0 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/test-element.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/test-element.ts @@ -100,7 +100,7 @@ export type TestUnpopulatedResponseDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string diff --git a/apps/hcdc-web-app/src/infra/api/access-service/test.ts b/apps/hcdc-web-app/src/infra/api/access-service/test.ts index 76facf5e..d495e553 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/test.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/test.ts @@ -119,7 +119,7 @@ export type TestResponseDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string @@ -179,7 +179,7 @@ export type TestUnpopulatedResponseDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string @@ -190,7 +190,7 @@ export type TestCreateRequestDto = { shouldDisplayWithChildren: boolean bioProductId?: string instrumentId?: string - sampleTypeId: string + sampleTypeId?: string testCategoryId: string printFormId?: string branchId: string diff --git a/apps/hcdc-web-app/src/infra/api/access-service/user.ts b/apps/hcdc-web-app/src/infra/api/access-service/user.ts index 946b5708..353342d8 100644 --- a/apps/hcdc-web-app/src/infra/api/access-service/user.ts +++ b/apps/hcdc-web-app/src/infra/api/access-service/user.ts @@ -98,6 +98,7 @@ export type PermissionRuleRequestDto = { | 'Patient' | 'TestCombo' | 'Sample' + | 'WebApp' | 'all' action: | 'Create' @@ -110,8 +111,9 @@ export type PermissionRuleRequestDto = { | 'OverrideAuthor' | 'UpdateInfo' | 'UpdateResult' - | 'ExportReport' | 'PrintResult' + | 'ExportReport' + | 'View' | 'manage' inverted?: boolean conditions: object diff --git a/apps/hcdc-web-app/src/infra/router/routes.tsx b/apps/hcdc-web-app/src/infra/router/routes.tsx index b045cc10..8a370046 100644 --- a/apps/hcdc-web-app/src/infra/router/routes.tsx +++ b/apps/hcdc-web-app/src/infra/router/routes.tsx @@ -9,7 +9,7 @@ import { CustomRouteObject } from 'src/infra/router' // import { infoInputPageLoader } from 'src/features/sample-info/pages/InfoInputPage/loader' // import { infoConfirmPageLoader } from 'src/features/sample-info/pages/InfoConfirmPage/loader' // import { editSelectPageLoader } from 'src/features/sample-result/pages/EditSelectPage/loader' -// import { manageTestPageLoader } from 'src/features/test/pages/ManageTestPage/loader' +import { manageTestPageLoader } from 'src/features/test/pages/ManageTestPage/loader' // import { manageTestElemenentPageLoader } from 'src/features/test-element/pages/ManageTestElementPage/loader' // import { printSelectPageLoader } from 'src/features/sample-result/pages/PrintSelectPage/loader' // import { testReportPageLoader } from 'src/features/report/pages/TestReportPage/loader' @@ -17,42 +17,39 @@ import { CustomRouteObject } from 'src/infra/router' //#region Lazy import pages const LoginPage = React.lazy(() => import('src/features/auth/pages/LoginPage')) -// const ManageDoctorPage = React.lazy( -// () => import('src/features/doctor/pages/ManageDoctorPage'), -// ) +const ManageDoctorPage = React.lazy( + () => import('src/features/doctor/pages/ManageDoctorPage'), +) // const ManageUserPage = React.lazy( // () => import('src/features/user/pages/ManageUserPage'), // ) -// const ManagePatientTypePage = React.lazy( -// () => import('src/features/patient-type/pages/ManagePatientTypePage'), -// ) -// const ManageTestCategoryPage = React.lazy( -// () => import('src/features/test-category/pages/ManageTestCategoryPage'), -// ) -// const ManageTestPage = React.lazy( -// () => import('src/features/test/pages/ManageTestPage'), -// ) +const ManagePatientTypePage = React.lazy( + () => import('src/features/patient-type/pages/ManagePatientTypePage'), +) +const ManageTestCategoryPage = React.lazy( + () => import('src/features/test-category/pages/ManageTestCategoryPage'), +) +const ManageTestPage = React.lazy( + () => import('src/features/test/pages/ManageTestPage'), +) // const ManageTestElementPage = React.lazy( // () => import('src/features/test-element/pages/ManageTestElementPage'), // ) -// const ManageIndicationPage = React.lazy( -// () => import('src/features/indication/pages/ManageIndicationPage'), -// ) -// const ManageSampleOriginPage = React.lazy( -// () => import('src/features/sample-origin/pages/ManageSampleOriginPage'), -// ) +const ManageDiagnosisPage = React.lazy( + () => import('src/features/diagnosis/pages/ManageDiagnosisPage'), +) const ManageBioProductPage = React.lazy( () => import('src/features/bio-product/pages/ManageBioProductPage'), ) -// const ManageSampleTypePage = React.lazy( -// () => import('src/features/sample-type/pages/ManageSampleTypePage'), -// ) -// const ManageTestComboPage = React.lazy( -// () => import('src/features/test-combo/pages/ManageTestComboPage'), -// ) -// const ManagePrintFormPage = React.lazy( -// () => import('src/features/print-form/pages/ManagePrintFormPage'), -// ) +const ManageSampleTypePage = React.lazy( + () => import('src/features/sample-type/pages/ManageSampleTypePage'), +) +const ManageTestComboPage = React.lazy( + () => import('src/features/test-combo/pages/ManageTestComboPage'), +) +const ManagePrintFormPage = React.lazy( + () => import('src/features/print-form/pages/ManagePrintFormPage'), +) // const InfoInputPage = React.lazy( // () => import('src/features/sample-info/pages/InfoInputPage'), // ) @@ -104,31 +101,27 @@ export const appRoutes: CustomRouteObject[] = [ // path: 'users', // element: , // }, - // { - // path: 'doctors', - // element: , - // }, - // { - // path: 'patient-types', - // element: , - // }, - // { - // path: 'indications', - // element: , - // }, - // { - // path: 'sample-origins', - // element: , - // }, - // { - // path: 'test-categories', - // element: , - // }, - // { - // path: 'tests', - // element: , - // loader: manageTestPageLoader, - // }, + { + path: 'doctors', + element: , + }, + { + path: 'patient-types', + element: , + }, + { + path: 'diagnoses', + element: , + }, + { + path: 'test-categories', + element: , + }, + { + path: 'tests', + element: , + loader: manageTestPageLoader, + }, // { // path: 'test-elements', // element: , @@ -138,14 +131,14 @@ export const appRoutes: CustomRouteObject[] = [ path: 'bio-products', element: , }, - // { - // path: 'sample-types', - // element: , - // }, - // { - // path: 'test-combos', - // element: , - // }, + { + path: 'sample-types', + element: , + }, + { + path: 'test-combos', + element: , + }, // { // path: 'print-forms', // element: , diff --git a/apps/hcdc-web-app/vite.config.ts b/apps/hcdc-web-app/vite.config.ts index 995ba767..cf3907f9 100644 --- a/apps/hcdc-web-app/vite.config.ts +++ b/apps/hcdc-web-app/vite.config.ts @@ -3,12 +3,13 @@ import url from 'url' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import tsconfigPaths from 'vite-tsconfig-paths' +// import basicSsl from '@vitejs/plugin-basic-ssl' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react(), tsconfigPaths()], + plugins: [react(), tsconfigPaths()], // basicSsl() resolve: { alias: [ { @@ -23,5 +24,6 @@ export default defineConfig({ }, server: { host: true, + // https: true, }, }) diff --git a/libs/hcdc/src/auth/action.ts b/libs/hcdc/src/auth/action.ts index f67f74e3..cfb8e143 100644 --- a/libs/hcdc/src/auth/action.ts +++ b/libs/hcdc/src/auth/action.ts @@ -48,4 +48,5 @@ export const AuthActionValues = [ ] export type AuthActionUnionType = - (typeof AuthAction)[AuthSubjectUnionType][number] + | (typeof AuthAction)[AuthSubjectUnionType][number] + | typeof AUTH_ACTION_ALL diff --git a/libs/hcdc/src/entity/test/entity.ts b/libs/hcdc/src/entity/test/entity.ts index 6c64cdec..249cb1cb 100644 --- a/libs/hcdc/src/entity/test/entity.ts +++ b/libs/hcdc/src/entity/test/entity.ts @@ -17,7 +17,7 @@ export type Test = BaseEntity & { instrumentId?: string instrument?: Instrument | null - sampleTypeId: string + sampleTypeId?: string sampleType?: SampleType | null testCategoryId: string diff --git a/libs/hcdc/src/entity/web-app/entity.ts b/libs/hcdc/src/entity/web-app/entity.ts index 16a51014..c72da0e1 100644 --- a/libs/hcdc/src/entity/web-app/entity.ts +++ b/libs/hcdc/src/entity/web-app/entity.ts @@ -1,6 +1,7 @@ export enum WebAppPage { SoNhanMau = 'SoNhanMau', TimKiemBenhNhan = 'TimKiemBenhNhan', + XuatBaoCao = 'XuatBaoCao', } export type WebApp = { diff --git a/libs/nestjs-infra/src/transport/http/bootstrap/cors.bootstrap.ts b/libs/nestjs-infra/src/transport/http/bootstrap/cors.bootstrap.ts index af2f6681..680fb010 100644 --- a/libs/nestjs-infra/src/transport/http/bootstrap/cors.bootstrap.ts +++ b/libs/nestjs-infra/src/transport/http/bootstrap/cors.bootstrap.ts @@ -1,11 +1,25 @@ +import { NodeEnv } from '@diut/common' import { INestApplication } from '@nestjs/common' import { BootstrapConfig } from '../../../bootstrap' -export const CorsBootstrap: BootstrapConfig = { - afterInit(ctx) { - ctx.app.enableCors({ - exposedHeaders: 'Content-Disposition', - }) - }, +export const CorsBootstrap = (config: { + originAllowList: string[] + devOriginAllowList: string[] +}): BootstrapConfig => { + return { + afterInit(ctx) { + const corsOriginAllowList = config.originAllowList + + if (ctx.nodeEnv === NodeEnv.Development) { + corsOriginAllowList.push(...config.devOriginAllowList) + } + + ctx.app.enableCors({ + exposedHeaders: 'Content-Disposition', + credentials: true, + origin: corsOriginAllowList, + }) + }, + } } diff --git a/libs/nestjs-infra/src/transport/http/dtos/paginated-response.ts b/libs/nestjs-infra/src/transport/http/dtos/paginated-response.ts index e009f891..b80d2d43 100644 --- a/libs/nestjs-infra/src/transport/http/dtos/paginated-response.ts +++ b/libs/nestjs-infra/src/transport/http/dtos/paginated-response.ts @@ -1,5 +1,6 @@ import { ApiProperty } from '@nestjs/swagger' import { ClassConstructor, Expose, Type } from 'class-transformer' +import { IsNumber, ValidateNested } from 'class-validator' export function PaginatedResponse>( ItemClass: ItemType, @@ -7,14 +8,17 @@ export function PaginatedResponse>( class PaginationDtoClass { @Expose() @ApiProperty() + @IsNumber() total: number @Expose() @ApiProperty() + @IsNumber() offset: number @Expose() @ApiProperty() + @IsNumber() limit: number @Expose() @@ -23,6 +27,7 @@ export function PaginatedResponse>( isArray: true, }) @Type(() => ItemClass) + @ValidateNested({ each: true }) items: (typeof ItemClass)[] } diff --git a/libs/nestjs-infra/src/transport/http/dtos/search-request.ts b/libs/nestjs-infra/src/transport/http/dtos/search-request.ts index 68bd79c4..be17d753 100644 --- a/libs/nestjs-infra/src/transport/http/dtos/search-request.ts +++ b/libs/nestjs-infra/src/transport/http/dtos/search-request.ts @@ -17,6 +17,7 @@ import { Type } from 'class-transformer' class PopulateOptionDto { @ApiProperty({ example: 'results.elements.testElementId', + type: 'string', }) @IsString() path: PopulatePath diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a24b7b7..59bb0fde 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -284,6 +284,9 @@ importers: '@reduxjs/toolkit': specifier: ^2.2.1 version: 2.2.1(react-redux@9.1.0)(react@18.2.0) + '@vitejs/plugin-basic-ssl': + specifier: ^1.1.0 + version: 1.1.0(vite@4.5.2) '@vitejs/plugin-react': specifier: ^4.2.1 version: 4.2.1(vite@4.5.2) @@ -4170,6 +4173,15 @@ packages: '@ucast/core': 1.10.2 dev: false + /@vitejs/plugin-basic-ssl@1.1.0(vite@4.5.2): + resolution: {integrity: sha512-wO4Dk/rm8u7RNhOf95ZzcEmC9rYOncYgvq4z3duaJrCgjN8BxAnDVyndanfcJZ0O6XZzHz6Q0hTimxTg8Y9g/A==} + engines: {node: '>=14.6.0'} + peerDependencies: + vite: ^3.0.0 || ^4.0.0 || ^5.0.0 + dependencies: + vite: 4.5.2 + dev: false + /@vitejs/plugin-react@4.2.1(vite@4.5.2): resolution: {integrity: sha512-oojO9IDc4nCUUi8qIR11KoQm0XFFLIwsRBwHRR4d/88IWghn1y6ckz/bJ8GHDCsYEJee8mDzqtJxh15/cisJNQ==} engines: {node: ^14.18.0 || >=16.0.0}