Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Feb 26, 2024
1 parent 6728d5a commit 9d9dc56
Show file tree
Hide file tree
Showing 82 changed files with 468 additions and 547 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
2 changes: 1 addition & 1 deletion apps/hcdc-access-service/src/domain/entity/test/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const exampleTest = {
required: false,
nullable: true,
},
sampleTypeId: exampleMongoObjectId,
sampleTypeId: { ...exampleMongoObjectId, required: false },
sampleType: {
required: false,
nullable: true,
Expand Down
4 changes: 2 additions & 2 deletions apps/hcdc-access-service/src/infra/mongo/test/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
5 changes: 4 additions & 1 deletion apps/hcdc-access-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ bootstrapApp(
},
[
LogBootstrap,
CorsBootstrap,
CorsBootstrap({
devOriginAllowList: ['http://localhost:5173'],
originAllowList: ['http://lab.hcdc.vn:8000'],
}),
LifecycleBootstrap,
PipeBootstrap,
PrefixBootstrap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export class TestCreateRequestDto {

@Expose()
@ApiProperty(exampleTest.sampleTypeId)
@IsOptional()
@IsObjectId()
sampleTypeId: string
sampleTypeId?: string

@Expose()
@ApiProperty(exampleTest.testCategoryId)
Expand Down
1 change: 1 addition & 0 deletions apps/hcdc-web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions apps/hcdc-web-app/src/components/layout/AppBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +41,7 @@ export function AppBar({ drawerWidth }: AppBarProps) {

const handleLogout = () => {
handleClose()
dispatch(authSlice.actions.handleLogout())
dispatch(userLogout())
}

const handleChangePassword = () => {
Expand All @@ -56,7 +57,7 @@ export function AppBar({ drawerWidth }: AppBarProps) {
>
<Toolbar variant="dense">
<Typography variant="h6" noWrap component="div" sx={{ flexGrow: 1 }}>
Xin chào, {name}
{name}
</Typography>
<div>
<IconButton
Expand Down
54 changes: 47 additions & 7 deletions apps/hcdc-web-app/src/components/layout/AppDrawer/drawer-items.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AUTH_ACTION_ALL,
AuthSubject,
SampleAction,
WebApp,
Expand All @@ -24,7 +25,6 @@ import ListAltIcon from '@mui/icons-material/ListAlt'
import RuleIcon from '@mui/icons-material/Rule'
import PersonSearchIcon from '@mui/icons-material/PersonSearch'
import FileDownloadIcon from '@mui/icons-material/FileDownload'
import MapsHomeWorkIcon from '@mui/icons-material/MapsHomeWork'

import { DrawerItemGroup, authOneOf } from './utils'

Expand All @@ -37,6 +37,11 @@ export const drawerItems: DrawerItemGroup[] = [
label: 'Trang chủ',
destination: '/',
},
],
},
{
title: '',
children: [
{
icon: <AirlineSeatReclineNormalIcon />,
label: 'Nhập TT',
Expand Down Expand Up @@ -97,6 +102,13 @@ export const drawerItems: DrawerItemGroup[] = [
icon: <FileDownloadIcon />,
label: 'Xuất báo cáo',
destination: 'report/export',
isAuthorized: authOneOf([
{
subject: AuthSubject.WebApp,
action: WebAppAction.View,
filterObj: { page: WebAppPage.XuatBaoCao } as WebApp,
},
]),
},
],
},
Expand All @@ -107,61 +119,89 @@ export const drawerItems: DrawerItemGroup[] = [
icon: <ManageAccountsIcon />,
label: 'Người dùng',
destination: 'manage/users',
},
{
icon: <MapsHomeWorkIcon />,
label: 'Đơn vị',
destination: 'manage/sample-origins',
isAuthorized: authOneOf([
{ subject: AuthSubject.User, action: AUTH_ACTION_ALL },
]),
},
{
icon: <AccountBoxIcon />,
label: 'Bác sĩ',
destination: 'manage/doctors',
isAuthorized: authOneOf([
{ subject: AuthSubject.Doctor, action: AUTH_ACTION_ALL },
]),
},
{
icon: <WorkIcon />,
label: 'Đối tượng',
destination: 'manage/patient-types',
isAuthorized: authOneOf([
{ subject: AuthSubject.PatientType, action: AUTH_ACTION_ALL },
]),
},
{
icon: <MedicalInformationIcon />,
label: 'Chẩn đoán',
destination: 'manage/indications',
destination: 'manage/diagnoses',
isAuthorized: authOneOf([
{ subject: AuthSubject.Diagnosis, action: AUTH_ACTION_ALL },
]),
},
{
icon: <CoronavirusIcon />,
label: 'Sinh phẩm',
destination: 'manage/bio-products',
isAuthorized: authOneOf([
{ subject: AuthSubject.BioProduct, action: AUTH_ACTION_ALL },
]),
},
{
icon: <VaccinesIcon />,
label: 'Loại mẫu',
destination: 'manage/sample-types',
isAuthorized: authOneOf([
{ subject: AuthSubject.SampleType, action: AUTH_ACTION_ALL },
]),
},
{
icon: <WorkspacesIcon />,
label: 'Nhóm XN',
destination: 'manage/test-categories',
isAuthorized: authOneOf([
{ subject: AuthSubject.TestCategory, action: AUTH_ACTION_ALL },
]),
},
{
icon: <BiotechIcon />,
label: 'Tên XN',
destination: 'manage/tests',
isAuthorized: authOneOf([
{ subject: AuthSubject.Test, action: AUTH_ACTION_ALL },
]),
},
{
icon: <BloodtypeIcon />,
label: 'Thành phần XN',
destination: 'manage/test-elements',
isAuthorized: authOneOf([
{ subject: AuthSubject.TestElement, action: AUTH_ACTION_ALL },
]),
},
{
icon: <Diversity2Icon />,
label: 'Bộ xét nghiệm',
destination: 'manage/test-combos',
isAuthorized: authOneOf([
{ subject: AuthSubject.TestCombo, action: AUTH_ACTION_ALL },
]),
},
{
icon: <ListAltIcon />,
label: 'Form In',
destination: 'manage/print-forms',
isAuthorized: authOneOf([
{ subject: AuthSubject.PrintForm, action: AUTH_ACTION_ALL },
]),
},
],
},
Expand Down
24 changes: 2 additions & 22 deletions apps/hcdc-web-app/src/components/layout/AppDrawer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
Box,
Divider,
Drawer,
List,
Expand All @@ -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 }) {
Expand All @@ -39,24 +37,6 @@ export function AppDrawer({ drawerWidth }: { drawerWidth: number }) {
},
}}
>
<Box
sx={{
position: 'sticky',
backgroundColor: 'background.paper',
zIndex: 'appBar',
top: 0,
left: 0,
}}
>
<img
src={fullLogo}
width={`${drawerWidth}px`}
style={{
padding: '4px',
}}
/>
<Divider sx={{ mt: 1, borderColor: 'primary.main' }} />
</Box>
<List
sx={{
'&& .Mui-selected, && .Mui-selected:hover': {
Expand All @@ -75,8 +55,8 @@ export function AppDrawer({ drawerWidth }: { drawerWidth: number }) {
}}
>
{drawerItems.map((group, groupIndex) => (
<Fragment key={group.title}>
{groupIndex > 0 && <Divider sx={{ my: 1 }} />}
<Fragment key={groupIndex}>
{groupIndex > 0 && <Divider />}
<ListSubheader disableSticky component="div" inset>
{group.title}
</ListSubheader>
Expand Down
2 changes: 1 addition & 1 deletion apps/hcdc-web-app/src/features/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './components'
export * from './state'
export * from './components'
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -68,10 +70,10 @@ export function LoginForm({ reason }: LoginPageProps) {
alignItems: 'center',
}}
>
<img
{/* <img
src={fullLogo}
style={{ maxWidth: '50%', marginTop: '24px', marginBottom: '24px' }}
/>
/> */}
<FormContainer
onSubmit={handleSubmit(handleLogin)}
sx={{ maxWidth: '350px' }}
Expand Down
6 changes: 6 additions & 0 deletions apps/hcdc-web-app/src/features/auth/state/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createAction } from '@reduxjs/toolkit'

export const USER_LOGOUT = 'USER_LOGOUT'
export const userLogout = createAction(USER_LOGOUT, () => {
return { payload: null }
})
2 changes: 1 addition & 1 deletion apps/hcdc-web-app/src/features/auth/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './slice'
export * from './types'
export * from './slice'
10 changes: 5 additions & 5 deletions apps/hcdc-web-app/src/features/auth/state/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
AuthStateAuthenticated,
AuthStateUnauthenticated,
} from './types'
import { userLogout } from './actions'

export const authSlice = createSlice({
name: 'auth',
Expand All @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -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<IndicationResponseDto>[] = [
export const diagnosisColumns: GridColDef<DiagnosisResponseDto>[] = [
{
field: 'index',
field: 'displayIndex',
headerName: 'Thứ tự',
type: 'number',
minWidth: 100,
Expand Down
Loading

0 comments on commit 9d9dc56

Please sign in to comment.