diff --git a/.gitignore b/.gitignore index 68856e1..2808f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,5 +36,4 @@ yarn-error.log* next-env.d.ts .idea/ -./docker-compose.yml -./Dockerfile +Dockerfile diff --git a/src/pages/api/v1/order/make.ts b/src/pages/api/v1/order/make.ts index ce31610..5c12cae 100644 --- a/src/pages/api/v1/order/make.ts +++ b/src/pages/api/v1/order/make.ts @@ -34,7 +34,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { { // FIO orderPropsId: 103, - value: body.fullName,E + value: body.fullName }, { // Phone diff --git a/src/pages/catalog/[code].tsx b/src/pages/catalog/[code].tsx index 507bcd0..60ee6ac 100644 --- a/src/pages/catalog/[code].tsx +++ b/src/pages/catalog/[code].tsx @@ -180,7 +180,8 @@ const OilCard = ({product}: InferGetStaticPropsType) => { export default OilCard export const getStaticPaths = async () => { - const {data} = await axios.get("http://localhost:8000/api/v1/catalog") + const service = new LocalAPI() + const data = await service.getCatalogItems() as {code: string}[] const codes = data.map(item => ({params: {code: item.code}})) return { paths: [ @@ -192,7 +193,8 @@ export const getStaticPaths = async () => { } export const getStaticProps = async ({params: {code}}: { params: { code: string } }) => { - const {data} = await axios.get(`http://localhost:8000/api/v1/catalog/${code}`) + const service = new LocalAPI() + const data = await service.getCatalogItemByCode(code) return { props: { product: data diff --git a/src/pages/catalog/index.tsx b/src/pages/catalog/index.tsx index f9a453f..22b272f 100644 --- a/src/pages/catalog/index.tsx +++ b/src/pages/catalog/index.tsx @@ -5,12 +5,9 @@ import { Checkbox, Button, Skeleton } from "@nextui-org/react"; -import Image from "next/image"; import Link from "next/link"; import axios from "axios"; import {InferGetStaticPropsType} from "next"; -import {ResponseData} from "@/pages/api/v1/catalog/properties" -import {ResponseData as ResponseDataProduct} from "@/pages/api/v1/catalog" import FavouriteIcon from "@/../public/favourites_icon.svg"; import {Dispatch, SetStateAction, useEffect, useState} from "react"; import {toggleFavourite} from "@/store/favourites"; @@ -80,7 +77,7 @@ const CatalogCard = (product: CardProps) => { imageIsLoading && } { - product.properties.main_image && {product.properties.viscosity!} + product.properties.main_image && {product.name} }
Стандарт API: {product.properties.api_standart} Тип: {product.properties.oil_type} @@ -137,11 +134,24 @@ const Catalog = (props: InferGetStaticPropsType) => { export default Catalog; export const getStaticProps = async () => { - const {data} = await axios.get("http://localhost:8000/api/v1/catalog/filters") - const {data: catalogData} = await axios.get("http://localhost:8000/api/v1/catalog") + const service = new LocalAPI() + const filterData = await service.getFilters() as {id: number, name: string, values: {id: number, value: string}[]}[] + const catalogData = await service.getCatalogItems() as { + id: number + code: string, + name: string, + properties: { + [key: string]: string | string[] + } + detailText: string, + price: { + [key: string]: number | null + } + }[] + return { props: { - filterPropertiesData: data, + filterPropertiesData: filterData, catalog: catalogData } } diff --git a/src/service/localAPI.ts b/src/service/localAPI.ts index a173393..4d2b159 100644 --- a/src/service/localAPI.ts +++ b/src/service/localAPI.ts @@ -1,4 +1,5 @@ import axios, {AxiosInstance} from "axios"; +import {ResponseData} from "@/pages/api/v1/catalog"; type createFUserType = { @@ -22,10 +23,25 @@ class LocalAPI { constructor() { this.instance = axios.create({ - baseURL: 'http://localhost:8000' + baseURL: process.env.NODE_ENV === "development" ? "http://localhost:8000": "https://relynolli.ru" }) } + async getCatalogItems() { + const {data} = await this.instance.get('/api/v1/catalog') + return data + } + + async getFilters() { + const {data} = await this.instance.get("/api/v1/catalog/filters") + return data + } + + async getCatalogItemByCode(code: string) { + const {data} = await this.instance.get(`/api/v1/catalog/${code}`) + return data + } + async getFuserId() { let fuserId: string | number | null = localStorage.getItem('fuserId')