import { CreateProductReviewRequestType, DeleteProductReviewRequestType, ListProductReviewRequestType, ProductReview, ProductReviewBatchUpdateRequestType, ProductReviewBatchUpdateResponseType, ProductReviewByIdRequestType, UpdateProductReviewRequestType, } from './types'; import { AxiosInstance } from 'axios'; export default class ProductReviews { private readonly client: AxiosInstance; constructor(client: AxiosInstance) { this.client = client; } async create(data: CreateProductReviewRequestType) { const response = await this.client.post( 'product/reviews', data ); return response.data; } async getById({ id }: ProductReviewByIdRequestType) { const response = await this.client.get( `product/reviews/${id}` ); return response.data; } async list( params?: ListProductReviewRequestType ): Promise<{ data: ProductReview[]; count: number; totalPages: number; }> { const response = await this.client.get('product/reviews', { params, }); return { data: response.data, count: response.headers['x-wp-total'], totalPages: response.headers['x-wp-totalpages'], }; } async updateById({ id, data }: UpdateProductReviewRequestType) { const response = await this.client.put( `product/reviews/${id}`, data ); return response.data; } async deleteById({ id, data: { force = true }, }: DeleteProductReviewRequestType) { const response = await this.client.delete( `product/reviews/${id}`, { data: { force, }, } ); return response.data; } async batch(data: ProductReviewBatchUpdateRequestType) { const response = await this.client.post< ProductReviewBatchUpdateResponseType >('product/reviews/batch', data); return response.data; } }