From c9c9b2a1ae5e946069a36b18ff3d66329a7aec3d Mon Sep 17 00:00:00 2001 From: HungLV Date: Wed, 14 Aug 2024 11:23:32 +0700 Subject: [PATCH] fix: CI/CD build, and graphql --- .env.public | 3 ++ .gitignore | 1 + Dockerfile | 3 +- src/lib/apis/product/create-product.ts | 16 +++++----- src/lib/apis/product/get-product.ts | 18 +++++++---- src/routes/(sidebar)/crud/products/+page.ts | 4 +-- .../(sidebar)/crud/products/Product.svelte | 13 ++++---- .../(sidebar)/crud/products/[id]/+page.ts | 8 ++--- .../crud/products/create/+page.server.ts | 30 ++++++++++++------- .../(sidebar)/crud/products/create/+page.ts | 4 +-- 10 files changed, 61 insertions(+), 39 deletions(-) create mode 100644 .env.public diff --git a/.env.public b/.env.public new file mode 100644 index 0000000..b59f20c --- /dev/null +++ b/.env.public @@ -0,0 +1,3 @@ +PUBLIC_GRAPHQL_ENDPOINT="https://graphql.dev.seekhype.io/v1/graphql" +# PUBLIC_API_ENDPOINT="https://ip.dev.aurascan.io" +PUBLIC_API_ENDPOINT="http://localhost:3000" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8a6c2f3..f9f0320 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ node_modules .env .env.* !.env.example +!.env.public vite.config.js.timestamp-* vite.config.ts.timestamp-* /test-results \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 334a2a3..b16274a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ FROM node:20-alpine AS builder WORKDIR /staging COPY . /staging/ +COPY ./.env.public /staging/.env RUN corepack enable && \ yarn install --frozen-lockfile && \ yarn build @@ -12,4 +13,4 @@ COPY --from=builder /staging/node_modules /app/node_modules COPY --from=builder /staging/build /app/build EXPOSE 3000 -CMD ["node", "-r", "dotenv/config", "/app/build/index.js"] \ No newline at end of file +CMD ["node", "-r", "dotenv/config", "/app/build/index.js"] diff --git a/src/lib/apis/product/create-product.ts b/src/lib/apis/product/create-product.ts index 22ccb17..b44c216 100644 --- a/src/lib/apis/product/create-product.ts +++ b/src/lib/apis/product/create-product.ts @@ -2,19 +2,19 @@ import { config } from '$lib/public-config'; export interface CreateProductRequest { name: string; - category: string; - description: string; + owner_id: number; avatar_img: string; banner_img: string; - metadata: any; - owner: { id: number }; - featured_at: string | null; - attributes: { name: string; value: string }[]; + category: string; + description: string; + metadata: { previews?: string[]; cta_link?: string }; + featured?: boolean; + attributes?: { name: string; value: string }[]; collections?: { chain_id: string; contract_address: string }[]; } -export async function createProduct(data: CreateProductRequest): Promise { - await fetch(`${config.apiEndpoint}/products`, { +export async function createProduct(data: CreateProductRequest): Promise { + return fetch(`${config.apiEndpoint}/products`, { method: 'POST', body: JSON.stringify(data), headers: { diff --git a/src/lib/apis/product/get-product.ts b/src/lib/apis/product/get-product.ts index 1663161..65a86a7 100644 --- a/src/lib/apis/product/get-product.ts +++ b/src/lib/apis/product/get-product.ts @@ -8,7 +8,7 @@ export interface ProductGetResponseData { banner_img: string; category: string; description: string; - created_at: string; + created_at?: string; featured_at: string | null; attributes: { id: number; name: string; value: string }[]; metadata: any; @@ -50,10 +50,12 @@ export async function getProductById(id: number): Promise response.json()) - .then((response) => response.data.ipscan_products[0]); + .then((response) => { + return { + ...response.data.ipscan_products[0], + collections: response.data.ipscan_products[0]?.collections?.map((c: any) => c.collection) + }}); } diff --git a/src/routes/(sidebar)/crud/products/+page.ts b/src/routes/(sidebar)/crud/products/+page.ts index a46368d..35ca5f1 100644 --- a/src/routes/(sidebar)/crud/products/+page.ts +++ b/src/routes/(sidebar)/crud/products/+page.ts @@ -7,8 +7,8 @@ import { type ProductGetResponseData } from '$lib/apis/product/get-product'; export interface ProductPageData { mode?: string; product?: ProductGetResponseData; - status: string[]; - selected_status?: string[]; + statuses: string[]; + selected_statuses?: string[]; genres: string[]; selected_genres?: string[]; player_supports: string[]; diff --git a/src/routes/(sidebar)/crud/products/Product.svelte b/src/routes/(sidebar)/crud/products/Product.svelte index 06d05d3..0af03f4 100644 --- a/src/routes/(sidebar)/crud/products/Product.svelte +++ b/src/routes/(sidebar)/crud/products/Product.svelte @@ -29,6 +29,7 @@ export let data: ProductPageData; export let mode: string = PAGE_MODE.CREATE; + export let form: any; const path: string = '/crud/products/create'; $: description = `A place to ${mode} a single product`; @@ -37,6 +38,8 @@ let openDelete: boolean = false; $: isViewMode = mode === PAGE_MODE.VIEW; + + console.log(form); @@ -86,7 +89,7 @@