Loading web/src/data/datasources/prod/place_datasource.ts +50 −31 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ import axios from "axios"; import { APIUrl } from "../../../constants/api_url"; import { PlaceDatasourceInf } from "../../../infraestructure/datasources/place_datasource"; import { AvailableDays, Place } from "../../../infraestructure/entities/place"; import { PlaceModel } from "../../models/prod/PlaceModel"; import { PlaceModel, placeModelToEntity } from "../../models/prod/PlaceModel"; export class PlaceDatasourceProd implements PlaceDatasourceInf{ async registerPlace(form: Place): Promise<void> { Loading @@ -10,7 +10,7 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); formToSend.append('name', form.name); formToSend.append('categoriesId', form.categoriesId); formToSend.append('categoriesId', form.categoriesId as string | ''); formToSend.append('descriptionES', form.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', form.descriptions?.[1] ?? ''); formToSend.append('image', form.imagesList?.[0] ?? ''); Loading @@ -37,37 +37,56 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ lang: 'ES' } }); const places = data.map((value) => { let availableDays = AvailableDays.WEEKEND; switch(value.available){ case AvailableDays.ALL_DAYS: availableDays = AvailableDays.ALL_DAYS; break; case AvailableDays.CUSTOM: availableDays = AvailableDays.CUSTOM; break; case AvailableDays.WEEKDAYS: availableDays = AvailableDays.WEEKDAYS; break; default: availableDays = AvailableDays.WEEKEND; break; const places = data.map((dataES) => { return placeModelToEntity(dataES); }) return places; } async getPlaceById(idPlace: number): Promise<Place> { const {data: dataES} = await axios.get<PlaceModel>(APIUrl+`/place/${idPlace}`, { params: { lang: 'ES' } }); const place: Place = { idTown : value.idTown, idPlace : value.idPlace, available : availableDays, latitude: value.latitude, longitude: value.longitude, name: value.name, categoriesId: value.categoriesId, openAt: value.openAt, closeAt: value.closeAt const {data: dataEN} = await axios.get<PlaceModel>(APIUrl+`/place/${idPlace}`, { params: { lang: 'EN' } }); const place: Place = placeModelToEntity(dataES); place.descriptions?.push(dataEN.description); return place; }) } return places; async updatePlace(place: Place): Promise<void> { const formToSend = new FormData(); formToSend.append('available', place.available); formToSend.append('idTown', String(place.idTown)); formToSend.append('name', place.name); formToSend.append('categoriesId', place.categoriesId as string | ''); formToSend.append('descriptionES', place.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', place.descriptions?.[1] ?? ''); formToSend.append('image', place.imagesList?.[0] ?? ''); formToSend.append('latitude', String(place.latitude)); formToSend.append('longitude', String(place.longitude)); formToSend.append('openAt', String(place.openAt)); formToSend.append('closeAt', String(place.closeAt)); if(place.available === AvailableDays.CUSTOM){ formToSend.append('startDate', String(place.startDate)); formToSend.append('endDate', String(place.endDate)); } const headers = { 'Content-Type': 'multipart/form-data' }; await axios.patch(APIUrl+`/place/${place.idPlace}`, formToSend,{headers}); } } No newline at end of file web/src/data/repositories/prod/place_repository.ts +8 −0 Original line number Diff line number Diff line Loading @@ -13,4 +13,12 @@ export class PlaceRepositoryProd implements PlaceRepositoryInf{ async getPlacesByTown(idTown: number): Promise<Place[]> { return this.datasouce.getPlacesByTown(idTown); } async getPlaceById(idPlace: number): Promise<Place> { return this.datasouce.getPlaceById(idPlace); } async updatePlace(place: Place): Promise<void> { return this.datasouce.updatePlace(place); } } No newline at end of file web/src/infraestructure/datasources/place_datasource.ts +2 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceDatasourceInf{ registerPlace(form: Place): Promise<void>; getPlacesByTown(idTown: number): Promise<Place[]>; getPlaceById(idPlace: number): Promise<Place>; updatePlace(place: Place): Promise<void>; } No newline at end of file web/src/infraestructure/repositories/place_repository.ts +2 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceRepositoryInf{ registerPlace(form: Place): Promise<void>; getPlacesByTown(idTown: number): Promise<Place[]>; getPlaceById(idPlace: number): Promise<Place>; updatePlace(place: Place): Promise<void>; } No newline at end of file Loading
web/src/data/datasources/prod/place_datasource.ts +50 −31 Original line number Diff line number Diff line Loading @@ -2,7 +2,7 @@ import axios from "axios"; import { APIUrl } from "../../../constants/api_url"; import { PlaceDatasourceInf } from "../../../infraestructure/datasources/place_datasource"; import { AvailableDays, Place } from "../../../infraestructure/entities/place"; import { PlaceModel } from "../../models/prod/PlaceModel"; import { PlaceModel, placeModelToEntity } from "../../models/prod/PlaceModel"; export class PlaceDatasourceProd implements PlaceDatasourceInf{ async registerPlace(form: Place): Promise<void> { Loading @@ -10,7 +10,7 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); formToSend.append('name', form.name); formToSend.append('categoriesId', form.categoriesId); formToSend.append('categoriesId', form.categoriesId as string | ''); formToSend.append('descriptionES', form.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', form.descriptions?.[1] ?? ''); formToSend.append('image', form.imagesList?.[0] ?? ''); Loading @@ -37,37 +37,56 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ lang: 'ES' } }); const places = data.map((value) => { let availableDays = AvailableDays.WEEKEND; switch(value.available){ case AvailableDays.ALL_DAYS: availableDays = AvailableDays.ALL_DAYS; break; case AvailableDays.CUSTOM: availableDays = AvailableDays.CUSTOM; break; case AvailableDays.WEEKDAYS: availableDays = AvailableDays.WEEKDAYS; break; default: availableDays = AvailableDays.WEEKEND; break; const places = data.map((dataES) => { return placeModelToEntity(dataES); }) return places; } async getPlaceById(idPlace: number): Promise<Place> { const {data: dataES} = await axios.get<PlaceModel>(APIUrl+`/place/${idPlace}`, { params: { lang: 'ES' } }); const place: Place = { idTown : value.idTown, idPlace : value.idPlace, available : availableDays, latitude: value.latitude, longitude: value.longitude, name: value.name, categoriesId: value.categoriesId, openAt: value.openAt, closeAt: value.closeAt const {data: dataEN} = await axios.get<PlaceModel>(APIUrl+`/place/${idPlace}`, { params: { lang: 'EN' } }); const place: Place = placeModelToEntity(dataES); place.descriptions?.push(dataEN.description); return place; }) } return places; async updatePlace(place: Place): Promise<void> { const formToSend = new FormData(); formToSend.append('available', place.available); formToSend.append('idTown', String(place.idTown)); formToSend.append('name', place.name); formToSend.append('categoriesId', place.categoriesId as string | ''); formToSend.append('descriptionES', place.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', place.descriptions?.[1] ?? ''); formToSend.append('image', place.imagesList?.[0] ?? ''); formToSend.append('latitude', String(place.latitude)); formToSend.append('longitude', String(place.longitude)); formToSend.append('openAt', String(place.openAt)); formToSend.append('closeAt', String(place.closeAt)); if(place.available === AvailableDays.CUSTOM){ formToSend.append('startDate', String(place.startDate)); formToSend.append('endDate', String(place.endDate)); } const headers = { 'Content-Type': 'multipart/form-data' }; await axios.patch(APIUrl+`/place/${place.idPlace}`, formToSend,{headers}); } } No newline at end of file
web/src/data/repositories/prod/place_repository.ts +8 −0 Original line number Diff line number Diff line Loading @@ -13,4 +13,12 @@ export class PlaceRepositoryProd implements PlaceRepositoryInf{ async getPlacesByTown(idTown: number): Promise<Place[]> { return this.datasouce.getPlacesByTown(idTown); } async getPlaceById(idPlace: number): Promise<Place> { return this.datasouce.getPlaceById(idPlace); } async updatePlace(place: Place): Promise<void> { return this.datasouce.updatePlace(place); } } No newline at end of file
web/src/infraestructure/datasources/place_datasource.ts +2 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceDatasourceInf{ registerPlace(form: Place): Promise<void>; getPlacesByTown(idTown: number): Promise<Place[]>; getPlaceById(idPlace: number): Promise<Place>; updatePlace(place: Place): Promise<void>; } No newline at end of file
web/src/infraestructure/repositories/place_repository.ts +2 −0 Original line number Diff line number Diff line Loading @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceRepositoryInf{ registerPlace(form: Place): Promise<void>; getPlacesByTown(idTown: number): Promise<Place[]>; getPlaceById(idPlace: number): Promise<Place>; updatePlace(place: Place): Promise<void>; } No newline at end of file