UNPKG

phx-react

Version:

PHX REACT

153 lines (152 loc) 4.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getListProductQuery = exports.getListBundleQuery = exports.countAllBundleAndProductQuery = void 0; const constant_1 = require("./constant"); const getCustomQuery = ({ searchValue, isInCampaign, type, }) => { const queryArr = []; if (searchValue) { queryArr.push(` _or:[ {name: { _ilike: "%${searchValue}%" }} {code: { _ilike: "%${searchValue}%" }} ]`); } if (isInCampaign && type === 'PRODUCT') { queryArr.push(`store_product_sale_type:{ code:{_eq: "${constant_1.BAN_THEO_DOT}"} }`); } if (isInCampaign && type === 'BUNDLE') { queryArr.push(` store_bundle_sale_type:{ code:{_eq: "${constant_1.BAN_THEO_DOT}"} }`); } return queryArr.join(','); }; const countAllBundleAndProductQuery = (isInCampaign) => { return ` query getListProductQuery($school_id: Int!) { store_product_aggregate( where: { ${isInCampaign ? ` store_product_sale_type:{ code:{_eq: "${constant_1.BAN_THEO_DOT}"} }` : ''}, store_product_status:{code:{_eq:"${constant_1.ACTIVE_CODE}"}} deleted_at: {_is_null: true}, school_id: {_eq: $school_id} }) { aggregate{ count } } store_bundle_aggregate( where:{ deleted_at:{_is_null: true} store_bundle_status:{code:{_eq: "${constant_1.ACTIVE_CODE}"}} school_id:{_eq: $school_id} ${isInCampaign ? ` store_bundle_sale_type:{ code:{_eq: "${constant_1.BAN_THEO_DOT}"} }` : ''} }) { aggregate{ count } } } `; }; exports.countAllBundleAndProductQuery = countAllBundleAndProductQuery; const getListBundleQuery = (searchValue, isInCampaign) => { return ` query getListBundleQuery($school_id: Int!, $school_year_id: Int!, $limit: Int!, $offset: Int!) { store_bundle( limit: $limit offset: $offset order_by:{id: asc} where:{ deleted_at:{_is_null: true} store_bundle_status:{code:{_eq: "${constant_1.ACTIVE_CODE}"}} school_id:{_eq: $school_id} ${getCustomQuery({ searchValue, isInCampaign, type: 'BUNDLE' })} }) { bundle_id: id name image price_type status: store_bundle_status { name code } tuition_fee_type_of_service { description tuition_fee_project_codes(where: {deleted_at: {_is_null: true}, school_year_id: {_eq: $school_year_id}}) { code } } store_bundle_products( where: {deleted_at: {_is_null: true}store_product: {deleted_at: {_is_null: true}}}) { store_bundle_product_attribute_values( where: { deleted_at: {_is_null:true} store_product_attribute_value: { deleted_at:{_is_null:true} } }) { store_product_attribute_value { price } } } } } `; }; exports.getListBundleQuery = getListBundleQuery; const getListProductQuery = (searchValue, isInCampaign) => { return ` query getListProductQuery($school_id: Int!, $school_year_id: Int!, $limit: Int!, $offset: Int!) { store_product( limit: $limit offset: $offset order_by:{id: asc} where: { ${getCustomQuery({ searchValue, isInCampaign, type: 'PRODUCT' })} store_product_status:{code:{_eq:"${constant_1.ACTIVE_CODE}"}} deleted_at: {_is_null: true}, school_id: {_eq: $school_id} }) { product_id: id name image status: store_product_status { name code } tuition_fee_type_of_service { description tuition_fee_project_codes(where: {deleted_at: {_is_null: true}, school_year_id: {_eq: $school_year_id}}) { code } } store_product_attributes(where:{ deleted_at: {_is_null: true}}) { store_product_attribute_values_aggregate(where:{ deleted_at: {_is_null: true}}) { aggregate { min { price } max { price } } } } } } `; }; exports.getListProductQuery = getListProductQuery; //# sourceMappingURL=query.js.map