import apollo from "@/lib/apollo.js"; async function GetDetailProduct(id, token = "") { var res = await apollo.query( ` query($input : ID!){ product(id:$input){ data{ id attributes{ Company{ data{ attributes{ Name } } } Category{ data{ attributes{ Name } } } Name Description Product_parts{ data{ attributes{ Name Part_Code Product_prices{ data{ attributes{ Price } } } } } } Stock Discount Machine Dimension Structure Voltage Image{ data{ attributes{ url } } } Product_colors{ data{ attributes{ Color Image{ data{ attributes{ url } } } } } } Product_prices{ data{ attributes{ Price region{ data{ attributes{ Name } } } } } } } } } } `, token, { "input": id } ); return res; } async function GetProductImgColor(id, token = "") { var res = await apollo.query( ` query($input: ID!) { productImageColors(where:{id:$input}) { id name img{ url } } } `, token, { "input": id } ); return res; } async function GetProductCategory(token=''){ var res = await apollo.query( ` query{ productCategories{ data{ attributes{ Name } } } } `,token ); return res; } async function GetProductOthers(company,category,current,pageSize=999,page=1,token=""){ var allProduct= ''; category.forEach(i => { allProduct = allProduct+` ${i.replace(' ','_')}:products(pagination:{pageSize:${pageSize},page:${(i.toLowerCase()==current)?page:1}} filters:{Category:{Name:{containsi:"${i}"}} Company:{id:{eq:$input}}}){ meta{ pagination{ pageCount total } } data{ id attributes{ Name Image{ data{ attributes{ url } } } Discount Stock Product_prices{ data{ attributes{ Price region{ data{ attributes{ Name } } } } } } } } } `; }); var res = await apollo.query( ` query($input : ID!){ ${allProduct} } `,token,{ input:company, } ); return res; } async function GetProduct(company,category,pageSize=999,page=1, token = "") { var res = await apollo.query( ` query($input : ID! $cat: String!){ products(pagination:{pageSize:${pageSize},page:${page}} filters:{Category:{Name:{eq:$cat}} Company:{id:{eq:$input}}}){ meta{ pagination{ pageCount total } } data{ id attributes{ Name Image{ data{ attributes{ url } } } Product_prices{ data{ attributes{ Price region{ data{ attributes{ Name } } } } } } } } } } `, token, { input:company, cat:category, } ); return res; } module.exports = { GetProductImgColor: GetProductImgColor, GetProduct: GetProduct, GetProductCategory:GetProductCategory, //detail GetDetailProduct: GetDetailProduct, GetProductOthers:GetProductOthers, };