@@ -18,7 +18,7 @@ npm install
1818npm start
1919```
2020
21- - Update ` getHotelCollection ` api method:
21+ ## Update ` getHotelCollection ` API method
2222
2323### Fetch version
2424
@@ -50,7 +50,7 @@ export const getHotelCollection = async (): Promise<HotelEntityApi[]> => {
5050_ ./src/pods/hotel-collection/api/hotel-collection.api.ts_
5151
5252``` diff
53- + import Axios from 'axios';
53+ + import axios from 'axios';
5454import { HotelEntityApi } from './hotel-collection.api-model';
5555import { mockHotelCollection } from './hotel-collection.mock-data';
5656
@@ -59,18 +59,15 @@ let hotelCollection = [...mockHotelCollection];
5959
6060export const getHotelCollection = async (): Promise<HotelEntityApi[]> => {
6161- return hotelCollection;
62- + const { data } = await Axios .get<HotelEntityApi[]>(url);
62+ + const { data } = await axios .get<HotelEntityApi[]>(url);
6363+ return data;
6464};
6565
6666...
6767
6868```
6969
70- - Update ` deleteHotel ` api method:
71-
72- > NOTE: There is an issue with delete method
73- > Check [ issue] ( https://github.com/typicode/json-server/issues/760 )
70+ ## Update ` deleteHotel ` API method
7471
7572### Fetch version
7673
@@ -85,8 +82,6 @@ const url = '/api/hotels';
8582
8683...
8784
88- + // json-server delete issue: It deletes all collection instead of single one.
89- + // https://github.com/typicode/json-server/issues/760
9085export const deleteHotel = async (id: string): Promise<boolean> => {
9186- hotelCollection = hotelCollection.filter((h) => h.id !== id);
9287- return true;
@@ -101,7 +96,7 @@ export const deleteHotel = async (id: string): Promise<boolean> => {
10196_ ./src/pods/hotel-collection/api/hotel-collection.api.ts_
10297
10398``` diff
104- import Axios from 'axios';
99+ import axios from 'axios';
105100import { HotelEntityApi } from './hotel-collection.api-model';
106101- import { mockHotelCollection } from './hotel-collection.mock-data';
107102
@@ -110,19 +105,17 @@ const url = '/api/hotels';
110105
111106...
112107
113- + // json-server delete issue: It deletes all collection instead of single one.
114- + // https://github.com/typicode/json-server/issues/760
115108export const deleteHotel = async (id: string): Promise<boolean> => {
116109- hotelCollection = hotelCollection.filter((h) => h.id !== id);
117- + await Axios .delete(`${url}/${id}`);
110+ + await axios .delete(`${url}/${id}`);
118111 return true;
119112};
120113
121114```
122115
123- - Delete ` ./src/pods/hotel-collection/api/hotel-collection.mock-data.ts ` , not used.
116+ Delete ` ./src/pods/hotel-collection/api/hotel-collection.mock-data.ts ` , not used.
124117
125- - Update ` getHotel ` api method:
118+ ## Update ` getHotel ` API method
126119
127120### Fetch version
128121
@@ -155,7 +148,7 @@ export const getHotel = async (id: string): Promise<Hotel> => {
155148_ ./src/pods/hotel/api/hotel.api.ts_
156149
157150``` diff
158- + import Axios from 'axios';
151+ + import axios from 'axios';
159152import { Hotel } from './hotel.api-model';
160153import { Lookup } from 'common/models';
161154- import { mockCities, mockHotelCollection } from './hotel.mock-data';
@@ -165,16 +158,15 @@ import { Lookup } from 'common/models';
165158
166159export const getHotel = async (id: string): Promise<Hotel> => {
167160- return mockHotelCollection.find((h) => h.id === id);
168- + const { data } = await Axios.get<Hotel>(`${hotelListUrl}/${id}`);
169-
161+ + const { data } = await axios.get<Hotel>(`${hotelListUrl}/${id}`);
170162+ return data;
171163};
172164
173165...
174166
175167```
176168
177- - Update ` getCities ` api method:
169+ ## Update ` getCities ` API method
178170
179171### Fetch version
180172
@@ -209,7 +201,7 @@ export const getCities = async (): Promise<Lookup[]> => {
209201_ ./src/pods/hotel/api/hotel.api.ts_
210202
211203``` diff
212- import Axios from 'axios';
204+ import axios from 'axios';
213205import { Hotel } from './hotel.api-model';
214206import { Lookup } from 'common/models';
215207- import { mockCities } from './hotel.mock-data';
@@ -221,16 +213,15 @@ const hotelListUrl = '/api/hotels';
221213
222214export const getCities = async (): Promise<Lookup[]> => {
223215- return mockCities;
224- + const { data } = await Axios.get<Lookup[]>(cityListUrl);
225-
216+ + const { data } = await axios.get<Lookup[]>(cityListUrl);
226217+ return data;
227218};
228219
229220...
230221
231222```
232223
233- - Update ` saveHotel ` api method:
224+ ## Update ` saveHotel ` API method
234225
235226### Fetch version
236227
@@ -271,16 +262,16 @@ _./src/pods/hotel/api/hotel.api.ts_
271262
272263export const saveHotel = async (hotel: Hotel): Promise<boolean> => {
273264+ if (hotel.id) {
274- + await Axios .put<Hotel>(`${hotelListUrl}/${hotel.id}`, hotel);
265+ + await axios .put<Hotel>(`${hotelListUrl}/${hotel.id}`, hotel);
275266+ } else {
276- + await Axios .post<Hotel>(hotelListUrl, hotel);
267+ + await axios .post<Hotel>(hotelListUrl, hotel);
277268+ }
278269 return true;
279270};
280271
281272```
282273
283- - Delete ` ./src/pods/hotel/api/hotel.mock-data.ts ` , not used.
274+ Delete ` ./src/pods/hotel/api/hotel.mock-data.ts ` , not used.
284275
285276# About Basefactor + Lemoncode
286277
0 commit comments