Skip to content

Commit

Permalink
fix: model booking
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekitech committed Apr 2, 2024
1 parent 6a35f7c commit d339872
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 115 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
doc_build:
docker-compose up -d --build --wait
watch:
docker compose watch
i:
npm i --legacy-peer-deps --save
docker compose watch
2 changes: 1 addition & 1 deletion src/app/context/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, Dispatch, ReactNode, useReducer } from "react";
import { IUser, UserRoles } from "../../entities/user/user.ts";
import { IUser, UserRoles } from "@src/entities/user";

const defaultAuthInit = {
user: null,
Expand Down
6 changes: 6 additions & 0 deletions src/entities/area/area.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import $api from "@src/shared/api/axios.ts";
import { baseUrl } from "@src/app/config/api.ts";

export interface Area {
id: number;
institutes_id: number;
Expand All @@ -7,3 +10,6 @@ export interface Area {
institute: string;
square: number;
}

export const getAllAreas = () =>
$api.get(`${baseUrl}/areas`).then((response) => response?.data?.data);
2 changes: 1 addition & 1 deletion src/entities/area/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @ts-ignore
export type { Area } from "./area.ts";
export { getAllAreas } from "./area.ts";
81 changes: 51 additions & 30 deletions src/entities/booking/booking.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
export type TBooking = {
id: number
date_from: Date
date_to: Date
created_at: Date
updated_at: Date
status: "CREATED" | "COMPLETE"
user_id: number,
equipment_id: number
equipments: {
id: number
area_id: number
name: string
description: string
count: number
status: "FREE" | "BOOKED"
}
users: {
id: 16,
roles: {
id: number,
role: "USER" | "ADMIN" | "OWNER"
}
first_name: string
second_name: string
mail: string
import { baseUrl } from "@src/app/config/api.ts";
import $api from "@src/shared/api";

}
}
export type TBooking = {
id: number;
date: Date;
created_at: Date;
updated_at: Date;
status: "CREATED" | "COMPLETE";
user_id: number;
equipment_id: number;
equipments: {
id: number;
area_id: number;
name: string;
description: string;
count: number;
status: "FREE" | "BOOKED";
};
users: {
id: 16;
roles: {
id: number;
role: "USER" | "ADMIN" | "OWNER";
};
first_name: string;
second_name: string;
mail: string;
};
};

export type BookingDatesList = {
date_to: string
}
date_to: string;
};

export const getBookings = (selectDate: Date | undefined) => {
return $api
.get(`${baseUrl}/bookings`, {
params: {
...(selectDate
? {
date_to: new Date(selectDate)?.toISOString(),
}
: {}),
skip: 0,
take: 10,
},
})
.then((res) => res.data);
};

export const fetchBookingDates = () => {
return $api.get(`${baseUrl}/booking_dates`).then((res) => res?.data?.data);
};
2 changes: 2 additions & 0 deletions src/entities/booking/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { getBookings, fetchBookingDates } from "./booking";
export type { TBooking, BookingDatesList } from "./booking";
35 changes: 26 additions & 9 deletions src/entities/department/department.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { baseUrl } from "../../app/config/api.ts";
import $api from "@src/shared/api/axios.ts";

export interface InstitutesModel {
id: number,
name: string
id: number;
name: string;
}

export interface DepartmentInfo {
id: number
equipment: string
area: string
institute: string
id: number;
equipment: string;
area: string;
institute: string;
}

export type fetchAllInfoDepartmentT = {
skip: number
take: number
}
skip: number;
take: number;
};

export const fetchAllInfoDepartment = (filter: fetchAllInfoDepartmentT) =>
$api
.get(`${baseUrl}/department/info`, {
params: {
...filter,
},
})
.then((res) => {
return res.data.data;
});

export const getAllInstitutes = async () =>
$api.get("/departments").then((res) => res.data.data);
6 changes: 6 additions & 0 deletions src/entities/department/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { fetchAllInfoDepartment, getAllInstitutes } from "./department";
export type {
fetchAllInfoDepartmentT,
DepartmentInfo,
InstitutesModel,
} from "./department";
2 changes: 2 additions & 0 deletions src/entities/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type { IUser } from "./user.ts";
export { UserRoles } from "./user.ts";
5 changes: 0 additions & 5 deletions src/shared/api/Areas.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/shared/api/Booking.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/shared/api/Departments.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/shared/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from "./axios.ts";
export { signIn, signOut, logOut } from "./Auth.ts";
4 changes: 2 additions & 2 deletions src/shared/hooks/useBooking.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useQuery } from "react-query";
import { getBookings } from "@src/shared/api/Booking.ts";
import { getBookings } from "@src/entities/booking";

export const useBooking = (selectDate: Date | undefined) => {
return useQuery({
queryKey: ["booking", selectDate],
queryFn: () => getBookings(selectDate),
});
};
};
4 changes: 2 additions & 2 deletions src/shared/hooks/useDepartmentInfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useQuery } from "react-query";
import { fetchAllInfoDepartment } from "@src/shared/api/Departments.ts";
import {
DepartmentInfo,
fetchAllInfoDepartment,
fetchAllInfoDepartmentT,
} from "../../entities/department/department.ts";
} from "@src/entities/department";

export const useDepartmentInfo = (filter: fetchAllInfoDepartmentT) => {
return useQuery<DepartmentInfo[], Error>({
Expand Down
3 changes: 1 addition & 2 deletions src/shared/hooks/useGetAreas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useQuery } from "react-query";
import { getAllAreas } from "@src/shared/api/Areas.ts";
import { Area } from "../../entities/area/Area.ts";
import { Area, getAllAreas } from "@src/entities/area";

export const useGetAreas = () => {
return useQuery<Area[], Error>({
Expand Down
3 changes: 1 addition & 2 deletions src/shared/hooks/useInstitutes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useQuery } from "react-query";
import { InstitutesModel } from "../../entities/department/department.ts";
import { getAllInstitutes } from "@src/shared/api/Departments.ts";
import { getAllInstitutes, InstitutesModel } from "@src/entities/department";

export const useInstitutes = () => {
return useQuery<InstitutesModel[], Error>("institutes", getAllInstitutes);
Expand Down
22 changes: 5 additions & 17 deletions src/widgets/booking-history/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,12 @@ const columns: GridColDef[] = [
editable: false,
},
{
field: "date_from",
headerName: "Дата начала брони",
field: "date",
headerName: "Дата бронирования",
sortable: false,
width: 160,
type: "dateTime",
valueGetter: (params: GridValueGetterParams) =>
new Date(params.row.date_from),
},
{
field: "date_to",
headerName: "Дата конца брони",
sortable: false,
width: 160,
type: "dateTime",
valueGetter: (params: GridValueGetterParams) =>
new Date(params.row.date_to),
valueGetter: (params: GridValueGetterParams) => new Date(params.row.date),
},
{
field: "status",
Expand All @@ -73,14 +63,12 @@ const BookingList = ({ data }: BookingList) => {
const {
equipments: { status, name },
users: { first_name, second_name },
date_from,
date_to,
date,
id,
} = item;
return {
status,
date_from,
date_to,
date,
id,
first_name,
second_name,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/card-list/model/card-equipment.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useQuery } from "react-query";
import { getAllEquipments } from "@src/widgets/card-list/model/api/equipment.ts";
import { Equipment } from "@src/entities/equipment/Equipments.ts";
import { Equipment } from "@src/entities/equipment";

type FilterEquipments = {
debouncedValue: string;
Expand Down

0 comments on commit d339872

Please sign in to comment.