EventsProvider.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import BaseProvider from '~/services/data/BaseProvider'
  2. import Address from "~/components/Ui/Search/Address.vue";
  3. class PublicEventsProvider extends BaseProvider {
  4. protected normalize (e: any) : PublicEvent {
  5. e.address = {
  6. type: '',
  7. latitude: e.latitude,
  8. longitude: e.longitude,
  9. streetAddress: e.streetAddress,
  10. postalCode: e.postalCode,
  11. addressCity: e.addressCity,
  12. country: ''
  13. } as Address
  14. // s.categories = s.categories.split()
  15. return e
  16. }
  17. async getBy (
  18. name: string | null = null,
  19. organizationId: number | null = null,
  20. dateMin: string | null = null,
  21. dateMax: string | null = null,
  22. city: string | null = null
  23. ): Promise<Array<PublicEvent>> {
  24. const query = new URLSearchParams();
  25. if (name !== null) {
  26. query.append('name', name)
  27. }
  28. if (organizationId !== null) {
  29. query.append('organizationId', String(organizationId))
  30. }
  31. if (dateMin !== null) {
  32. query.append('dateStart[after]', dateMin)
  33. }
  34. if (dateMax !== null) {
  35. query.append('dateEnd[before]', dateMax)
  36. }
  37. if (city !== null) {
  38. query.append('city', city)
  39. }
  40. let url = `/api/public/events`
  41. if (query) {
  42. url += `?{query}`
  43. }
  44. return await this.get(url).then((res) => {
  45. console.log(res)
  46. return res['hydra:member'].map((s: any) => { return this.normalize(s) })
  47. })
  48. }
  49. async getById (eventUuid: number): Promise<PublicEvent> {
  50. return await this.get(
  51. `/api/public/events/${eventUuid}`
  52. ).then((s) => {
  53. return this.normalize(s)
  54. })
  55. }
  56. }
  57. export default PublicEventsProvider