diff --git a/src/components/ui/NewVnSearchBar.vue b/src/components/ui/NewVnSearchBar.vue index d5b57433..7806b297 100644 --- a/src/components/ui/NewVnSearchBar.vue +++ b/src/components/ui/NewVnSearchBar.vue @@ -53,6 +53,12 @@ const search = async () => { return; } + if (props.searchFn) { + const data = await props.searchFn(searchTerm.value); + emit('onSearch', data); + return; + } + if (props.url) { const params = { filter: props.filter, diff --git a/src/composables/serviceUtils.js b/src/composables/serviceUtils.js index ce124398..d1c27a3c 100644 --- a/src/composables/serviceUtils.js +++ b/src/composables/serviceUtils.js @@ -45,6 +45,8 @@ async function fetch({ }); } + params.filter = params.filter || {}; + if (params.filter?.where || exprFilter) { params.filter.where = { ...params.filter.where, ...exprFilter }; } diff --git a/src/pages/Account/AddressList.vue b/src/pages/Account/AddressList.vue index 9939c926..50bb7de9 100644 --- a/src/pages/Account/AddressList.vue +++ b/src/pages/Account/AddressList.vue @@ -14,7 +14,6 @@ import { storeToRefs } from 'pinia'; import { useUserStore } from 'stores/user'; const router = useRouter(); -const jApi = inject('jApi'); const api = inject('api'); const { notify } = useNotify(); const { t } = useI18n(); @@ -26,32 +25,30 @@ const fetchAddressesRef = ref(null); const addresses = ref([]); const defaultAddress = ref(null); -const clientId = ref(null); const goToAddressDetails = (id = 0) => router.push({ name: 'addressDetails', params: { id } }); const getDefaultAddress = async () => { try { - const [address] = await jApi.query( - 'SELECT id, defaultAddressFk FROM myClient c' - ); - defaultAddress.value = address.defaultAddressFk; - clientId.value = address.id; + const filter = { fields: ['defaultAddressFk'] }; + const { data } = await api.get(`Clients/${userStore?.userId}`, { + params: { filter: JSON.stringify(filter) } + }); + defaultAddress.value = data.defaultAddressFk; } catch (error) { console.error('Error getting default address:', error); } }; -const changeDefaultAddress = async () => { - if (!clientId.value) return; - await jApi.execQuery( - `UPDATE myClient - SET defaultAddressFk = #defaultAddress - WHERE id = #id;`, +const changeDefaultAddress = async address => { + if (!userStore?.userId) return; + + await api.patch( + `/Clients/${userStore?.user?.id}/updateAddress/${address.id}`, { - defaultAddress: defaultAddress.value, - id: clientId.value + ...address, + defaultAddressFk: defaultAddress.value } ); notify(t('defaultAddressModified'), 'positive'); @@ -129,7 +126,7 @@ onMounted(async () => { v-model="defaultAddress" :val="address.id" class="q-mr-sm" - @update:model-value="changeDefaultAddress" + @update:model-value="changeDefaultAddress(address)" /> diff --git a/src/pages/Admin/AccessLogView.vue b/src/pages/Admin/AccessLogView.vue index 45a71af2..47a8f6ed 100644 --- a/src/pages/Admin/AccessLogView.vue +++ b/src/pages/Admin/AccessLogView.vue @@ -7,8 +7,7 @@ import VnList from 'src/components/ui/VnList.vue'; import { formatDateTitle } from 'src/lib/filters.js'; -const jApi = inject('jApi'); - +const api = inject('api'); const route = useRoute(); const accessLogs = ref([]); @@ -17,15 +16,32 @@ const user = ref(null); const getUser = async () => { try { if (!route.params.id) return; - const [data] = await jApi.query( - `SELECT u.id, u.name user, u.nickname, u.email, c.phone, r.name role - FROM account.user u - JOIN account.role r ON r.id = u.role - LEFT JOIN vn.client c ON c.id = u.id - WHERE u.id = #user`, - { user: route.params.id } - ); - user.value = data; + + const filter = { + where: { id: route.params.id }, + include: [ + { + relation: 'role', + scope: { + fields: ['name'] + } + }, + { + relation: 'worker', + scope: { + fields: ['phone'] + } + } + ] + }; + const { data } = await api.get('VnUsers/preview', { + params: { + filter: JSON.stringify(filter) + } + }); + + if (!data || !data.length) return; + user.value = data[0]; } catch (error) { console.error('Error getting user:', error); } @@ -33,16 +49,12 @@ const getUser = async () => { const getAccessLogs = async () => { try { - accessLogs.value = await jApi.query( - `SELECT u.stamp, a.platform, a.browser, a.version, a.javascript, a.cookies - FROM visitUser u - JOIN visitAccess c ON c.id = u.accessFk - JOIN visitAgent a ON a.id = c.agentFk - WHERE u.userFk = #user - ORDER BY u.stamp DESC - LIMIT 8`, - { user: route.params.id } - ); + const { data } = await api.get('visitUsers/getUserVisits', { + params: { + userId: route.params.id + } + }); + accessLogs.value = data; } catch (error) { console.error('Error getting access logs:', error); } @@ -68,9 +80,9 @@ onMounted(async () => { {{ user?.nickname }} #{{ user?.id }} - {{ user.user }} - {{ user?.role }} + {{ user?.role?.name }} {{ user?.email }} - {{ user?.phone }} + {{ user?.worker?.phone }} diff --git a/src/pages/Ecomerce/CatalogView.vue b/src/pages/Ecomerce/CatalogView.vue index 92a63858..714bc47c 100644 --- a/src/pages/Ecomerce/CatalogView.vue +++ b/src/pages/Ecomerce/CatalogView.vue @@ -1,308 +1,3 @@ - - - - { - items = []; - search = ''; - } - " - /> - - - {{ viewTypeButtonContent.label }} - - - - - {{ t('shoppingCart') }} - - - - - - - - - - {{ order.nickname }} - - {{ - formatDateTitle(order.sent, { - shortDay: true, - shortMonth: true, - includeOfString: true - }) - }} - - - {{ t('modify') }} - - - - - {{ t('category') }} - - - - - - {{ cat.name }} - - - - - - {{ t('filterBy') }} - - - - - - - - {{ t('orderBy') }} - - - - - {{ t('chooseCategory') }} - - - - - - - {{ t('pleaseSetFilter') }} - - - - - - - - - - - {{ selectedItem.item }} - - - {{ selectedItem.subName }} - - - #{{ selectedItem.id }} - - - - - - {{ tag.name }} - - {{ tag.value }} - - - - - - {{ t('minQuantity') }} - - - {{ - selectedItem.minQuantity - }} - - - - - - {{ currency(lot.price) }} - x{{ lot.grouping }} - - {{ t('add') }} - - - - - - {{ t('delete') }} - - {{ amount }} - - {{ t('confirm') }} - - - - - - - - + + + + { + items = []; + search = ''; + } + " + /> + + + {{ viewTypeButtonContent.label }} + + + + + {{ t('shoppingCart') }} + + + + + + + + + + {{ order.nickname }} + + {{ + formatDateTitle(order.sent, { + shortDay: true, + shortMonth: true, + includeOfString: true + }) + }} + + + {{ t('modify') }} + + + + + {{ t('category') }} + + + + + + {{ cat.name }} + + + + + + {{ t('filterBy') }} + + + + + + + + {{ t('orderBy') }} + + + + + {{ t('chooseCategory') }} + + + + + + + {{ t('pleaseSetFilter') }} + + + + + + + + + + + {{ selectedItem.name }} + + + {{ selectedItem.subName }} + + + #{{ selectedItem.id }} + + + + + + {{ tag.name }} + + {{ tag.value }} + + + + + + {{ t('minQuantity') }} + + + {{ + selectedItem.minQuantity + }} + + + + + + {{ currency(lot.price) }} + x{{ lot.grouping }} + + {{ t('add') }} + + + + + + {{ t('delete') }} + + {{ amount }} + + {{ t('confirm') }} + + + + + + + +