2021-09-13 05:50:12 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
|
|
|
|
|
|
|
interface Filters {
|
|
|
|
name?: string;
|
|
|
|
}
|
|
|
|
|
2021-09-16 03:19:39 +00:00
|
|
|
export default (nestId: number, filters?: Filters, include: string[] = []): Promise<Egg[]> => {
|
2021-09-13 05:50:12 +00:00
|
|
|
const params = {};
|
|
|
|
if (filters !== undefined) {
|
|
|
|
Object.keys(filters).forEach(key => {
|
|
|
|
// @ts-ignore
|
|
|
|
params['filter[' + key + ']'] = filters[key];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2021-09-16 03:19:39 +00:00
|
|
|
http.get(`/api/application/nests/${nestId}/eggs`, { params: { include: include.join(','), ...params } })
|
2021-09-13 05:50:12 +00:00
|
|
|
.then(response => resolve(
|
|
|
|
(response.data.data || []).map(rawDataToEgg)
|
|
|
|
))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|