Skip to content

Commit

Permalink
improve(ui): add product unit and docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
chanthavong committed Dec 30, 2023
1 parent f134b16 commit 62f7566
Show file tree
Hide file tree
Showing 16 changed files with 1,409 additions and 1,242 deletions.
1 change: 1 addition & 0 deletions constants/app-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum TermGroupID {
paymentMethod = 6,
projectStatus = 7,
productType = 8,
productUnit = 9,
}

export enum SORT_MODE {
Expand Down
8 changes: 7 additions & 1 deletion doc-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ AUTH_WEBAUTHN_RP_ORIGINS=
AUTH_LOG_LEVEL=info

# JWT
AUTH_JWT_CUSTOM_CLAIMS=
AUTH_JWT_CUSTOM_CLAIMS=

STORAGE_ACCESS_KEY=
STORAGE_SECRET_KEY=
STORAGE_BUCKET=
STORAGE_ENDPOINT=https://s3-ap-southeast-1.amazonaws.com
STORAGE_REGION=ap-southeast-1
2 changes: 2 additions & 0 deletions doc-backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
.env
140 changes: 121 additions & 19 deletions doc-backend/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,158 @@
version: '3.6'
services:
traefik:
image: "traefik:v2.5"
container_name: "traefik"
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:1337"
ports:
- "1337:1337"
- "9090:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
postgres:
image: postgres:15.0
image: postgres
restart: always
volumes:
- ./docker/data/db:/var/lib/postgresql/data
- ./docker/initdb.d:/docker-entrypoint-initdb.d:ro
- ./data/db:/var/lib/postgresql/data
- ./initdb.d:/docker-entrypoint-initdb.d:ro
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-secretpgpassword}
ports:
- '5432:5432'
graphql-engine:
image: hasura/graphql-engine:v2.35.0
image: hasura/graphql-engine:latest
depends_on:
- postgres
- 'postgres'
restart: always
expose:
- 8080
ports:
- '8080:8080'
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD:-secretpgpassword}@postgres:5432/postgres
HASURA_GRAPHQL_JWT_SECRET: ${HASURA_GRAPHQL_JWT_SECRET}
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: public
HASURA_GRAPHQL_LOG_LEVEL: debug
HASURA_GRAPHQL_ENABLE_CONSOLE: 'true'
ports:
- '8080:8080'
hasura-auth:
image: nhost/hasura-auth:latest
HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION: 'hasura-default'
HASURA_GRAPHQL_EXPERIMENTAL_FEATURES: 'naming_convention'
labels:
- "traefik.enable=true"
- "traefik.http.routers.hasura.rule=Host(`localhost`) && PathPrefix(`/`)"
- "traefik.http.routers.hasura.entrypoints=web"
auth:
image: nhost/hasura-auth
depends_on:
- postgres
- graphql-engine
restart: always
volumes:
- ./emails:/app/email-templates
env_file:
- .env
environment:
AUTH_HOST: '0.0.0.0'
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:${POSTGRES_PASSWORD:-secretpgpassword}@postgres:5432/postgres
HASURA_GRAPHQL_GRAPHQL_URL: http://graphql-engine:8080/v1/graphql
HASURA_GRAPHQL_JWT_SECRET: ${HASURA_GRAPHQL_JWT_SECRET}
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
AUTH_CLIENT_URL: ${AUTH_CLIENT_URL:-http://localhost:3001}
AUTH_PORT: 4000
AUTH_SMTP_HOST: mailhog
AUTH_SMTP_PORT: 1025
AUTH_SMTP_USER: user
AUTH_SMTP_PASS: password
AUTH_SMTP_SENDER: [email protected]
expose:
- 4000
ports:
- '4000:4000'
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.strip-auth.stripprefix.prefixes=/v1/auth"
- "traefik.http.routers.auth.rule=Host(`localhost`) && PathPrefix(`/v1/auth`)"
- "traefik.http.routers.auth.middlewares=strip-auth@docker"
- "traefik.http.routers.auth.entrypoints=web"
storage:
image: nhost/hasura-storage:0.4.0
depends_on:
- postgres
- graphql-engine
- minio
restart: always
expose:
- 8000
ports:
- '8000:8000'
environment:
PUBLIC_URL: http://localhost:${PROXY_PORT:-1337}
HASURA_METADATA: 1
HASURA_ENDPOINT: http://graphql-engine:8080/v1
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
S3_ACCESS_KEY: ${STORAGE_ACCESS_KEY}
S3_SECRET_KEY: ${STORAGE_SECRET_KEY}
S3_ENDPOINT: http://minio:8484
S3_BUCKET: nhost
POSTGRES_MIGRATIONS: 1
POSTGRES_MIGRATIONS_SOURCE: postgres://postgres:${POSTGRES_PASSWORD:-secretpgpassword}@postgres:5432/postgres?sslmode=disable
labels:
- "traefik.enable=true"
- "traefik.http.routers.storage.rule=Host(`localhost`) && PathPrefix(`/v1/storage`)"
- "traefik.http.routers.storage.entrypoints=web"
# Rewrite the path so it matches with the new storage API path introduced in hasura-storage 0.2
- "traefik.http.middlewares.strip-suffix.replacepathregex.regex=^/v1/storage/(.*)"
- "traefik.http.middlewares.strip-suffix.replacepathregex.replacement=/v1/$$1"
- "traefik.http.routers.storage.middlewares=strip-suffix@docker"
command: serve
functions:
image: nhost/functions:0.1.8
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.strip-functions.stripprefix.prefixes=/v1/functions"
- "traefik.http.routers.functions.rule=Host(`localhost`) && PathPrefix(`/v1/functions`)"
- "traefik.http.routers.functions.middlewares=strip-functions@docker"
- "traefik.http.routers.functions.entrypoints=web"
restart: always
expose:
- 3000
volumes:
- .:/opt/project
- functions_node_modules:/opt/project/node_modules
- /opt/project/data/
- /opt/project/initdb.d/
minio:
image: minio/minio:RELEASE.2021-09-24T00-24-24Z
entrypoint: sh
command: -c 'mkdir -p /data/nhost && /opt/bin/minio server --address :8484 /data'
environment:
MINIO_ROOT_USER: ${STORAGE_ACCESS_KEY}
MINIO_ROOT_PASSWORD: ${STORAGE_SECRET_KEY}
ports:
- ${MINIO_PORT:-8484}:8484
volumes:
- ./email-templates:/app/email-templates
- ./data/minio:/data
mailhog:
image: mailhog/mailhog
environment:
SMTP_HOST: mailhog
SMTP_PORT: 1025
SMTP_PASS: ${AUTH_SMTP_PASS}
SMTP_USER: ${AUTH_SMTP_USER}
SMTP_SECURE: '${AUTH_SMTP_SECURE}'
SMTP_SENDER: ${AUTH_SMTP_SENDER}
SMTP_HOST: ${AUTH_SMTP_HOST:-mailhog}
SMTP_PORT: ${AUTH_SMTP_PORT:-1025}
SMTP_PASS: ${AUTH_SMTP_PASS:-password}
SMTP_USER: ${AUTH_SMTP_USER:-user}
SMTP_SECURE: "${AUTH_SMTP_SECURE:-false}"
SMTP_SENDER: ${AUTH_SMTP_SENDER:[email protected]}
ports:
- 1025:1025 # smtp server
- 8025:8025 # web ui
- ${AUTH_SMTP_PORT:-1025}:1025
- 8025:8025
volumes:
- ./docker/data/mailhog:/maildir
- ./data/mailhog:/maildir
# dashboard:
# image: nhost/dashboard:0.7.4
# ports:
# - "3030:3000"
volumes:
functions_node_modules:
12 changes: 12 additions & 0 deletions doc-backend/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "functions",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
11 changes: 11 additions & 0 deletions doc-backend/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"isolatedModules": true,
"strictNullChecks": false
}
}
1 change: 1 addition & 0 deletions doc-backend/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ CREATE TABLE products (
thumbnail character varying null,
type_id uuid null references terms(id),
category_id uuid null references terms(id),
unit_id uuid null references terms(id),
parent_id uuid null references products(id),
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
Expand Down
7 changes: 7 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
"no_data": "No data",
"sign_out": "Sign out",
"type": "Type",
"unit": "Unit",
"success": "Success",
"error": "Error",
"warning": "Warning",
"info": "Info",
"confirm": "Confirm",
"confirm_delete": "Are you sure to delete?",
"confirm_delete_multiple": "Are you sure to delete all selected items?",
"auth": {
"invalid_credentials": "Invalid credentials",
"signin_failed": "Sign in failed",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
"vue-router": "^4.2.5"
},
"dependencies": {
"echarts": "^5.3"
"echarts": "^5.2.0"
}
}
4 changes: 4 additions & 0 deletions pages/products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const links = [
to: '/products/type',
name: 'type',
},
{
to: '/products/unit',
name: 'unit',
},
{
to: '/products/tag',
name: 'tag',
Expand Down
13 changes: 12 additions & 1 deletion pages/products/add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
</n-form-item>
</div>

<div class="grid grid-cols-2 gap-4">
<div class="grid grid-cols-3 gap-4">
<n-form-item path="category" :label="$t('unit')">
<TermInput
v-model:value="frm.unitId"
:placeholder="$t('unit')"
:group-id="TermGroupID.productUnit"
/>
</n-form-item>
<n-form-item path="category" :label="$t('category')">
<TermInput
v-model:value="frm.categoryId"
Expand Down Expand Up @@ -150,6 +157,7 @@ function handleAdd() {
stockTrackable = false,
name = '',
cost = 0,
unitId,
} = frm.value;
const { errors, product } = await insert({
categoryId,
Expand All @@ -162,19 +170,22 @@ function handleAdd() {
stockQuantity,
stockTrackable,
cost,
unitId,
});
if (!errors) {
notification.success({
title: t('success'),
description: t('products.add_success'),
duration: 3000,
});
useRouter().push(`/products/${product.id}`);
return;
}
notification.error({
title: t('fail'),
description: t('products.add_success'),
duration: 3000,
});
throw new Error(`Add product failed: ${errors}`);
}
Expand Down
13 changes: 13 additions & 0 deletions pages/products/unit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
<TermTable :group-id="TermGroupID.productUnit" />
</div>
</template>

<script setup lang="ts">
import { TermGroupID } from '~/constants';
useHead({
title: 'Unit',
});
</script>
2 changes: 1 addition & 1 deletion pages/signin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
show-password-on="mousedown"
>
<template #prefix>
<Icon name="system-uicons:mail" />
<Icon name="system-uicons:lock" />
</template>
</n-input>

Expand Down
1 change: 1 addition & 0 deletions types/Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Product extends BaseModel {
stockTrackable: boolean;
typeId?: string;
categoryId?: string;
unitId?: string;
parentId?: string;
thumbnail?: string;
cost?: number;
Expand Down
Loading

0 comments on commit 62f7566

Please sign in to comment.