datasquirel/package-shared/api/crud/put.ts
Benjamin Toby 3730e4722e Updates
2025-07-05 15:16:31 +01:00

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,
});
}