Skip to content

Commit

Permalink
Merge pull request #113 from moevm/102-fix-notes
Browse files Browse the repository at this point in the history
102 fix notes
  • Loading branch information
1that authored Dec 20, 2024
2 parents 21ace7a + d952b5d commit deff478
Show file tree
Hide file tree
Showing 18 changed files with 449 additions and 179 deletions.
1 change: 1 addition & 0 deletions frontend/src/api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export const uploadDumpsPath = '/v1/dumps'
export const exportDumpsPath = '/v1/dumps'
export const getAllOrdersPath = '/v1/orders'
export const updateOrdersPath = (id: string) => `/v1/orders/${id}`
export const createOrderPath = '/v1/orders'
export const getAllServicesPath = '/v1/services'
4 changes: 2 additions & 2 deletions frontend/src/api/models/address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
interface Address {
id: string;
id?: string;
city: string;
street: string;
building: string;
entrance: string;
floor: string;
door_number: string;
created_at: Date;
created_at?: Date;
updated_at?: Date;
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/api/models/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Address from "./address";
import StatusLog from "./statuslog";

interface Order {
id: string;
id?: string;
user_id: string;
address: Address;
date_time: Date;
Expand All @@ -12,12 +12,12 @@ interface Order {
pollution: number;
area: number;
comment: string;
status: string;
status_logs: StatusLog[];
status?: string;
status_logs?: StatusLog[];
services: string[];
required_workers: number;
workers: string[];
created_at: Date;
workers?: string[];
created_at?: Date;
updated_at?: Date;
}

Expand Down
76 changes: 36 additions & 40 deletions frontend/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
exportDumpsPath,
getAllOrdersPath,
getAllServicesPath,
updateOrdersPath
updateOrdersPath,
createOrderPath
} from './endpoint'
import Order from './models/order'
import Service from './models/service'
Expand Down Expand Up @@ -104,47 +105,23 @@ export function deleteUser(id: string): Promise<any> {
}

export async function getClientAddresses(id: string): Promise<Address[]> {
try {
const response = await fetch(baseURL+getClientAddressesPath(id), {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error(`Error HTTP: ${response.status}`);
}

const data = (await response.json()) as Address[];
return data;
} catch (error) {
console.error('Error request:', error);
throw error;
}
return axios.get(baseURL + getClientAddressesPath(id))
.then((response) => {
return Promise.resolve(response.data)
})
.catch((error) => {
return Promise.reject(error)
})
}

export async function createNewAddress(id: string, addressData: Address): Promise<Address> {
try {
const response = await fetch(baseURL+createNewAddressPath(id), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(addressData),
});

if (!response.ok) {
throw new Error(`Error HTTP: ${response.status}`);
}

const data = await response.json();
return data.id;

} catch (error) {
console.error('Error request:', error);
throw error;
}
return axios.post<Address>(baseURL + createNewAddressPath(id), addressData)
.then((response) => {
return Promise.resolve(response.data)
})
.catch((error) => {
return Promise.reject(error)
})
}

export function getClientAddress(id: string, address_id: string): Promise<Address> {
Expand Down Expand Up @@ -246,7 +223,7 @@ export async function getAllOrders(id: string | null): Promise<Order[]> {
}

export async function updateOrder(newOrder: Order): Promise<Order> {
return axios.put<Order>(baseURL + updateOrdersPath(newOrder.id), newOrder)
return axios.put<Order>(baseURL + updateOrdersPath(newOrder.id!), newOrder)
.then((response) => {
return response.data
})
Expand Down Expand Up @@ -282,3 +259,22 @@ export async function filterOrder(filterData: FilterOrder): Promise<Order[]> {
})
}

export async function createOrder(newOrder: Order): Promise<Order> {
return axios.post<Order>(baseURL + createOrderPath, newOrder)
.then((response) => {
return Promise.resolve(response.data)
})
.catch((error) => {
return Promise.reject(error)
})
}

export async function getOrderById(id: string): Promise<Order> {
return axios.get(baseURL + updateOrdersPath(id))
.then((response) => {
return Promise.resolve(response.data)
})
.catch((error) => {
return Promise.reject(error)
})
}
16 changes: 1 addition & 15 deletions frontend/src/components/admin/AdminMainPage.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
<script setup lang="ts">
import { inject, onMounted } from 'vue'
import { RouterView } from 'vue-router'
import { getUserInfo, getUsers } from '../../api/request'
import { ref } from 'vue'
import { User } from '../../api/models/user'
// const userStore = useUserStore()
// const user = userStore.getUser()
const clients = ref<User[]>([]);
const workers = ref<User[]>([]);
const headers = [
{ text: 'ID', value: 'id' },
{ text: 'Имя', value: 'name' },
{ text: 'Email', value: 'email' },
// Добавьте другие заголовки по мере необходимости
];
import { getUserInfo } from '../../api/request'
const addSideBarButtons: Function | undefined = inject('addSideBarButtons')
const setUserCard: Function | undefined = inject('setUserCard')
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/admin/AdminOrdersPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ onMounted(() => {
<HeaderList
title="Заказы"
:items="orders"
height="100%"
height="92%"
width="95%"
>
<template #items="{ item }">
Expand Down
53 changes: 19 additions & 34 deletions frontend/src/components/client/ClientAddressesPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import MainContainer from '../../ui/uikit/containers/MainContainer.vue'
import Dialog from '../../ui/uikit/Dialog.vue'
import ActionButton from '../../ui/uikit/ActionButton.vue'
import InputTextField from '../../ui/uikit/inputs/InputTextField.vue'
import { getClientAddresses, createNewAddress } from '../../api/request'
import { getClientAddresses, createNewAddress, getUserInfo } from '../../api/request'
import Address from '../../api/models/address'
onMounted(() => {
fetchClientAddresses("me")
getUserInfo('me')
.then((user) => {
getClientAddresses(user.id)
.then((response) => {
addresses.value = response
})
})
})
const addresses = ref<Address[]>([])
Expand All @@ -33,49 +39,28 @@ function closeDialog(): void {
isDialogVisible.value = false
}
function formatAddress(item: any): string {
return `${item.city}, ${item.street}, ${item.building}, Подъезд ${item.entrance}, Этаж ${item.floor}, Квартира ${item.door_number}`;
}
async function fetchClientAddresses(clientId: string) {
getClientAddresses(clientId)
.then((response) => {
addresses.value = response
})
.catch((error) => {
console.error("Failed to fetch client addresses:", error)
function submitNewAddress(): void {
getUserInfo('me').then((userId) => {
addNewAddress(userId.id)
})
}
async function addNewAddress(clientId: string) {
function addNewAddress(clientId: string) {
closeDialog()
const addressData: Address = {
id: clientId.toString(),
city: newAddress.value.city,
street: newAddress.value.street,
building: newAddress.value.building,
entrance: newAddress.value.entrance,
floor: newAddress.value.floor,
door_number: newAddress.value.door_number,
created_at: new Date(),
updated_at: new Date()
};
addresses.value.push(addressData);
}
createNewAddress(clientId, addressData)
.then((newAddressId) => {
/* раскомментировать после добавления авторизации
addresses.value.push({
...addressData,
id: newAddressId
});
*/
})
.catch((error) => {
console.error("Failed to createNewAddress:", error)
// addresses.value.pop() раскомментировать после добавления авторизации
.then((response) => {
addresses.value.push(addressData)
})
}
</script>

<template>
Expand All @@ -87,7 +72,7 @@ async function addNewAddress(clientId: string) {
width="95%"
>
<template #items="{ item }">
<AddressItem :address="formatAddress(item)" />
<AddressItem :address="item" />
</template>
</HeaderList>
</MainContainer>
Expand Down Expand Up @@ -119,7 +104,7 @@ async function addNewAddress(clientId: string) {
<InputTextField
v-model="newAddress.building"
placeholder="Дом"
type="number"
type="text"
label="Дом"
></InputTextField>
<InputTextField
Expand Down Expand Up @@ -154,7 +139,7 @@ async function addNewAddress(clientId: string) {
type="create"
variant="flat"
color="#394cc2"
@click="addNewAddress"
@click="submitNewAddress"
></ActionButton>
</template>
</Dialog>
Expand Down
Loading

0 comments on commit deff478

Please sign in to comment.