Skip to content

Commit b86fca8

Browse files
committed
refactor api.serverApi and api.types. ensuring that the names are Pkg, PkgNode, PkgInstance, and Pipeline.
1 parent ee903fe commit b86fca8

File tree

29 files changed

+701
-569
lines changed

29 files changed

+701
-569
lines changed

src/api/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import config from "config";
22
import { Cookies } from "react-cookie";
3+
import { T } from "vitest/dist/chunks/environment.d.cL3nLXbE.js";
4+
import type { List } from "../api/types";
35
import { STATUS_UNAUTHORIZED } from "./constants";
46

57
export type Query = Record<string, any>;
@@ -76,7 +78,10 @@ const collectionJsonLinkToJson = (links: any[]) => {
7678
}, {});
7779
};
7880

79-
export const collectionJsonToJson = (theData: any, isLink = false) => {
81+
export const collectionJsonToJson = <T>(
82+
theData: any,
83+
isLink = false,
84+
): T | T[] | List<T> => {
8085
if (isLink) {
8186
return collectionJsonLinkToJson(theData.collection.links);
8287
}

src/api/serverApi.ts

Lines changed: 0 additions & 296 deletions
This file was deleted.

src/api/serverApi/data.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import api, { type ApiResult } from "../api";
2+
import type { Data } from "../types";
3+
import { createPkgInstance } from "./pkgInstance";
4+
5+
export const getData = (dataID: number) =>
6+
api<Data>({
7+
endpoint: `/${dataID}/`,
8+
method: "get",
9+
});
10+
11+
export const updateDataName = (dataID: number, dataName: string) =>
12+
api<Data>({
13+
endpoint: `/${dataID}/`,
14+
method: "put",
15+
json: {
16+
name: dataName,
17+
},
18+
});
19+
20+
export const updateDataPublic = (dataID: number, isPublic = true) =>
21+
api<Data>({
22+
endpoint: `/${dataID}/`,
23+
method: "put",
24+
json: {
25+
public: isPublic,
26+
},
27+
});
28+
29+
export const createDataWithFilepath = async (
30+
filepath: string,
31+
theName: string,
32+
// biome-ignore lint/correctness/noUnusedFunctionParameters: not using tags for now.
33+
tags?: string[],
34+
isPublic: boolean = false,
35+
): Promise<ApiResult<Data>> => {
36+
const { status, data, errmsg } = await createPkgInstance(1, [filepath]);
37+
if (!data) {
38+
return {
39+
errmsg,
40+
status,
41+
};
42+
}
43+
44+
const { feed_id: dataID } = data;
45+
46+
await updateDataName(dataID, theName);
47+
48+
if (isPublic) {
49+
await updateDataPublic(dataID, true);
50+
}
51+
52+
const dataResult = await getData(dataID);
53+
54+
return dataResult;
55+
};

0 commit comments

Comments
 (0)