Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Mar 8, 2024
1 parent 9f467b7 commit 4ced8d8
Show file tree
Hide file tree
Showing 20 changed files with 1,252 additions and 1,106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ export class AuthPopulateContextUseCase {
) {}

async execute(input: AuthPayload): Promise<AuthContextData> {
const { user, ability } = await this.createUserAbility(input.userId)

return { user, ability }
}

async createUserAbility(userId: string) {
const user = await this.userRepository.findOne({
filter: { _id: input.userId },
filter: { _id: userId },
populates: [
{ path: 'roles', fields: ['permissions'] satisfies (keyof Role)[] },
],
Expand Down
1 change: 1 addition & 0 deletions apps/hcdc-access-service/src/domain/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function authorizePopulates<TEntity extends BaseEntity>(
for (const populate of populates) {
const { subject, action } = authMapping(populate.path)
const authMatchObj = accessibleBy(ability, action)[subject]

if (populate.match) {
let matchObject: FilterQuery<TEntity>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { OutlinedInputProps } from '@mui/material'
import { Control, Path, FieldValues } from 'react-hook-form'

import { FormDateTimePicker } from '../FormDateTimePicker'

export type FormDateRangePickerProps<T extends FieldValues = FieldValues> =
Omit<OutlinedInputProps, 'name'> & {
fromDateName: Path<T>
toDateName: Path<T>
label: string
control: Control<T>
disableError?: boolean
}

export function FormDateRangePicker<
TFieldValues extends FieldValues = FieldValues,
>({
fromDateName,
toDateName,
control,
disableError = false,
...outlinedInputProps
}: FormDateRangePickerProps<TFieldValues>) {
const fromDate = control._getWatch(fromDateName) as Date
const toDate = control._getWatch(fromDateName) as Date

return (
<>
<FormDateTimePicker
{...outlinedInputProps}
sx={[
{
mr: 2,
},
...(Array.isArray(outlinedInputProps.sx)
? outlinedInputProps.sx
: [outlinedInputProps.sx]),
]}
control={control}
name={fromDateName}
dateOnly
label="Từ ngày"
disableError={disableError}
/>
<FormDateTimePicker
{...outlinedInputProps}
control={control}
name={fromDateName}
dateOnly
label="Đến ngày"
disableError={disableError}
/>
</>
)
}
Empty file.
Loading

0 comments on commit 4ced8d8

Please sign in to comment.