import { WordpressCoreService } from '../WordpressCoreService'; import type { IPriceJob, IPricePreview, IPriceRow } from './prices.interface'; const PRICES = 'recomaze/v1/prices'; /** What the file would change, read against the shop. Nothing is written. */ export const previewPrices = (csv: string): Promise => WordpressCoreService.post(`${PRICES}/preview`, { csv }); /** Write the previewed changes, in the background. */ export const applyPrices = ( items: IPriceRow[], file: string ): Promise => WordpressCoreService.post(`${PRICES}/apply`, { items, file }); /** Where the import has got to. */ export const getPriceJob = (jobId: string): Promise => WordpressCoreService.get(`${PRICES}/status/${encodeURIComponent(jobId)}`); /** The imports this shop has run, newest first. */ export const listPriceJobs = (): Promise<{ jobs: IPriceJob[] }> => WordpressCoreService.get(`${PRICES}/jobs`); /** Put every price this import changed back where it was. */ export const undoPrices = (jobId: string): Promise<{ restored: number }> => WordpressCoreService.post(`${PRICES}/undo`, { job_id: jobId });