From a3156b57788276d18e55c5f84da34a30fada17b1 Mon Sep 17 00:00:00 2001 From: inmake Date: Mon, 23 Oct 2023 20:37:41 +0500 Subject: [PATCH] upd --- client/public/images/avatar.jpg | Bin 2639 -> 0 bytes client/public/images/no-avatar.png | Bin 0 -> 585 bytes client/src/pages/DashboardPage.tsx | 6 -- server/src/config/db.ts | 2 +- server/src/index.ts | 2 +- server/src/models/Build.ts | 5 ++ server/src/routes/scheduledSessions.ts | 92 ++++++++++++++++++++++++- 7 files changed, 96 insertions(+), 11 deletions(-) delete mode 100644 client/public/images/avatar.jpg create mode 100644 client/public/images/no-avatar.png diff --git a/client/public/images/avatar.jpg b/client/public/images/avatar.jpg deleted file mode 100644 index 8c8cfa8b1f0b2d15b6c43fbd1ed444e75be95640..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2639 zcmbu9cU02}632g`2%?Bc5mCWKP>?3=sKV(=G_W8f61oVYY!b>P5DAE3MQI6$3IPF8 z0ZHglmVf~SLkR)`k^otvl!SIPH=)F=2juYf-rjrn*S*`BH-F8%@4U~U%2z(EK{-k{q`I8bLkmN0(EDsz5j!A=*0V!pWv@%H231|ZVNcMMa z;NJ$4l9rL(B`3dIVb4whZ9gCdl9rZ|k(QN}k=d!fy^{xIlw}WmXLfd%if6E#4qDax z&ckB)Qn5QBtt=z^o!PDfXFcVD(JDITcjQ&iJuH63*nQjrDo_i-3@NDV zTJrRS-_ZU=_P>E8{a<8%fc=My3+$B!?JQ4P8E^u&Ijv5c2}E9U`3DD^+%FTBt&P5^ zPsyk=yI3J`!@hS6sarj7uU!xI(f2U<%xFB#h%17;u2Gwi0Gz(7PDK(xtnYMR0)$fu znz6}v%>-p}wgiyRA~+sTY(IOOubrW}zPfmN)BeMzp;PLFzo`<=%lNR%ZCK~p655Bm zRb;F_Ffe(Uo^e)Z&pSudnf{4DaK^Z`tye{#hQX?>Z(!|>f~3*U0d+Tr44bKB-jnQq zM63A`pCH)9uG|4=Mw#l1Pq0~H26>%zWN7YY#F(W7P~2!EXbZfx#V00-;jO0;&uHCg zj@DxTzqX~qgo$@)+WS$BUoWL^+Kb+m4M(W7w;ro+V#SDVVYl8F-0r2ND}2a*Ztfc( zrpF!}qGsM#sMR7LfFi)u#!RHiB_1*IG%BAKg|4E-hEYatw8(iY<_>oUSFt+V3+8f; zr;-%br&83|# zvwcP)Yacvm%tMBnjrrHcJ0n7JMIQ`wt396UK7hh_c{*zq=hj89&!Ol}tJ6#H4fugc z)s3hWztnb9^-n0+q?pLS;4rt5+p#cg1rb+5E<;ZzDy|A)`PA?O^sGobpg1V81HY5UCOsMShGI(dBfod*u-*f!P(Z$uM^dh9Eaa3{oAXWZj!~@twWR2v%jUdJ@)AI&OtJh;~yh>!263cipg3~ zv^&g8PoG?popZ{DY2p?{)#3l(?pb*C)ni;0xH|ZXSu-iXk}Fyt;X=wOx--j_=Zxz~ zgUVZ_c%w~cL5`!^R@KV3J>1w3?v2lWq&dL0!=9;@XEb zIM)U9snwp?%LHEd=2hW9bUTuc<2$88%f zK0Dw5n>Lnfw|09zwovNKT7Ra1&`iyu>DCGIl4IH$2dRs8}yeD>WLeJvKuK zy4OAXI1YU@Vc?CQC5*v(PC1DHE4cMzss(tb}<))~Jnf&2uefL3Q1a*ZepR!Cje5 waO3A61B0j5F>n&Rb(l0x`iRad&8^U1gOWLI(1FsG`h@JdHfmr0Pm-~J0&l+X-v9sr diff --git a/client/public/images/no-avatar.png b/client/public/images/no-avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..07e6f5af560815342a8665bbc05d32ab49fec7d7 GIT binary patch literal 585 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyT>(BJuFu~5cbf9wYsUYy<^LbO z`hWKR|L1T2FFgJ~amjzzY5#$;*Pi@;^7{YFmmoF}MK1W?vFm^5uK(4W|4%*y5`PX9 zfBQdS$^Sdg{`<`asVQ0iKX2{-IY<9LdkvCp-1fg=>;KIc|2J+0$vy?EfBp`n3uq2d z1gOTnz$dceaum>2dL==A!T&)(v>HfM{C~`S>D$lP|J&8Yv%-M_pO5_iZ)`ek%Kv2_ zbKE>V%40eh_Dw7@2kPW3@Q5r1(r-YRu~MUOF9QRkwx^3@h{fsJ$v0;;EAX@~?vT#9 zySD89^0^=X#^Q?K&Y-w`lNQ{+kweebJ76UQ)l=b;}GtzHfMG3=BU8Pgg&e IbxsLQ0JzsWq5uE@ literal 0 HcmV?d00001 diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index dc51032..86bca1e 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -78,8 +78,6 @@ function DashboardPage() { ); if (foundSchedule) { - console.log("foundSchedule", foundSchedule); - const startDateTime = parse( foundSchedule.startTime, "HH:mm", @@ -138,8 +136,6 @@ function DashboardPage() { } async function getManagers() { - console.log("getManagers"); - if (!company || !selectedBuild) { return; } @@ -236,8 +232,6 @@ function DashboardPage() { ) .json(); - console.log(scheduledSessions, result); - setScheduledSessions( scheduledSessions.map((scheduledSession) => scheduledSession.id === result.id ? result : scheduledSession diff --git a/server/src/config/db.ts b/server/src/config/db.ts index 81b9319..06cc0c9 100644 --- a/server/src/config/db.ts +++ b/server/src/config/db.ts @@ -2,7 +2,7 @@ import { connect } from "mongoose"; async function connectDB() { try { - await connect(process.env.MONGO_URI!, { dbName: "test2" }); + await connect(process.env.MONGO_URI!, { dbName: "crm_stream" }); console.log("MongoDB connected..."); } catch (error) { if (error instanceof Error) { diff --git a/server/src/index.ts b/server/src/index.ts index 002f2a9..db6464d 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -23,11 +23,11 @@ app.use(cors()); app.use("/login", loginRouter); app.use("/registration", registrationRouter); app.use("/actions", actionsRouter); +app.use("/scheduled_sessions", scheduledSessionsRouter); app.use("/app", authMiddleware, appRouter); app.use("/companies", authMiddleware, companiesRouter); app.use("/users", authMiddleware, usersRouter); app.use("/builds", authMiddleware, buildsRouter); -app.use("/scheduled_sessions", authMiddleware, scheduledSessionsRouter); app.listen(port, () => { console.log(`Server listening on port ${port}`); diff --git a/server/src/models/Build.ts b/server/src/models/Build.ts index 0c00d9f..3b031c2 100644 --- a/server/src/models/Build.ts +++ b/server/src/models/Build.ts @@ -11,6 +11,11 @@ const buildSchema = new Schema( required: true, unique: true, }, + build: { + type: String, + required: true, + unique: true, + }, sessionLimit: { type: Number, required: true, diff --git a/server/src/routes/scheduledSessions.ts b/server/src/routes/scheduledSessions.ts index 58b9f47..cd79b8e 100644 --- a/server/src/routes/scheduledSessions.ts +++ b/server/src/routes/scheduledSessions.ts @@ -1,12 +1,98 @@ import { Router } from "express"; import ScheduledSession from "../models/ScheduledSession.js"; +import Build from "../models/Build.js"; +import Schedule from "../models/Schedule.js"; +import { addMinutes, endOfDay, parseISO, startOfDay } from "date-fns"; const scheduledSessionsRouter = Router(); -scheduledSessionsRouter.get("/", async (_req, res) => { - await ScheduledSession.find(); +scheduledSessionsRouter.get("/:buildId", async (req, res) => { + if (!req.params.buildId) { + res.json({ error: "Parameter `buildId` is required!" }); + return; + } - res.json({ ok: 1 }); + 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; + const scheduledSessions = await ScheduledSession.find({ + buildId, + startAt: { + $gte: startOfDay(parseISO(date)), + $lt: endOfDay(parseISO(date)), + }, + }); + + res.json(scheduledSessions); +}); + +scheduledSessionsRouter.post("/", async (req, res) => { + if (!req.body.companyId) { + res.json({ error: "Parameter `companyId` is required!" }); + return; + } + + if (!req.body.buildId) { + res.json({ error: "Parameter `buildId` is required!" }); + return; + } + + if (!req.body.startAt) { + res.json({ error: "Parameter `startAt` is required!" }); + return; + } + + if (!req.body.client) { + res.json({ error: "Parameter `client` is required!" }); + return; + } + + const { companyId, buildId, startAt, client } = req.body; + + const build = await Build.findById(buildId); + const schedule = await Schedule.findOne({ companyId, buildId }); + const scheduledSessions = await ScheduledSession.find({ + companyId, + buildId, + startAt, + }); + + if (!build) { + res.json({ error: "`Build` not found in the database!" }); + return; + } + + if (scheduledSessions.length === build.sessionLimit) { + res.json({ + error: "No slots available!", + scheduledSessionsLength: scheduledSessions.length, + buildSessionLimit: build.sessionLimit, + }); + return; + } + + if (!schedule) { + res.json({ error: "`Schedule` not found in the database!" }); + return; + } + + const endAt = addMinutes(parseISO(startAt), schedule.sessionDuration); + + const scheduleSession = await ScheduledSession.create({ + companyId, + buildId, + startAt, + endAt, + clientName: client.name, + clientEmail: client.email, + clientPhone: client.phone, + }); + + res.json({ ok: 1, scheduleSession }); }); export default scheduledSessionsRouter;