28 lines
655 B
TypeScript
28 lines
655 B
TypeScript
import apiCrudPOST, { APICrudPostParams } from "./post";
|
|
|
|
type Params<T extends { [key: string]: any } = { [key: string]: any }> = Omit<
|
|
APICrudPostParams<T>,
|
|
"update"
|
|
> & {
|
|
targetID: string | number;
|
|
apiKey?: string;
|
|
};
|
|
|
|
export default async function apiCrudPUT<
|
|
T extends { [key: string]: any } = { [key: string]: any }
|
|
>({ dbName, tableName, body, targetID, apiKey }: Params<T>) {
|
|
const updatedBody = { ...body } as any;
|
|
|
|
if (targetID) {
|
|
updatedBody["id"] = targetID;
|
|
}
|
|
|
|
return await apiCrudPOST({
|
|
dbName,
|
|
tableName,
|
|
body: updatedBody,
|
|
update: true,
|
|
apiKey,
|
|
});
|
|
}
|