diff --git a/frontend/src/api/endpoint.ts b/frontend/src/api/endpoint.ts index adbc0e4..b7e151b 100644 --- a/frontend/src/api/endpoint.ts +++ b/frontend/src/api/endpoint.ts @@ -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' diff --git a/frontend/src/api/models/address.ts b/frontend/src/api/models/address.ts index 84e4fed..4cdbbde 100644 --- a/frontend/src/api/models/address.ts +++ b/frontend/src/api/models/address.ts @@ -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; } diff --git a/frontend/src/api/models/order.ts b/frontend/src/api/models/order.ts index 9969cc8..9c4a310 100644 --- a/frontend/src/api/models/order.ts +++ b/frontend/src/api/models/order.ts @@ -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; @@ -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; } diff --git a/frontend/src/api/request.ts b/frontend/src/api/request.ts index 6848eda..a34a255 100644 --- a/frontend/src/api/request.ts +++ b/frontend/src/api/request.ts @@ -22,7 +22,8 @@ import { exportDumpsPath, getAllOrdersPath, getAllServicesPath, - updateOrdersPath + updateOrdersPath, + createOrderPath } from './endpoint' import Order from './models/order' import Service from './models/service' @@ -104,47 +105,23 @@ export function deleteUser(id: string): Promise { } export async function getClientAddresses(id: string): Promise { - 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
{ - 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
(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
{ @@ -246,7 +223,7 @@ export async function getAllOrders(id: string | null): Promise { } export async function updateOrder(newOrder: Order): Promise { - return axios.put(baseURL + updateOrdersPath(newOrder.id), newOrder) + return axios.put(baseURL + updateOrdersPath(newOrder.id!), newOrder) .then((response) => { return response.data }) @@ -282,3 +259,22 @@ export async function filterOrder(filterData: FilterOrder): Promise { }) } +export async function createOrder(newOrder: Order): Promise { + return axios.post(baseURL + createOrderPath, newOrder) + .then((response) => { + return Promise.resolve(response.data) + }) + .catch((error) => { + return Promise.reject(error) + }) +} + +export async function getOrderById(id: string): Promise { + return axios.get(baseURL + updateOrdersPath(id)) + .then((response) => { + return Promise.resolve(response.data) + }) + .catch((error) => { + return Promise.reject(error) + }) +} \ No newline at end of file diff --git a/frontend/src/components/admin/AdminMainPage.vue b/frontend/src/components/admin/AdminMainPage.vue index e1734e2..1f88922 100644 --- a/frontend/src/components/admin/AdminMainPage.vue +++ b/frontend/src/components/admin/AdminMainPage.vue @@ -1,21 +1,7 @@ diff --git a/frontend/src/components/client/ClientCreateOrderPage.vue b/frontend/src/components/client/ClientCreateOrderPage.vue index 607d5af..f22af85 100644 --- a/frontend/src/components/client/ClientCreateOrderPage.vue +++ b/frontend/src/components/client/ClientCreateOrderPage.vue @@ -5,6 +5,12 @@ import ActionButton from '../../ui/uikit/ActionButton.vue' import Step1 from '../createOrderStep/ContactInfo.vue' import Step2 from '../createOrderStep/AppartmentInfo.vue' import Step3 from '../createOrderStep/ServiceInfo.vue' +import { createOrder, getUserInfo } from '../../api/request' +import Order from '../../api/models/order' +import Service from '../../api/models/service' +import { useRouter } from 'vue-router' + +const router = useRouter(); const currentStep: Ref = ref(1) const steps: any = { @@ -13,15 +19,88 @@ const steps: any = { 3: Step3, } const currentStepComponent = computed(() => steps[currentStep.value]) +const currentPrice = ref(0) +const isFormValid = ref(false) +const userId = ref('') +const appartmentData = ref({ + rooms: 0, + bathrooms: 0, + area: 0, + pollution: 0, + comment: "", +}) +const addressData = ref({ + city: "", + street: "", + building: "", + entrance: "", + floor: "", + doorNumber: "", + date: new Date(""), + time: "" +}) +const selectedServices = ref([]) function changeStep(): void { if (currentStep.value >= 3) { - // create order - // redirect to order history + getUserInfo('me').then((user) => { + userId.value = user.id + const [hours, minutes] = addressData.value.time.split(':').map(Number) + const dateWithTime = new Date(addressData.value.date) + dateWithTime.setHours(hours) + dateWithTime.setMinutes(minutes) + const requiredWorkers = Math.max( + ...selectedServices.value.map((service) => service.workers_quantity) + ) + const newOrder: Order = { + user_id: userId.value, + address: { + city: addressData.value.city, + street: addressData.value.street, + building: addressData.value.building, + entrance: addressData.value.entrance, + floor: addressData.value.floor, + door_number: addressData.value.doorNumber, + }, + date_time: dateWithTime, + area: appartmentData.value.area, + number_of_rooms: appartmentData.value.rooms, + number_of_bathrooms: appartmentData.value.bathrooms, + pollution: appartmentData.value.pollution, + comment: appartmentData.value.comment, + price: currentPrice.value, + required_workers: requiredWorkers, + services: selectedServices.value.map((service) => service.id), + } + createOrder(newOrder).then(() => { + router.push({ name: 'client-orders-history' }) + }) + }) } else { currentStep.value += 1; + isFormValid.value = false } } + +function updateFormValidity(isValid: boolean): void { + isFormValid.value = isValid +} + +function updateAppartmentData(data: any): void { + appartmentData.value = data; + +} +function updateAddressData(data: any): void { + addressData.value = data; +} + +function updatePrice(num: number): void { + currentPrice.value = num +} + +function updateSelectedServices(services: Service[]): void { + selectedServices.value = services; +} diff --git a/frontend/src/components/client/ClientOrdersHistoryPage.vue b/frontend/src/components/client/ClientOrdersHistoryPage.vue index dc8be20..adefb5e 100644 --- a/frontend/src/components/client/ClientOrdersHistoryPage.vue +++ b/frontend/src/components/client/ClientOrdersHistoryPage.vue @@ -6,7 +6,7 @@ import OrderItem from '../../ui/uikit/items/OrderItem.vue' import ActionButton from '../../ui/uikit/ActionButton.vue' import DateFilter from '../../ui/uikit/DateFilter.vue' import MainContainer from '../../ui/uikit/containers/MainContainer.vue' -import { getAllOrders, getUserInfo } from '../../api/request' +import { getAllOrders } from '../../api/request' import Order from '../../api/models/order' const orders = ref([]) @@ -54,18 +54,4 @@ onMounted(() => { diff --git a/frontend/src/components/createOrderStep/AppartmentInfo.vue b/frontend/src/components/createOrderStep/AppartmentInfo.vue index b93949b..c43b88f 100644 --- a/frontend/src/components/createOrderStep/AppartmentInfo.vue +++ b/frontend/src/components/createOrderStep/AppartmentInfo.vue @@ -1,7 +1,38 @@