forked from rexxars/vinmonopolet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed getAllStores to use vinmonopolet api. Removed stream api.
- Loading branch information
1 parent
59857ff
commit 7409a98
Showing
10 changed files
with
213 additions
and
287 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,76 @@ | ||
import PopulatedStore from "../models/Store"; | ||
import PopulatedStore, { IOpeningHours } from "../models/Store"; | ||
import request from "../util/request"; | ||
|
||
interface IOpeningTime { | ||
closingTime: { | ||
formattedHour: string; | ||
hour: number; | ||
minute: number; | ||
}; | ||
openingTime: { | ||
formattedHour: string; | ||
hour: number; | ||
minute: number; | ||
}; | ||
weekDay: string; | ||
closed: false; | ||
formattedDate: string; | ||
readableValue: string; | ||
} | ||
|
||
interface IGetStoreDTO { | ||
address: { | ||
defaultAddress: boolean; | ||
formattedAddress: string; | ||
line1: string; | ||
line2: string; | ||
phone: string; | ||
postalCode: string; | ||
town: string; | ||
}; | ||
assortment: string; | ||
clickAndCollect: boolean; | ||
displayName: string; | ||
geoPoint: { | ||
latitude: number; | ||
longitude: number; | ||
}; | ||
name: string; | ||
openingTimes: IOpeningTime[]; | ||
} | ||
|
||
const getStore = async (store_id: string): Promise<PopulatedStore> => { | ||
const res = await request.get(`/vmpws/v2/vmp/stores/${store_id}`, { | ||
baseUrl: "https://www.vinmonopolet.no", | ||
query: { fields: "FULL" }, | ||
}); | ||
const res = await request.get<IGetStoreDTO>( | ||
`/vmpws/v2/vmp/stores/${store_id}`, | ||
{ | ||
baseUrl: "https://www.vinmonopolet.no", | ||
query: { fields: "FULL" }, | ||
} | ||
); | ||
|
||
return new PopulatedStore(res); | ||
return toPopulatedStore(res); | ||
}; | ||
|
||
function toPopulatedStore(storeDTO: IGetStoreDTO): PopulatedStore { | ||
return new PopulatedStore( | ||
storeDTO.name, | ||
storeDTO.displayName, | ||
storeDTO.address.line1, | ||
storeDTO.address.postalCode, | ||
storeDTO.address.town, | ||
storeDTO.geoPoint.latitude, | ||
storeDTO.geoPoint.longitude, | ||
storeDTO.assortment, | ||
storeDTO.openingTimes.map(toOpeningHours) | ||
); | ||
} | ||
|
||
function toOpeningHours(openingTimeDTO: IOpeningTime): IOpeningHours { | ||
return { | ||
closes: openingTimeDTO.closingTime, | ||
opens: openingTimeDTO.openingTime, | ||
weekDay: openingTimeDTO.weekDay, | ||
}; | ||
} | ||
|
||
export default getStore; |
Oops, something went wrong.