Skip to content

Commit

Permalink
fix: CI/CD docker build, graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
HungLV46 committed Aug 15, 2024
1 parent 206b990 commit 5685051
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .env.public
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PUBLIC_GRAPHQL_ENDPOINT="https://graphql.dev.seekhype.io/v1/graphql"
PUBLIC_API_ENDPOINT="https://ip.dev.aurascan.io"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
.env
.env.*
!.env.example
!.env.public
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/test-results
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"]
CMD ["node", "-r", "dotenv/config", "/app/build/index.js"]
16 changes: 8 additions & 8 deletions src/lib/apis/product/create-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
await fetch(`${config.apiEndpoint}/products`, {
export async function createProduct(data: CreateProductRequest): Promise<Response> {
return fetch(`${config.apiEndpoint}/products`, {
method: 'POST',
body: JSON.stringify(data),
headers: {
Expand Down
18 changes: 12 additions & 6 deletions src/lib/apis/product/get-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,10 +50,12 @@ export async function getProductById(id: number): Promise<ProductGetResponseData
id
name
}
collections {
id
chain_id
contract_address
collections: product_collections {
collection {
id
chain_id
contract_address
}
}
}
}
Expand All @@ -68,5 +70,9 @@ export async function getProductById(id: number): Promise<ProductGetResponseData
})
})
.then((response) => 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)
}});
}
4 changes: 2 additions & 2 deletions src/routes/(sidebar)/crud/products/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
13 changes: 8 additions & 5 deletions src/routes/(sidebar)/crud/products/Product.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -37,6 +38,8 @@
let openDelete: boolean = false;
$: isViewMode = mode === PAGE_MODE.VIEW;
console.log(form);
</script>

<MetaTag {path} {description} {title} {subtitle} />
Expand Down Expand Up @@ -86,7 +89,7 @@
<Select
class="w-22 me-4"
items={PRODUCT_CATEGORIES.map((c) => ({ name: c, value: c }))}
selected={data.product?.category}
selected={data.product?.category || ''}
selectProps={{
name: 'category',
disabled: isViewMode
Expand Down Expand Up @@ -211,8 +214,8 @@
name="Status"
placeholder="e.g. Ethereum"
class="mb-2 me-4 mt-3 w-full"
items={data.status}
selected={data.selected_status}
items={data.statuses}
selected={data.selected_statuses}
multiSelectProps={{
name: 'statuses',
allowUserOptions: 'append',
Expand All @@ -223,8 +226,8 @@
name="Player info"
placeholder="e.g. Ethereum"
class="mb-2 me-4 mt-3 w-full"
items={data.status}
selected={data.selected_status}
items={data.player_supports}
selected={data.selected_player_supports}
multiSelectProps={{
name: 'players_infos',
allowUserOptions: 'append',
Expand Down
8 changes: 4 additions & 4 deletions src/routes/(sidebar)/crud/products/[id]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export async function load(pageLoadEvent): Promise<ProductPageData> {
return {
mode: pageLoadEvent.url.searchParams.get('mode') as string,
product,
status: nameToValues['status']?.map((v) => v.value),
selected_status: selectedNameToValues['status']?.map((v) => v.value),
genres: nameToValues['player support']?.map((v) => v.value),
selected_genres: selectedNameToValues['player support']?.map((v) => v.value),
statuses: nameToValues['status']?.map((v) => v.value),
selected_statuses: selectedNameToValues['status']?.map((v) => v.value),
genres: nameToValues['genre']?.map((v) => v.value),
selected_genres: selectedNameToValues['genre']?.map((v) => v.value),
player_supports: nameToValues['player support']?.map((v) => v.value),
selected_player_supports: selectedNameToValues['player support']?.map((v) => v.value),
game_modes: nameToValues['game mode']?.map((v) => v.value),
Expand Down
30 changes: 19 additions & 11 deletions src/routes/(sidebar)/crud/products/create/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { createProduct } from '$lib/apis/product/create-product';
import { fail, redirect } from '@sveltejs/kit';

export const actions = {
default: async ({ cookies, request }) => {
default: async ({ request }) => {
const data = await request.formData();
console.log(data);

const requestData = {
banner_img: data.get('banner_img') as string,
avatar_img: data.get('avatar_img') as string,
banner_img: data.get('banner_img') as string, // TODO upload banner
avatar_img: data.get('avatar_img') as string, // TODO upload img
name: data.get('name') as string,
featured_at: new Date().toISOString(),
featured: data.get('featured') === 'true',
category: data.get('category') as string,
collections: JSON.parse(data.get('collections') as string),
description: data.get('about') as string,
owner: { id: 1 }, // TODO get users
metadata: JSON.stringify({
owner_id: 1, // TODO get users
metadata: {
// previews: data.get("previews"), TODO upload then use url
previews: JSON.parse(data.get('previews') as string).map(() => 'http://demmo.jjj'),
cta_url: data.get('cta_url')
}), // TODO use object instead
cta_url: data.get('cta_url') || undefined
},
attributes: [
...JSON.parse(data.get('statuses') as string).map((value: string) => ({
name: 'status',
Expand All @@ -38,7 +38,15 @@ export const actions = {
}))
]
};
console.log(JSON.stringify(requestData));
await createProduct(requestData);

const createResponse = await createProduct(requestData);

const responseData = await createResponse.json();

if (createResponse.status === 200) {
throw redirect(303, `/crud/products/${responseData.data.id}`);
} else {
return fail(responseData.statusCode, responseData);
}
}
};
4 changes: 2 additions & 2 deletions src/routes/(sidebar)/crud/products/create/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function load(): Promise<ProductPageData> {
attributes: [],
collections: []
},
status: nameToValues['status']?.map((v) => v.value),
genres: nameToValues['player support']?.map((v) => v.value),
statuses: nameToValues['status']?.map((v) => v.value),
genres: nameToValues['genre']?.map((v) => v.value),
player_supports: nameToValues['player support']?.map((v) => v.value),
game_modes: nameToValues['game mode']?.map((v) => v.value)
};
Expand Down

0 comments on commit 5685051

Please sign in to comment.