auto-post-marketplace-facebook/src/api/product-api.service.ts

78 lines
1.9 KiB
TypeScript

import axios from "@/lib/axios";
import type { IPost, ISyncItem } from "@/lib/utils";
class ProductApiService {
item_per_page = 10;
token =
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2ludC5pcHN1cHBseS5jb20uYXUvYXBpL2xvZ2luIiwiaWF0IjoxNzIxNjA5MTEzLCJleHAiOjMyMzUzMzcxMTMsIm5iZiI6MTcyMTYwOTExMywianRpIjoiWHpCZkZPc0ZJUlFxaEZvaiIsInN1YiI6MSwicHJ2IjoiYzhlZTFmYzg5ZTc3NWVjNGM3Mzg2NjdlNWJlMTdhNTkwYjZkNDBmYyJ9.kFFEPpdmNUp-kn_G3cIIc26bivO6tbfcvkpG9I8Im7M";
async index(filter?: {
skip?: number;
limit?: number;
order?: string;
where?: Record<string, any>;
}) {
const defaultFilter = {
skip: 0,
limit: 10,
order: "updatedAt desc",
where: {
account: "prology_net",
status: "Updated",
},
};
return axios({
url: "transferGetData",
headers: {
Authorization: "Bearer " + this.token,
},
method: "POST",
data: {
urlAPI: "/api/ebay-listing/listing-get-list",
filter: {
...defaultFilter,
...filter, // merge filter vào defaultFilter
where: {
...defaultFilter.where,
...filter?.where, // merge where riêng để không mất account/status mặc định
},
},
},
});
}
async get(data: IPost) {
return axios({
url: "transferGetData",
headers: {
Authorization: "Bearer " + this.token,
},
method: "POST",
data: {
urlAPI: "/api/product-model/get-info/" + data.id,
pageCurrent: "/productdata/products/edit/" + data.id,
},
});
}
async sync(data: ISyncItem[]) {
return axios({
baseURL: import.meta.env.VITE_API_SYNC_URL,
url: "sync",
method: "POST",
data,
});
}
async getPublistedProducts() {
return axios({
baseURL: import.meta.env.VITE_API_SYNC_URL,
url: "data",
});
}
}
export const productApi = new ProductApiService();