feat : Ajout d'un onglet Observation sur la page employé + fonctionnalité de verrouillage utilisateur
This commit is contained in:
6
frontend/services/dto/observation.ts
Normal file
6
frontend/services/dto/observation.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export type Observation = {
|
||||
id: number
|
||||
month: string
|
||||
content: string
|
||||
createdAt: string
|
||||
}
|
||||
@@ -4,5 +4,6 @@ export type User = {
|
||||
id: number
|
||||
username: string
|
||||
roles: string[]
|
||||
isLocked: boolean
|
||||
employee?: Employee | null
|
||||
}
|
||||
|
||||
50
frontend/services/observations.ts
Normal file
50
frontend/services/observations.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { Observation } from './dto/observation'
|
||||
import { extractItems } from '~/utils/api'
|
||||
|
||||
export const listObservations = async (employeeId: number) => {
|
||||
const api = useApi()
|
||||
const data = await api.get<Observation[] | { 'hydra:member'?: Observation[] }>(
|
||||
'/observations',
|
||||
{ employee: `/api/employees/${employeeId}` },
|
||||
{ toast: false }
|
||||
)
|
||||
return extractItems<Observation>(data)
|
||||
}
|
||||
|
||||
export const createObservation = async (data: {
|
||||
employeeId: number
|
||||
month: string
|
||||
content: string
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.post<Observation>('/observations', {
|
||||
employee: `/api/employees/${data.employeeId}`,
|
||||
month: data.month,
|
||||
content: data.content
|
||||
}, {
|
||||
toastSuccessKey: 'success.observation.create',
|
||||
toastErrorKey: 'errors.observation.create'
|
||||
})
|
||||
}
|
||||
|
||||
export const updateObservation = async (id: number, data: {
|
||||
month: string
|
||||
content: string
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.patch<Observation>(`/observations/${id}`, {
|
||||
month: data.month,
|
||||
content: data.content
|
||||
}, {
|
||||
toastSuccessKey: 'success.observation.update',
|
||||
toastErrorKey: 'errors.observation.update'
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteObservation = async (id: number) => {
|
||||
const api = useApi()
|
||||
return api.delete(`/observations/${id}`, {}, {
|
||||
toastSuccessKey: 'success.observation.delete',
|
||||
toastErrorKey: 'errors.observation.delete'
|
||||
})
|
||||
}
|
||||
@@ -16,6 +16,7 @@ export const createUser = async (payload: {
|
||||
plainPassword: string
|
||||
roles: string[]
|
||||
employeeId?: number | null
|
||||
isLocked?: boolean
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.post<User>(
|
||||
@@ -24,7 +25,8 @@ export const createUser = async (payload: {
|
||||
username: payload.username,
|
||||
plainPassword: payload.plainPassword,
|
||||
roles: payload.roles,
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null,
|
||||
isLocked: payload.isLocked ?? false
|
||||
},
|
||||
{
|
||||
toastSuccessKey: 'success.user.create',
|
||||
@@ -38,12 +40,14 @@ export const updateUser = async (id: number, payload: {
|
||||
plainPassword?: string
|
||||
roles: string[]
|
||||
employeeId?: number | null
|
||||
isLocked?: boolean
|
||||
}) => {
|
||||
const api = useApi()
|
||||
const body: Record<string, unknown> = {
|
||||
username: payload.username,
|
||||
roles: payload.roles,
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null,
|
||||
isLocked: payload.isLocked ?? false
|
||||
}
|
||||
|
||||
if (payload.plainPassword) {
|
||||
|
||||
Reference in New Issue
Block a user