From 7e692fee4c04c5bf384f5b146c43d0bb2d14fbc6 Mon Sep 17 00:00:00 2001 From: inmake Date: Thu, 6 Jun 2024 18:15:51 +0500 Subject: [PATCH] upd --- client/.env | 4 +- client/src/components/Card.tsx | 55 ++++---- client/src/components/DatePicker.tsx | 2 +- client/src/components/EmptyCard.tsx | 2 +- .../components/modals/CreateScheduleModal.tsx | 39 +++--- client/src/pages/DashboardPage.tsx | 8 +- server/src/index.ts | 6 +- server/src/routes/companies.ts | 3 - server/src/routes/scheduledSessions.ts | 121 +++++------------- server/src/routes/schedules.ts | 47 +++---- server/tsconfig.json | 2 +- 11 files changed, 116 insertions(+), 173 deletions(-) diff --git a/client/.env b/client/.env index 30293ab..0038af3 100644 --- a/client/.env +++ b/client/.env @@ -1,4 +1,4 @@ # VITE_API_URL=http://localhost:3001 -VITE_API_URL=http://192.168.1.171:3001 -# VITE_API_URL=https://crm.stream.graff.tech/api +# VITE_API_URL=http://192.168.1.171:3001 +VITE_API_URL=https://crm.stream.graff.tech/api VITE_STREAM_URL=https://stream.graff.tech diff --git a/client/src/components/Card.tsx b/client/src/components/Card.tsx index 326a59f..c237b67 100644 --- a/client/src/components/Card.tsx +++ b/client/src/components/Card.tsx @@ -60,28 +60,37 @@ function Card({ return (
-
-
-

{client.name}

- {manager ? ( -
-
-

- Готов -

+
+
+
+
+

Клиент

+

{client.name}

- ) : ( -
-
-

- Нет менеджера -

-
- )} -
-
-

{client.phone}

-

{client.email}

+ {manager ? ( +
+
+

+ Готов +

+
+ ) : ( +
+
+

+ Нет менеджера +

+
+ )} +
+
+

+ {client.phone} +

+

+ {client.email} +

+
@@ -105,7 +114,9 @@ function Card({
{manager && ( diff --git a/client/src/components/DatePicker.tsx b/client/src/components/DatePicker.tsx index 8853dc1..7095f33 100644 --- a/client/src/components/DatePicker.tsx +++ b/client/src/components/DatePicker.tsx @@ -51,7 +51,7 @@ function DatePicker({ defaultValue, startDate, onChange }: Props) { function handleClick(date: Date) { setValue(date); - onChange && onChange(value); + onChange && onChange(date); } return ( diff --git a/client/src/components/EmptyCard.tsx b/client/src/components/EmptyCard.tsx index 861d65f..b87c2b5 100644 --- a/client/src/components/EmptyCard.tsx +++ b/client/src/components/EmptyCard.tsx @@ -3,7 +3,7 @@ import PlusIcon from "./icons/PlusIcon"; function EmptyCard() { return ( -
+
diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index 8a28381..d55534d 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -422,11 +422,7 @@ function DashboardPage() { scheduleSessionStartAt={ scheduledSession.startAt } - client={{ - name: scheduledSession.clientName, - phone: scheduledSession.clientPhone, - email: scheduledSession.clientEmail, - }} + client={scheduledSession.client} manager={selectedManager} managers={selectedBuildManagers || []} handleSelect={(scheduledSessionId, managerId) => @@ -523,7 +519,7 @@ function DashboardPage() { ) diff --git a/server/src/index.ts b/server/src/index.ts index bc08135..789dcdd 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -21,15 +21,15 @@ connectDB(); app.use(json()); app.use(cors({ origin: "*" })); -app.use("/app", authMiddleware, appRouter); -app.use("/companies", authMiddleware, companiesRouter); -app.use("/users", authMiddleware, usersRouter); app.use("/login", loginRouter); app.use("/registration", registrationRouter); app.use("/actions", actionsRouter); app.use("/builds", buildsRouter); app.use("/scheduled_sessions", scheduledSessionsRouter); app.use("/schedules", schedulesRouter); +app.use("/app", authMiddleware, appRouter); +app.use("/companies", authMiddleware, companiesRouter); +app.use("/users", authMiddleware, usersRouter); app.listen(port, () => { console.log(`Server listening on port ${port}`); diff --git a/server/src/routes/companies.ts b/server/src/routes/companies.ts index 267b046..efc41f9 100644 --- a/server/src/routes/companies.ts +++ b/server/src/routes/companies.ts @@ -258,9 +258,6 @@ router.get( async (req, res) => { const { companyId, buildId } = req.params; - console.log("companyId", companyId); - console.log("buildId", buildId); - try { const lastScheduledSession = await ScheduledSession.findOne({ companyId, diff --git a/server/src/routes/scheduledSessions.ts b/server/src/routes/scheduledSessions.ts index 2429860..c41b730 100644 --- a/server/src/routes/scheduledSessions.ts +++ b/server/src/routes/scheduledSessions.ts @@ -5,13 +5,11 @@ import Schedule from "../models/Schedule"; import { addMinutes, areIntervalsOverlapping, - differenceInMinutes, endOfDay, isValid, parseISO, startOfDay, } from "date-fns"; -import { isValidObjectId } from "mongoose"; const scheduledSessionsRouter = Router(); @@ -26,50 +24,33 @@ scheduledSessionsRouter.get("/", async (_req, res) => { scheduledSessionsRouter.get("/:id", async (req, res) => { const scheduledSessionId = req.params.id; - - if (!isValidObjectId(scheduledSessionId)) { - return res.json({ - status: "error", - message: "Invalid session ID value", - }); - } - - const scheduledSession = await ScheduledSession.findById(req.params.id); + const scheduledSession = await ScheduledSession.findById(scheduledSessionId); res.json(scheduledSession); }); -scheduledSessionsRouter.get("/builds/:buildId", async (req, res) => { - if (!req.params.buildId) { - res.json({ error: "Parameter `buildId` is required" }); - return; +scheduledSessionsRouter.get( + "/companies/:companyId/builds/:buildId", + async (req, res) => { + const { companyId, buildId } = req.params; + const { date } = req.query; + + try { + const scheduledSessions = await ScheduledSession.find({ + companyId, + buildId, + startAt: { + $gte: startOfDay(parseISO(date as string)), + $lt: endOfDay(parseISO(date as string)), + }, + }); + + res.json(scheduledSessions); + } catch (error) { + res.json({ error: (error as Error).message }); + } } - - if (!req.query.date) { - res.json({ error: "Query parameter `date` is required" }); - return; - } - - const buildId = req.params.buildId; - const date = req.query.date as string; - - if (!isValidObjectId(buildId)) { - return res.json({ - status: "error", - message: "Invalid build ID value", - }); - } - - const scheduledSessions = await ScheduledSession.find({ - buildId, - startAt: { - $gte: startOfDay(parseISO(date)), - $lt: endOfDay(parseISO(date)), - }, - }); - - res.json(scheduledSessions); -}); +); scheduledSessionsRouter.get("/:buildId", async (req, res) => { if (!req.params.buildId) { @@ -98,13 +79,6 @@ scheduledSessionsRouter.get("/:buildId", async (req, res) => { scheduledSessionsRouter.post("/", async (req, res) => { const { buildId, startAt, client, duration } = req.body; - if (!isValidObjectId(buildId)) { - return res.json({ - status: "error", - message: "Invalid build ID value", - }); - } - if (!buildId || !startAt) { return res.json({ status: "error", @@ -183,7 +157,7 @@ scheduledSessionsRouter.post("/", async (req, res) => { const schedule = await Schedule.findOne({ buildId, startDate: { $lte: startAtISO }, - endDate: { $gte: startAtISO }, + // endDate: { $gte: startAtISO }, }); if (!schedule) { @@ -246,16 +220,13 @@ scheduledSessionsRouter.post("/", async (req, res) => { scheduledSessionsRouter.put("/:id", async (req, res) => { const scheduledSessionId = req.params.id; - if (!isValidObjectId(scheduledSessionId)) { - return res.json({ - status: "error", - message: "Invalid session ID value", - }); - } + let { + startAt, + endAt, + activeSessionId, + }: { startAt: string; endAt: string; activeSessionId: string } = req.body; - let { startAt, duration }: { startAt: string; duration: number } = req.body; - - if (!startAt && !duration) { + if (!startAt && !endAt) { return res.json({ status: "error", message: "Parameter `startAt` or `duration` is required, or both", @@ -269,16 +240,9 @@ scheduledSessionsRouter.put("/:id", async (req, res) => { }); } - function isInteger(num: number) { - return (num ^ 0) === num; - } - - if (duration && !isInteger(duration)) { - return res.json({ - status: "error", - message: "Parameter `duration` is not an integer", - }); - } + // function isInteger(num: number) { + // return (num ^ 0) === num; + // } const scheduledSession = await ScheduledSession.findById(scheduledSessionId); @@ -289,22 +253,10 @@ scheduledSessionsRouter.put("/:id", async (req, res) => { }); } - if (!duration) { - duration = differenceInMinutes( - scheduledSession.endAt, - scheduledSession.startAt - ); - } - - const endAt = addMinutes( - (startAt && parseISO(startAt.toString())) || scheduledSession.startAt, - duration - ); - try { const scheduledSession = await ScheduledSession.findByIdAndUpdate( scheduledSessionId, - { startAt, endAt }, + { startAt, endAt, activeSessionId }, { new: true } ); @@ -319,13 +271,6 @@ scheduledSessionsRouter.put("/:id", async (req, res) => { scheduledSessionsRouter.delete("/:id", async (req, res) => { const scheduledSessionId = req.params.id; - if (!isValidObjectId(scheduledSessionId)) { - return res.json({ - status: "error", - message: "Invalid session ID value", - }); - } - try { await ScheduledSession.findByIdAndDelete(scheduledSessionId); diff --git a/server/src/routes/schedules.ts b/server/src/routes/schedules.ts index 4acd14d..17aad05 100644 --- a/server/src/routes/schedules.ts +++ b/server/src/routes/schedules.ts @@ -3,33 +3,36 @@ import Schedule from "../models/Schedule"; const schedulesRouter = Router(); -schedulesRouter.get("/builds/:buildId", async (req, res) => { - const buildId = req.params.buildId; - const date = new Date(); +schedulesRouter.get( + "/companies/:companyId/builds/:buildId", + async (req, res) => { + const { companyId, buildId } = req.params; + const date = new Date(); - const schedules = await Schedule.find({ - buildId, - startDate: { $lte: date }, - endDate: { $gte: date }, - }); - - if (!schedules.length) { - res.json({ error: "No data" }); - return; - } - - if (req.query.date) { - const schedule = await Schedule.findOne({ + const schedules = await Schedule.find({ + companyId, buildId, startDate: { $lte: date }, - endDate: { $gte: date }, }); - res.json(schedule); - return; - } + if (!schedules.length) { + res.json({ error: "No data" }); + return; + } - res.json(schedules); -}); + if (req.query.date) { + const schedule = await Schedule.findOne({ + companyId, + buildId, + startDate: { $lte: date }, + }); + + res.json(schedule); + return; + } + + res.json(schedules); + } +); export default schedulesRouter; diff --git a/server/tsconfig.json b/server/tsconfig.json index e7913fc..2ca8d8c 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -10,7 +10,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, - "skipLibCheck": true + "skipLibCheck": true, }, "ts-node": { "transpileOnly": true