| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { useRepo } from 'pinia-orm'
- import EntityManager from '~/services/data/entityManager'
- import { useAp2iRequestService } from '~/composables/data/useAp2iRequestService'
- import { useAccessProfileStore } from '~/stores/accessProfile'
- import type ApiResource from '~/models/ApiResource'
- import type { AsyncData } from '#app'
- let entityManager: EntityManager | null = null
- interface _useEntityManagerReturnType {
- fetch: <T extends typeof ApiResource>(
- model: T,
- id?: number | null,
- ) => AsyncData<InstanceType<T> | null, Error | null>
- }
- export const useEntityManager = () => {
- if (entityManager === null) {
- const { apiRequestService } = useAp2iRequestService()
- const getRepo = useRepo
- const profileStore = useAccessProfileStore()
- const getProfileMask = () => {
- return {
- activityYear: profileStore.activityYear,
- historical: profileStore.historical,
- }
- }
- entityManager = new EntityManager(
- apiRequestService,
- getRepo,
- getProfileMask,
- )
- }
- return { em: entityManager }
- }
|