useEntityManager.ts 798 B

12345678910111213141516171819202122232425262728
  1. import { useRepo } from 'pinia-orm'
  2. import EntityManager from '~/services/data/entityManager'
  3. import { useAp2iRequestService } from '~/composables/data/useAp2iRequestService'
  4. import { useAccessProfileStore } from '~/stores/accessProfile'
  5. let entityManager: EntityManager | null = null
  6. export const useEntityManager = () => {
  7. if (entityManager === null) {
  8. const { apiRequestService } = useAp2iRequestService()
  9. const getRepo = useRepo
  10. const profileStore = useAccessProfileStore()
  11. const getProfileMask = () => {
  12. return {
  13. activityYear: profileStore.activityYear,
  14. historical: profileStore.historical,
  15. }
  16. }
  17. entityManager = new EntityManager(
  18. apiRequestService,
  19. getRepo,
  20. getProfileMask,
  21. )
  22. }
  23. return { em: entityManager }
  24. }