Skip to content

Commit

Permalink
Merge pull request #1 from zafree/zis-mock-products
Browse files Browse the repository at this point in the history
Added mock products and get the products by category feature
  • Loading branch information
tareq89 authored Aug 13, 2021
2 parents b324225 + e4f7cc7 commit 9a2bcf6
Show file tree
Hide file tree
Showing 25 changed files with 681 additions and 1,783 deletions.
2 changes: 2 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function getProductBySlug (slug, authToken) {
export function getCategoryProducts (currentCategory, specialCategories, subCategories, authToken) {
const requestConfig = {
name: 'getCategoryProducts',
categoryId: (currentCategory ? currentCategory.id : null),
url: getUrlFromTemplate(API.PRODUCTS_BY_CATEGORY, {categoryId: (currentCategory ? currentCategory.id : null)}),
params: {
special_categories: map(specialCategories, 'id'),
Expand All @@ -222,6 +223,7 @@ export function getCategoryProducts (currentCategory, specialCategories, subCate
export function getSpecialCategoryProducts (specialCategory, currentCategory, authToken, from, take, brandId) {
const requestConfig = {
name: 'getSpecialCategoryProducts',
categoryId: specialCategory.id,
url: getUrlFromTemplate(API.PRODUCTS_BY_CATEGORY, {categoryId: specialCategory.id}),
params: {
context_id: (currentCategory ? currentCategory.id : null),
Expand Down
33 changes: 17 additions & 16 deletions api/mock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from '~/plugins/axios'
import location from '~/api/mock/location.json'
import { categories } from '~/api/mock/categories'
import { getCategoryProducts } from '~/api/mock/products/getCategoryProducts'
import { mockSaveCart, mockValidateCart } from './mock/cart'
import {
API_END_POINTS as API,
Expand All @@ -12,7 +13,7 @@ import isString from 'lodash/isString'
import extend from 'lodash/extend'
import omit from 'lodash/omit'
import get from 'lodash/get'
import map from 'lodash/map'
// import map from 'lodash/map'
// import some from 'lodash/some'
import trim from 'lodash/trim'

Expand Down Expand Up @@ -139,11 +140,11 @@ export function callMockApi (requestConfig) {
// return getProductBySlug()
return callApi(requestConfig)
case 'getCategoryProducts':
// return getCategoryProducts()
return callApi(requestConfig)
return getCategoryProducts(requestConfig)
// return callApi(requestConfig)
case 'getSpecialCategoryProducts':
// return getSpecialCategoryProducts()
return callApi(requestConfig)
return getCategoryProducts(requestConfig)
// return callApi(requestConfig)
case 'createOtp':
// return createOtp()
return callApi(requestConfig)
Expand Down Expand Up @@ -303,18 +304,18 @@ export function getProductBySlug (slug, authToken) {
return callApi(requestConfig)
}

export function getCategoryProducts (currentCategory, specialCategories, subCategories, authToken) {
const requestConfig = {
url: getUrlFromTemplate(API.PRODUCTS_BY_CATEGORY, {categoryId: (currentCategory ? currentCategory.id : null)}),
params: {
special_categories: map(specialCategories, 'id'),
sub_categories: map(subCategories, 'id')
}
}
authToken ? requestConfig.access_token = authToken : null
// export function getCategoryProducts (currentCategory, specialCategories, subCategories, authToken) {
// const requestConfig = {
// url: getUrlFromTemplate(API.PRODUCTS_BY_CATEGORY, {categoryId: (currentCategory ? currentCategory.id : null)}),
// params: {
// special_categories: map(specialCategories, 'id'),
// sub_categories: map(subCategories, 'id')
// }
// }
// authToken ? requestConfig.access_token = authToken : null

return callApi(requestConfig)
}
// return callApi(requestConfig)
// }

export function getSpecialCategoryProducts (specialCategory, currentCategory, authToken, from, take, brandId) {
const requestConfig = {
Expand Down
40 changes: 40 additions & 0 deletions api/mock/products/getCategoryProducts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import product10111 from '~/api/mock/products/product10/product10111.json'
import product10112 from '~/api/mock/products/product10/product10112.json'
import product10113 from '~/api/mock/products/product10/product10113.json'
import product10114 from '~/api/mock/products/product10/product10114.json'
import product10121 from '~/api/mock/products/product10/product10121.json'
import product10122 from '~/api/mock/products/product10/product10122.json'
import product10123 from '~/api/mock/products/product10/product10123.json'
import product10124 from '~/api/mock/products/product10/product10124.json'

import product20001 from '~/api/mock/products/product20/product20001.json'
import product20002 from '~/api/mock/products/product20/product20002.json'
import product20003 from '~/api/mock/products/product20/product20003.json'
import product20004 from '~/api/mock/products/product20/product20004.json'

const products = [
product10111,
product10112,
product10113,
product10114,
product10121,
product10122,
product10123,
product10124,
product20001,
product20002,
product20003,
product20004
]

function getProductByCategoryId (id) {
return products.filter(prod => prod.categoryId === id)
}

export function getCategoryProducts ({ categoryId }) {
const categoryProducts = {}

categoryProducts[categoryId] = getProductByCategoryId(categoryId)
return categoryProducts
}

Loading

0 comments on commit 9a2bcf6

Please sign in to comment.