2021-07-14 22:43:59 +00:00
|
|
|
import http, { FractalResponseData } from '@/api/http';
|
2021-05-20 22:00:46 +00:00
|
|
|
|
|
|
|
export interface Allocation {
|
|
|
|
id: number;
|
|
|
|
ip: string;
|
|
|
|
alias: string | null;
|
|
|
|
port: number;
|
|
|
|
notes: string | null;
|
2021-07-14 22:43:59 +00:00
|
|
|
assigned: boolean;
|
2021-05-20 22:00:46 +00:00
|
|
|
}
|
|
|
|
|
2021-07-14 22:43:59 +00:00
|
|
|
export const rawDataToAllocation = (data: FractalResponseData): Allocation => ({
|
|
|
|
id: data.attributes.id,
|
|
|
|
ip: data.attributes.ip,
|
|
|
|
alias: data.attributes.ip_alias,
|
|
|
|
port: data.attributes.port,
|
|
|
|
notes: data.attributes.notes,
|
|
|
|
assigned: data.attributes.assigned,
|
|
|
|
});
|
|
|
|
|
2021-07-20 19:20:41 +00:00
|
|
|
export default (id: string | number): Promise<Allocation[]> => {
|
2021-05-20 22:00:46 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2021-07-20 19:20:41 +00:00
|
|
|
http.get(`/api/application/nodes/${id}/allocations`)
|
2021-07-14 22:43:59 +00:00
|
|
|
.then(({ data }) => resolve((data.data || []).map(rawDataToAllocation)))
|
2021-05-20 22:00:46 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|