Updates
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
import { SQLDeleteData } from "../../types";
|
||||
type Params<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}> = {
|
||||
dbName: string;
|
||||
tableName: string;
|
||||
deleteSpec?: T & {
|
||||
deleteKeyValues?: SQLDeleteData<T>[];
|
||||
};
|
||||
targetID?: string | number;
|
||||
};
|
||||
export default function apiCrudDELETE<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ dbName, tableName, deleteSpec, targetID }: Params<T>): Promise<import("../../types").APIResponseObject<{
|
||||
[k: string]: any;
|
||||
}>>;
|
||||
export {};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import path from "path";
|
||||
import queryDSQLAPI from "../../functions/api/query-dsql-api";
|
||||
import grabAPIBasePath from "../../utils/grab-api-base-path";
|
||||
export default async function apiCrudDELETE({ dbName, tableName, deleteSpec, targetID }) {
|
||||
const basePath = grabAPIBasePath({ paradigm: "crud" });
|
||||
const finalID = typeof targetID === "number" ? String(targetID) : targetID;
|
||||
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
|
||||
const GET_RES = await queryDSQLAPI({
|
||||
method: "DELETE",
|
||||
path: finalPath,
|
||||
body: deleteSpec,
|
||||
});
|
||||
return GET_RES;
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { APIResponseObject, DsqlCrudQueryObject } from "../../types";
|
||||
type Params<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}> = {
|
||||
dbName: string;
|
||||
tableName: string;
|
||||
query?: DsqlCrudQueryObject<T>;
|
||||
targetId?: string | number;
|
||||
};
|
||||
export default function apiCrudGET<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ dbName, tableName, query, targetId, }: Params<T>): Promise<APIResponseObject>;
|
||||
export {};
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import path from "path";
|
||||
import queryDSQLAPI from "../../functions/api/query-dsql-api";
|
||||
import grabAPIBasePath from "../../utils/grab-api-base-path";
|
||||
export default async function apiCrudGET({ dbName, tableName, query, targetId, }) {
|
||||
const basePath = grabAPIBasePath({ paradigm: "crud" });
|
||||
const finalID = typeof targetId === "number" ? String(targetId) : targetId;
|
||||
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
|
||||
const GET_RES = await queryDSQLAPI({
|
||||
method: "GET",
|
||||
path: finalPath,
|
||||
query,
|
||||
});
|
||||
return GET_RES;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import apiCrudGET from "./get";
|
||||
import apiCrudPOST from "./post";
|
||||
import apiCrudPUT from "./put";
|
||||
import apiCrudDELETE from "./delete";
|
||||
declare const crud: {
|
||||
get: typeof apiCrudGET;
|
||||
insert: typeof apiCrudPOST;
|
||||
update: typeof apiCrudPUT;
|
||||
delete: typeof apiCrudDELETE;
|
||||
options: () => Promise<void>;
|
||||
};
|
||||
export default crud;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import apiCrudGET from "./get";
|
||||
import apiCrudPOST from "./post";
|
||||
import apiCrudPUT from "./put";
|
||||
import apiCrudDELETE from "./delete";
|
||||
const crud = {
|
||||
get: apiCrudGET,
|
||||
insert: apiCrudPOST,
|
||||
update: apiCrudPUT,
|
||||
delete: apiCrudDELETE,
|
||||
options: async () => { },
|
||||
};
|
||||
export default crud;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { APIResponseObject } from "../../types";
|
||||
export type APICrudPostParams<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}> = {
|
||||
dbName: string;
|
||||
tableName: string;
|
||||
body: T;
|
||||
update?: boolean;
|
||||
};
|
||||
export default function apiCrudPOST<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ dbName, tableName, body, update, }: APICrudPostParams<T>): Promise<APIResponseObject>;
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import path from "path";
|
||||
import queryDSQLAPI from "../../functions/api/query-dsql-api";
|
||||
import grabAPIBasePath from "../../utils/grab-api-base-path";
|
||||
export default async function apiCrudPOST({ dbName, tableName, body, update, }) {
|
||||
const basePath = grabAPIBasePath({ paradigm: "crud" });
|
||||
const passedID = body.id;
|
||||
const finalID = update
|
||||
? typeof passedID === "number"
|
||||
? String(passedID)
|
||||
: passedID
|
||||
: undefined;
|
||||
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
|
||||
const GET_RES = await queryDSQLAPI({
|
||||
method: update ? "PUT" : "POST",
|
||||
path: finalPath,
|
||||
body,
|
||||
});
|
||||
return GET_RES;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { APICrudPostParams } from "./post";
|
||||
type Params<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}> = Omit<APICrudPostParams<T>, "update"> & {
|
||||
targetID: string | number;
|
||||
};
|
||||
export default function apiCrudPUT<T extends {
|
||||
[key: string]: any;
|
||||
} = {
|
||||
[key: string]: any;
|
||||
}>({ dbName, tableName, body, targetID }: Params<T>): Promise<import("../../types").APIResponseObject>;
|
||||
export {};
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import apiCrudPOST from "./post";
|
||||
export default async function apiCrudPUT({ dbName, tableName, body, targetID }) {
|
||||
const updatedBody = Object.assign({}, body);
|
||||
if (targetID) {
|
||||
updatedBody["id"] = targetID;
|
||||
}
|
||||
return await apiCrudPOST({
|
||||
dbName,
|
||||
tableName,
|
||||
body: updatedBody,
|
||||
update: true,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user