| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import BaseProvider from '~/services/data/BaseProvider'
- import Address from "~/components/Ui/Search/Address.vue";
- import HydraParser from "~/services/data/HydraParser";
- const LOCATION_RADIUS = 20
- class PublicEventsProvider extends BaseProvider {
- protected normalize (e: any) : PublicEvent {
- e.address = {
- type: '',
- latitude: e.latitude,
- longitude: e.longitude,
- streetAddress: e.streetAddress,
- postalCode: e.postalCode,
- addressCity: e.city,
- country: ''
- } as Address
- delete e['@id']
- delete e['@type']
- delete e.latitude
- delete e.longitude
- delete e.streetAddress
- delete e.postalCode
- delete e.city
- return e
- }
- async getBy (
- name: string | null = null,
- organizationId: number | null = null,
- dateMin: string | null = null,
- dateMax: string | null = null,
- location: Coordinates | null = null,
- page: number = 1,
- itemsPerPage = 20
- ): Promise<HydraCollection<PublicEvent>> {
- const query = new URLSearchParams();
- if (name !== null) {
- query.append('name', name)
- }
- if (organizationId !== null) {
- query.append('organizationId', String(organizationId))
- }
- if (dateMin !== null && dateMin !== '') {
- query.append('datetimeEnd[after]', dateMin)
- }
- if (dateMax !== null && dateMax !== '') {
- query.append('datetimeEnd[before]', dateMax)
- }
- if (location !== null) {
- query.append('withinDistance', [location.latitude, location.longitude, LOCATION_RADIUS].join(','))
- }
- if (page !== null) {
- query.append('page', `${page}`)
- }
- if (itemsPerPage !== null) {
- query.append('itemsPerPage', `${itemsPerPage}`)
- }
- query.append('order[datetimeEnd]', 'asc')
- let url = `/api/public/events`
- if (query) {
- url += `?${query}`
- }
- return await this.get(url).then((res) => {
- return HydraParser.parseCollection(res, this.normalize)
- })
- }
- async getById (eventUuid: string): Promise<PublicEvent> {
- return await this.get(
- `/api/public/events/${eventUuid}`
- ).then((s) => {
- return this.normalize(s)
- })
- }
- }
- export default PublicEventsProvider
|