Skip to content

Commit

Permalink
Merge pull request #12 from story2Dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chanthavong authored Dec 17, 2023
2 parents b0938b4 + a6de0f9 commit 21575cf
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 44 deletions.
64 changes: 64 additions & 0 deletions components/term/TermInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<div class="w-full">
<n-select
v-if="type == 'select'"
:options="terms"
value-field="id"
label-field="name"
v-bind="$attrs"
/>
<article v-else-if="type == 'checkbox'">
<n-checkbox-group v-bind="$attrs">
<nav :class="wrapperClass">
<n-checkbox
v-for="(item, index) in terms"
:key="index"
:value="item.id"
:label="item.name"
/>
</nav>
</n-checkbox-group>
</article>
<article v-else-if="type == 'radio'">
<n-radio-group v-bind="$attrs" :name="name">
<nav :class="wrapperClass">
<n-radio
v-for="(item, index) in terms"
:key="index"
:value="item.id"
:label="item.name"
/>
</nav>
</n-radio-group>
</article>
</div>
</template>

<script setup lang="ts">
import type { Term } from '~/types';
interface Props {
groupId: number;
type?: 'select' | 'radio' | 'checkbox';
wrapperClass?: string;
name?: string;
}
const props = withDefaults(defineProps<Props>(), {
type: 'select',
wrapperClass: 'flex flex-wrap gap-2',
name: 'term',
});
const { getTerms } = useTerm();
const terms = ref<Term[]>([]);
const { items } = await getTerms({
where: {
group_id: {
_eq: props.groupId,
},
},
});
terms.value = items;
</script>
2 changes: 1 addition & 1 deletion composables/use-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useApp = () => {
const setting = useState<KeyValue>('app-setting', () => ({}));

const page = ref(1);
const limit = 2;
const limit = 10;
const search = ref('');

return {
Expand Down
116 changes: 116 additions & 0 deletions composables/use-product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { DELETE_PRODUCT, INSERT_PRODUCT, UPDATE_PRODUCT } from '~/gql/mutate';
import { PRODUCTS_QUERY } from '~/gql/query';
import type { Product, ProductInput, Variable } from '~/types';

export const useProduct = () => {
const { client } = useApolloClient();

const frm = useState<Partial<Product>>('frm', () => ({
name: '',
sku: '',
barcode: '',
description: '',
unitPrice: 0,
stockQuantity: 0,
stockTrackable: false,
}));
const count = useState<number>('count', () => 0);

async function getProducts(variables?: Partial<Variable>) {
try {
const { data, errors } = await client.query({
query: PRODUCTS_QUERY,
variables,
});
if (errors) {
throw new Error(`[useProduct]: getProducts errors: ${errors}`);
}
const _count = data?.aggregate?.aggregate?.count || 0;
count.value = _count;
const items: Product[] = data?.products || [];
return {
items,
errors,
};
} catch (error) {
throw new Error(`[useProduct]: getProducts error: ${error}`);
}
}

async function insert(object: ProductInput) {
try {
const { data, errors } = await client.mutate({
mutation: INSERT_PRODUCT,
variables: {
object: toHasuraInput(object),
},
});

if (errors) {
throw new Error(`[insert]: insert errors: ${errors}`);
}

return {
product: data?.insertProduct as Product,
errors,
};
} catch (error) {
throw new Error(`[useProduct]: insert error: ${error}`);
}
}

async function update(id: string, object: Partial<ProductInput>) {
try {
const { data, errors } = await client.mutate({
mutation: UPDATE_PRODUCT,
variables: {
id,
object: toHasuraInput(object),
},
});

if (errors) {
throw new Error(`[update]: update errors: ${errors}`);
}

return {
product: data?.updateProduct as Product,
errors,
};
} catch (error) {
throw new Error(`[useProduct]: update error: ${error}`);
}
}

// remove
async function remove(id: string) {
try {
const { data, errors } = await client.mutate({
mutation: DELETE_PRODUCT,
variables: {
id,
},
});

if (errors) {
throw new Error(`[remove]: remove errors: ${errors}`);
}

return {
product: data?.deleteProduct as Product,
errors,
};
} catch (error) {
throw new Error(`[useProduct]: remove error: ${error}`);
}
}

return {
frm,
count,
getProducts,
insert,
update,
remove,
};
};
1 change: 0 additions & 1 deletion composables/use-term.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TERMS_QUERY } from '~/gql/query';
import { DELETE_TERM, INSERT_TERM, UPDATE_TERM } from '~/gql/mutate';
import type { Term, TermInput, Variable } from '~/types';
import { TermGroupID } from '~/constants';

export const useTerm = () => {
const { client } = useApolloClient();
Expand Down
4 changes: 2 additions & 2 deletions doc-backend/log.logs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ create table if not exists log.logs (
object_id uuid null,
ip inet null,
user_agent character varying null,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);
79 changes: 49 additions & 30 deletions doc-backend/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create function now_utc() returns timestamp as $$
create function now_utc() returns timestamp without time zone as $$
select now() at time zone 'utc';
$$ language sql;

Expand All @@ -7,17 +7,17 @@ create table if not exists terms (
name character varying not null,
group_id int null,
parent_id uuid null references terms(id),
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists term_meta (
id uuid primary key default gen_random_uuid(),
term_id uuid not null references terms(id),
key character varying not null,
value character varying not null,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);


Expand All @@ -28,15 +28,15 @@ create table if not exists accounts (
account_type character varying null,
balance numeric(15,2) not null default 0,
parent_id uuid null references accounts(id),
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists transactions (
id uuid primary key default gen_random_uuid(),
description character varying null,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists transaction_items (
Expand All @@ -45,8 +45,8 @@ create table if not exists transaction_items (
account_id uuid not null references accounts(id),
amount numeric(15,2) not null,
type character varying not null,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists employees (
Expand All @@ -57,16 +57,16 @@ create table if not exists employees (
job_title VARCHAR(100) null,
user_id uuid null references auth.users(id),
department_id uuid null references terms(id),
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists employee_departments (
id uuid primary key default gen_random_uuid(),
employee_id uuid not null references employees(id),
department_id uuid not null references terms(id),
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

create table if not exists employee_salaries (
Expand All @@ -76,8 +76,8 @@ create table if not exists employee_salaries (
from_date DATE NOT NULL,
to_date DATE NOT NULL,
active boolean not null default true,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

-- Inventory Management Module
Expand All @@ -95,17 +95,17 @@ CREATE TABLE products (
type_id uuid null references terms(id),
category_id uuid null references terms(id),
parent_id uuid null references products(id),
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

CREATE TABLE product_data (
id uuid primary key default gen_random_uuid(),
product_id uuid not null references products(id),
key character varying not null,
value character varying not null,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);


Expand All @@ -117,25 +117,44 @@ CREATE TABLE customers (
email VARCHAR(255) NOT NULL,
phone_number VARCHAR(20) NULL,
user_id uuid null references auth.users(id),
created_at timestamp not null default now_utc(),
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);


CREATE TABLE orders (
id uuid primary key default gen_random_uuid(),
customer_id INT REFERENCES customers(customer_id),
customer_id uuid REFERENCES customers(id),
order_date DATE NOT NULL,
total_amount DECIMAL(15, 2) NOT NULL,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
total_cost DECIMAL(15, 2) NOT NULL,
total_tax DECIMAL(15, 2) NOT NULL,
total_discount DECIMAL(15, 2) NOT NULL,
total_profit DECIMAL(15, 2) NOT NULL,
status_id uuid null references terms(id),
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);

CREATE TABLE order_items (
order_item_id SERIAL PRIMARY KEY,
order_id INT REFERENCES orders(order_id),
product_id INT REFERENCES products(id),
id uuid primary key default gen_random_uuid(),
order_id uuid REFERENCES orders(id),
product_id uuid REFERENCES products(id),
quantity INT NOT NULL,
unit_price DECIMAL(15, 2) NOT NULL,
created_at timestamp not null default now_utc(),
updated_at timestamp not null default now_utc()
cost DECIMAL(15, 2) NOT NULL,
tax DECIMAL(15, 2) NOT NULL,
discount DECIMAL(15, 2) NOT NULL,
profit DECIMAL(15, 2) NOT NULL,
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);


create table if not exists term_objects (
id uuid primary key default gen_random_uuid(),
object_id uuid not null,
term_id uuid not null references terms(id),
created_at timestamp without time zone not null default now_utc(),
updated_at timestamp without time zone not null default now_utc()
);
1 change: 1 addition & 0 deletions gql/mutate/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './term-mutate';
export * from './product-mutate';
Loading

0 comments on commit 21575cf

Please sign in to comment.