mirror of
https://github.com/sakaljurgis/best-choice.git
synced 2026-07-08 21:47:40 +00:00
edit price
This commit is contained in:
@@ -48,6 +48,15 @@ export interface CreateItemPricePayload {
|
||||
note?: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateItemPricePayload {
|
||||
condition?: PriceCondition;
|
||||
amount?: number;
|
||||
currency?: string;
|
||||
sourceUrl?: string | null;
|
||||
sourceUrlId?: string | null;
|
||||
note?: string | null;
|
||||
}
|
||||
|
||||
interface SingleItemPriceResponse {
|
||||
data: ItemPrice;
|
||||
}
|
||||
@@ -74,6 +83,46 @@ export const createItemPrice = async (
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const updateItemPrice = async (
|
||||
priceId: string,
|
||||
payload: UpdateItemPricePayload
|
||||
): Promise<ItemPrice> => {
|
||||
const body: Record<string, unknown> = {};
|
||||
|
||||
if (payload.condition !== undefined) {
|
||||
body.condition = payload.condition;
|
||||
}
|
||||
if (payload.amount !== undefined) {
|
||||
body.amount = payload.amount;
|
||||
}
|
||||
if (payload.currency !== undefined) {
|
||||
body.currency = payload.currency;
|
||||
}
|
||||
if (payload.sourceUrlId !== undefined) {
|
||||
body.sourceUrlId = payload.sourceUrlId;
|
||||
}
|
||||
if (payload.sourceUrl !== undefined) {
|
||||
body.sourceUrl = payload.sourceUrl;
|
||||
}
|
||||
if (payload.note !== undefined) {
|
||||
body.note = payload.note;
|
||||
}
|
||||
|
||||
if (Object.keys(body).length === 0) {
|
||||
throw new Error('No fields provided to update item price');
|
||||
}
|
||||
|
||||
const response = await apiFetch<SingleItemPriceResponse>(
|
||||
`/prices/${priceId}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
body
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteItemPrice = async (priceId: string): Promise<void> => {
|
||||
await apiFetch<null>(`/prices/${priceId}`, {
|
||||
method: 'DELETE'
|
||||
|
||||
Reference in New Issue
Block a user