import bikePointsData from '../../shared/data/bike-point-data.json' import { IBikePoint } from '@entities/BikePoint' const bikePoints = bikePointsData as IBikePoint[] export interface IBikePointDao { getById: (bikePointId: string) => Promise getAll: (bikePointId: string) => Promise } class BikePointDao implements IBikePointDao { /** * @param bikePointId (without Prefix 'BikePoints_', only the numbers behind) */ public getById(bikePointId: string): Promise { return Promise.resolve(getBikePointById(bikePoints, bikePointId)) } public getAll(): Promise { return Promise.resolve(bikePoints.map(bikePoint => removeBikePointIdPrefix(bikePoint))) } } export const getBikePointById = (bikePoints: IBikePoint[], bikePointId: string) => { for (const bikePoint of bikePoints) { if (bikePoint.id.replace('BikePoints_', '') === bikePointId) { return removeBikePointIdPrefix(bikePoint) } } return null } const removeBikePointIdPrefix = (bikePoint: IBikePoint) => ({...bikePoint, id: bikePoint.id.replace('BikePoints_', '')}) export default BikePointDao