api(application): relocate egg endpoints
This commit is contained in:
parent
5946210e18
commit
58cfa98b9c
23 changed files with 309 additions and 112 deletions
|
@ -1,12 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/nests/eggs/getEggs';
|
||||
|
||||
export default (nestId: number, name: string): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.post('/api/application/eggs', {
|
||||
nestId, name,
|
||||
})
|
||||
.then(({ data }) => resolve(rawDataToEgg(data.attributes)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export default (id: number): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.delete(`/api/application/eggs/${id}`)
|
||||
.then(() => resolve())
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,10 +0,0 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/nests/eggs/getEggs';
|
||||
|
||||
export default (id: number): Promise<Egg> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/eggs/${id}`)
|
||||
.then(({ data }) => resolve(rawDataToEgg(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,57 +0,0 @@
|
|||
import http, { FractalResponseData } from '@/api/http';
|
||||
|
||||
export interface Egg {
|
||||
id: number;
|
||||
uuid: string;
|
||||
nest_id: number;
|
||||
author: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
features: string[] | null;
|
||||
dockerImages: string[];
|
||||
configFiles: string | null;
|
||||
configStartup: string | null;
|
||||
configLogs: string | null;
|
||||
configStop: string | null;
|
||||
configFrom: number | null;
|
||||
startup: string;
|
||||
scriptContainer: string;
|
||||
copyScriptFrom: number | null;
|
||||
scriptEntry: string;
|
||||
scriptIsPrivileged: boolean;
|
||||
scriptInstall: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const rawDataToEgg = ({ attributes }: FractalResponseData): Egg => ({
|
||||
id: attributes.id,
|
||||
uuid: attributes.uuid,
|
||||
nest_id: attributes.nest_id,
|
||||
author: attributes.author,
|
||||
name: attributes.name,
|
||||
description: attributes.description,
|
||||
features: attributes.features,
|
||||
dockerImages: attributes.docker_images,
|
||||
configFiles: attributes.config_files,
|
||||
configStartup: attributes.config_startup,
|
||||
configLogs: attributes.config_logs,
|
||||
configStop: attributes.config_stop,
|
||||
configFrom: attributes.config_from,
|
||||
startup: attributes.startup,
|
||||
scriptContainer: attributes.script_container,
|
||||
copyScriptFrom: attributes.copy_script_from,
|
||||
scriptEntry: attributes.script_entry,
|
||||
scriptIsPrivileged: attributes.script_is_privileged,
|
||||
scriptInstall: attributes.script_install,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
});
|
||||
|
||||
export default (nestId: number): Promise<Egg[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/nests/${nestId}`)
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToEgg)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
10
resources/scripts/api/admin/nests/getEggs.ts
Normal file
10
resources/scripts/api/admin/nests/getEggs.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import http from '@/api/http';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
export default (nestId: number): Promise<Egg[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/nests/${nestId}/eggs`)
|
||||
.then(({ data }) => resolve((data.data || []).map(rawDataToEgg)))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +1,9 @@
|
|||
import http from '@/api/http';
|
||||
import { Nest, rawDataToNest } from '@/api/admin/nests/getNests';
|
||||
|
||||
export default (id: number): Promise<Nest> => {
|
||||
export default (id: number, include: string[]): Promise<Nest> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/application/nests/${id}`)
|
||||
http.get(`/api/application/nests/${id}`, { params: { include: include.join(',') } })
|
||||
.then(({ data }) => resolve(rawDataToNest(data)))
|
||||
.catch(reject);
|
||||
});
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
import { createContext, useContext } from 'react';
|
||||
import useSWR from 'swr';
|
||||
import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg';
|
||||
|
||||
export interface Nest {
|
||||
id: number;
|
||||
|
@ -10,6 +11,10 @@ export interface Nest {
|
|||
description: string | null;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
|
||||
relations: {
|
||||
eggs: Egg[] | undefined;
|
||||
},
|
||||
}
|
||||
|
||||
export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({
|
||||
|
@ -20,6 +25,10 @@ export const rawDataToNest = ({ attributes }: FractalResponseData): Nest => ({
|
|||
description: attributes.description,
|
||||
createdAt: new Date(attributes.created_at),
|
||||
updatedAt: new Date(attributes.updated_at),
|
||||
|
||||
relations: {
|
||||
eggs: ((attributes.relationships?.eggs as FractalResponseList | undefined)?.data || []).map(rawDataToEgg),
|
||||
},
|
||||
});
|
||||
|
||||
interface ctx {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue