refactor: permission product service

This commit is contained in:
Methapon Metanipat 2024-09-10 14:36:36 +07:00
parent 67d360c92b
commit ed692c823d
5 changed files with 48 additions and 372 deletions

View file

@ -94,7 +94,7 @@ watch(
hide-bottom-space
input-debounce="0"
:disable="!readonly && disableCode"
class="col-md-3 col-6"
class="col-md-4 col-12"
v-model="code"
id="select-br-id"
option-label="label"
@ -123,7 +123,7 @@ watch(
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
class="col-6"
class="col-md-8 col-12"
:label="$t('productService.product.name')"
v-model="name"
:rules="[(val: string) => !!val || $t('form.error.required')]"

View file

@ -167,58 +167,12 @@ watch(
outlined
:readonly="readonly"
hide-bottom-space
class="col-md-3 col-4"
class="col-md-4 col-12"
:label="$t('productService.service.code')"
v-model="serviceCode"
:rules="[(val: string) => !!val || $t('form.error.required')]"
/>
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
class="col-md-3 col-8"
option-value="id"
option-label="name"
v-model="registeredBranchId"
id="input-source-nationality"
for="input-source-nationality"
:dense="dense"
:readonly="readonly"
:options="branchOptions"
:hide-dropdown-icon="readonly"
:label="$t('productService.service.registeredBranch')"
:rules="[
(val) => {
const roles = getRole() || [];
const isSpecialRole = ['admin', 'system', 'head_of_admin'].some(
(role) => roles.includes(role),
);
return (
isSpecialRole ||
!!val ||
$t('form.error.selectField', {
field: $t('productService.service.registeredBranch'),
})
);
},
]"
@filter="branchFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
id="input-service-name"
for="input-service-name"
@ -226,11 +180,12 @@ watch(
outlined
:readonly="readonly"
hide-bottom-space
class="col-md-6 col"
class="col-md-8 col-12"
:label="$t('productService.service.name')"
v-model="serviceName"
:rules="[(val: string) => !!val || $t('form.error.required')]"
/>
<q-input
id="input-service-description"
for="input-service-description"

View file

@ -70,12 +70,6 @@ const productServiceStore = useProductServiceStore();
const optionStore = useOptionStore();
const {
fetchStatsProductType,
createProductServiceType,
editProductServiceType,
deleteProductServiceType,
fetchListProductServiceType,
fetchStatsProductGroup,
fetchListProductService,
createProductService,
@ -100,8 +94,7 @@ const {
deleteWork,
} = productServiceStore;
const { workNameItems, recordTreeProductType } =
storeToRefs(productServiceStore);
const { workNameItems } = storeToRefs(productServiceStore);
const allStat = ref<{ mode: string; count: number }[]>([]);
const stat = ref<
@ -252,7 +245,6 @@ const formDataGroup = ref<ProductGroupCreate>({
const formDataProduct = ref<ProductCreate>({
expenseType: '',
vatIncluded: true,
registeredBranchId: '',
productGroupId: '',
remark: '',
serviceCharge: 0,
@ -274,7 +266,6 @@ const formDataProductService = ref<ServiceCreate>({
name: '',
code: '',
productGroupId: '',
registeredBranchId: '',
});
const hideStat = ref(false);
@ -473,21 +464,15 @@ const propertiesDialog = ref<boolean>(false);
const totalProduct = ref<number>(0);
const totalService = ref<number>(0);
const totalProductAndService = ref<number>(0);
const filterStat = ref<('group' | 'service' | 'product')[]>([]);
//
const currentPageGroup = ref<number>(1);
const maxPageGroup = ref<number>(1);
const pageSizeGroup = ref<number>(30);
const currentPageType = ref<number>(1);
const maxPageType = ref<number>(1);
const pageSizeType = ref<number>(30);
const maxPageServiceAndProduct = ref<number>(1);
const pageSizeServiceAndProduct = ref<number>(10);
const currentPageServiceAndProduct = ref<number>(1);
const totalType = ref<number>(0);
const totalGroup = ref<number>(0);
const total = ref<number>(0);
@ -559,9 +544,7 @@ async function fetchListOfOptionBranch() {
if (result && result.total > 0) branchOption.value = result.result;
}
formDataProduct.value.registeredBranchId = currentMyBranch.value?.id || '';
formDataProductService.value.registeredBranchId =
currentMyBranch.value?.id || '';
formDataGroup.value.registeredBranchId = currentMyBranch.value?.id || '';
}
async function fetchListGroups() {
@ -878,7 +861,6 @@ const prevService = ref<ServiceCreate>({
name: '',
code: '',
productGroupId: '',
registeredBranchId: '',
});
const currentService = ref<ServiceById>();
@ -902,7 +884,6 @@ async function assignFormDataProductService(id: string) {
work: [],
status: res.status,
productGroupId: res.productGroupId,
registeredBranchId: res.registeredBranchId,
};
formDataProductService.value = { ...prevService.value };
@ -949,7 +930,6 @@ const prevProduct = ref<ProductCreate>({
name: '',
code: '',
image: undefined,
registeredBranchId: '',
});
function assignFormDataProduct(data: ProductList) {
@ -970,7 +950,6 @@ function assignFormDataProduct(data: ProductList) {
name: data.name,
code: data.code,
image: undefined,
registeredBranchId: data.registeredBranchId,
status: data.status,
expenseType: data.expenseType,
vatIncluded: data.vatIncluded,
@ -1003,7 +982,6 @@ function clearFormProduct() {
name: '',
code: '',
image: undefined,
registeredBranchId: '',
expenseType: '',
vatIncluded: true,
};
@ -1026,7 +1004,6 @@ function clearFormService() {
work: [],
status: undefined,
productGroupId: '',
registeredBranchId: '',
};
workItems.value = [];
@ -1060,10 +1037,6 @@ async function submitService() {
if (dialogService.value) {
formDataProductService.value.productGroupId = currentIdGrop.value;
if (formDataProductService.value.registeredBranchId === '') {
formDataProductService.value.registeredBranchId = null;
}
if (
formDataProductService.value.code === '' ||
formDataProductService.value.name === ''
@ -3449,8 +3422,6 @@ watch(productMode, async () => {
>
<BasicInfoProduct
v-if="productTab === 1"
v-model:options-branch="branchOption"
v-model:registered-branch-id="formDataProduct.registeredBranchId"
v-model:detail="formDataProduct.detail"
v-model:remark="formDataProduct.remark"
v-model:name="formDataProduct.name"
@ -3628,8 +3599,6 @@ watch(productMode, async () => {
<BasicInfoProduct
v-if="productTab === 1"
:readonly="!infoProductEdit"
v-model:options-branch="branchOption"
v-model:registered-branch-id="formDataProduct.registeredBranchId"
v-model:detail="formDataProduct.detail"
v-model:remark="formDataProduct.remark"
v-model:name="formDataProduct.name"

View file

@ -18,147 +18,20 @@ import {
Work,
ProductOnWork,
WorkCreate,
ServiceAndProduct,
TreeProduct,
} from './types';
import { computed, ref } from 'vue';
import { ref } from 'vue';
import useFlowStore from '../flow';
import useMyBranchStore from 'stores/my-branch';
const useProductServiceStore = defineStore('api-product-service', () => {
const useMyBranch = useMyBranchStore();
const recordTreeProductType = ref<Record<string, TreeProduct[]>>({});
// Product Type
const flowStore = useFlowStore();
const workNameItems = ref<{ id: string; name: string; isEdit: boolean }[]>(
[],
);
async function fetchStatsProductType() {
const res = await api.get('/product-type/stats');
if (!res) return false;
if (res.status === 200) {
return res.data;
}
}
async function fetchListProductServiceByIdType(groupId: string) {
const res = await api.get<ProductGroup & { productGroupId: string }>(
`/product-type/${groupId}`,
);
if (!res) return false;
if (res.status === 200) {
return res.data;
}
}
async function fetchListProductServiceType(
opts?: {
page?: number;
pageSize?: number;
query?: string;
productGroupId?: string;
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
v !== undefined && params.append(k, v.toString());
}
const query = params.toString();
const res = await api.get<
Pagination<(ProductGroup & { productGroupId: string })[]>
>(`/product-type${(params && '?'.concat(query)) || ''}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
if (res.status === 200) {
if (!!opts?.productGroupId) {
recordTreeProductType.value[opts?.productGroupId] = res.data.result;
}
return res.data;
}
return false;
}
async function createProductServiceType(
id: string,
data: ProductGroupCreate,
) {
const { code, ...payload } = data;
const res = await api.post<ProductGroupCreate & { productGroupId: string }>(
'/product-type',
{
productGroupId: id,
...payload,
},
);
if (!res) return false;
if (res.status === 201) {
return res.data;
}
return false;
}
async function editProductServiceType(
groupId: string,
data: Partial<ProductGroupUpdate & { productGroupId: string }>,
) {
const { code, ...payload } = data;
const res = await api.put<ProductGroupUpdate & { productGroupId: string }>(
`/product-type/${groupId}`,
{
...payload,
},
);
if (!res) return false;
if (res.status === 200) {
return res.data;
}
return false;
}
async function deleteProductServiceType(groupId: string) {
const res = await api.delete(`/product-type/${groupId}`);
if (!res) return false;
if (res.status === 200) {
return res.data;
}
return false;
}
const workNameItems = ref<
{
id: string;
name: string;
isEdit: boolean;
}[]
>([]);
// Product Group
@ -182,19 +55,12 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
}
async function fetchListProductService(
opts?: {
page?: number;
pageSize?: number;
query?: string;
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchListProductService(opts?: {
page?: number;
pageSize?: number;
query?: string;
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
@ -207,9 +73,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
`/product-group${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
'X-Rtid': flowStore.rtid,
},
},
);
@ -291,40 +155,25 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
}
async function fetchListProduct(
opts?: {
query?: string;
page?: number;
pageSize?: number;
productGroupId?: string;
status?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchListProduct(opts?: {
query?: string;
page?: number;
pageSize?: number;
productGroupId?: string;
status?: string;
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
v !== undefined && params.append(k, v.toString());
}
if (useMyBranch.myBranch?.length !== 0 && useMyBranch.myBranch) {
params.append('registeredBranchId', useMyBranch.myBranch[0].id);
}
const query = params.toString();
const res = await api.get<Pagination<ProductList[]>>(
`/product${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
headers: { 'X-Rtid': flowStore.rtid },
},
);
@ -433,39 +282,26 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
}
async function fetchListService(
opts?: {
query?: string;
page?: number;
pageSize?: number;
productGroupId?: string;
status?: string;
},
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
async function fetchListService(opts?: {
query?: string;
page?: number;
pageSize?: number;
productGroupId?: string;
status?: string;
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
v !== undefined && params.append(k, v.toString());
}
if (useMyBranch.myBranch?.length !== 0 && useMyBranch.myBranch) {
params.append('registeredBranchId', useMyBranch.myBranch[0].id);
}
const query = params.toString();
const res = await api.get<Pagination<Service[]>>(
`/service${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
'X-Rtid': flowStore.rtid,
},
},
);
@ -508,11 +344,6 @@ const useProductServiceStore = defineStore('api-product-service', () => {
async function fetchListServiceByIdWork(
serviceId: string,
opts?: { query?: string; page?: number; pageSize?: number },
flow?: {
sessionId?: string;
refTransactionId?: string;
transactionId?: string;
},
) {
const params = new URLSearchParams();
@ -526,9 +357,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
`/service/${serviceId}/work${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
'X-Rtid': flowStore.rtid,
},
},
);
@ -598,19 +427,12 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
// work
async function fetchListWork(
opts?: {
query?: string;
page?: number;
pageSize?: number;
baseOnly?: boolean;
},
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
async function fetchListWork(opts?: {
query?: string;
page?: number;
pageSize?: number;
baseOnly?: boolean;
}) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
@ -623,9 +445,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
Pagination<(Work & { productOnWork: ProductOnWork[] })[]>
>(`/work${(params && '?'.concat(query)) || ''}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
'X-Rtid': flowStore.rtid,
},
});
@ -698,11 +518,6 @@ const useProductServiceStore = defineStore('api-product-service', () => {
async function fetchListProductByIdWork(
workId: string,
opts?: { query?: string; page?: number; pageSize?: number },
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const params = new URLSearchParams();
@ -716,9 +531,7 @@ const useProductServiceStore = defineStore('api-product-service', () => {
`/work/${workId}/product${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
'X-Rtid': flowStore.rtid,
},
},
);
@ -741,60 +554,8 @@ const useProductServiceStore = defineStore('api-product-service', () => {
}
}
async function fetchListProductAndService(
opts?: {
query?: string;
page?: number;
pageSize?: number;
productGroupId?: string;
status?: string;
},
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const params = new URLSearchParams();
for (const [k, v] of Object.entries(opts || {})) {
v !== undefined && params.append(k, v.toString());
}
if (useMyBranch.myBranch?.length !== 0 && useMyBranch.myBranch) {
params.append('registeredBranchId', useMyBranch.myBranch[0].id);
}
const query = params.toString();
const res = await api.get<Pagination<ServiceAndProduct[]>>(
`/product-service${(params && '?'.concat(query)) || ''}`,
{
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId,
},
},
);
if (!res) return false;
if (res.status === 200) {
return res.data;
}
return false;
}
return {
workNameItems,
recordTreeProductType,
fetchStatsProductType,
fetchListProductServiceByIdType,
fetchListProductServiceType,
createProductServiceType,
editProductServiceType,
deleteProductServiceType,
fetchStatsProductGroup,
fetchListProductServiceById,
@ -826,8 +587,6 @@ const useProductServiceStore = defineStore('api-product-service', () => {
fetchListProductByIdWork,
fetchListOfWork,
fetchListProductAndService,
};
});

View file

@ -1,9 +1,5 @@
import { Status } from '../types';
import { Pagination, UpdatedBy, CreatedBy } from 'stores/types';
export type ServiceAndProduct =
| (Service & { type: 'service' })
| (ProductList & { type: 'product' });
import { UpdatedBy, CreatedBy } from 'stores/types';
export interface TreeProduct {
name: string;
@ -63,7 +59,6 @@ export interface ServiceCreate {
image?: File;
status?: Status;
productGroupId: string;
registeredBranchId: string | null;
}
export interface Attributes {
@ -154,13 +149,11 @@ export interface ProductList {
code: string;
id: string;
imageUrl: string;
registeredBranchId: string;
}
export interface ProductCreate {
expenseType: string;
vatIncluded: boolean;
registeredBranchId: string;
productGroupId: string;
remark: string;
serviceCharge: number;