upd
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
VITE_API_URL=http://localhost:3001
|
||||
# VITE_API_URL=https://crm.stream.graff.tech/api
|
||||
VITE_STREAM_URL=https://stream.graff.tech
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
@@ -43,7 +43,7 @@ function Card({
|
||||
async function getAvailableManagers() {
|
||||
const result: any[] = await api
|
||||
.get(
|
||||
`companies/${companyId}/builds/${buildId}/scheduled_sessions/${scheduledSessionId}/availableManagers?startAt=${scheduleSessionStartAt}`
|
||||
`companies/${companyId}/builds/${buildId}/scheduledSessions/${scheduledSessionId}/availableManagers?startAt=${scheduleSessionStartAt}`
|
||||
)
|
||||
.json();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ interface InputProps {
|
||||
required?: boolean;
|
||||
readOnly?: boolean;
|
||||
className?: string;
|
||||
autoComplete?: string;
|
||||
handleChange?: (value: string) => void;
|
||||
handleFocus?: () => void;
|
||||
}
|
||||
@@ -21,6 +22,7 @@ function Input({
|
||||
required,
|
||||
readOnly,
|
||||
className,
|
||||
autoComplete,
|
||||
handleChange,
|
||||
handleFocus,
|
||||
}: InputProps) {
|
||||
@@ -31,6 +33,7 @@ function Input({
|
||||
|
||||
return (
|
||||
<input
|
||||
autoComplete={autoComplete}
|
||||
ref={type === "tel" ? inputRef : undefined}
|
||||
type={type}
|
||||
placeholder={placeholder}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import useAuthStore from "../stores/useAuthStore";
|
||||
import useModalStore from "../stores/useModalStore";
|
||||
import useSettingsStore from "../stores/useSettingsStore";
|
||||
import useStore from "../stores/useStore";
|
||||
import Button from "./Button";
|
||||
import ChevronDownIcon from "./icons/ChevronDownIcon";
|
||||
import ChevronUpIcon from "./icons/ChevronUpIcon";
|
||||
import MoreIcon from "./icons/MoreIcon";
|
||||
// import MoreIcon from "./icons/MoreIcon";
|
||||
import AddManagerModal from "./modals/AddManagerModal";
|
||||
|
||||
function Managers() {
|
||||
const { user } = useAuthStore();
|
||||
const { managers } = useStore();
|
||||
const { isShowManagers, setIsShowManagers } = useSettingsStore();
|
||||
const { setModal } = useModalStore();
|
||||
|
||||
return (
|
||||
<div className="p-4 flex flex-col gap-4 border-b border-[#DAE0E5]">
|
||||
@@ -34,19 +37,23 @@ function Managers() {
|
||||
</div>
|
||||
<p className="text-sm">{manager.name}</p>
|
||||
</div>
|
||||
{user?.role === "admin" && (
|
||||
{/* {user?.role === "admin" && (
|
||||
<Button
|
||||
disabled
|
||||
variant="tertiary"
|
||||
onlyIcon
|
||||
icon={<MoreIcon />}
|
||||
/>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{user?.role === "admin" && (
|
||||
<Button disabled variant="secondary" widthFull>
|
||||
<Button
|
||||
variant="secondary"
|
||||
widthFull
|
||||
onClick={() => setModal(<AddManagerModal />)}
|
||||
>
|
||||
Добавить
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import { Transition } from "react-transition-group";
|
||||
import useModalStore from "../stores/useModalStore";
|
||||
import { useEffect } from "react";
|
||||
|
||||
function ModalContainer() {
|
||||
const [modal, setModal] = useModalStore((state) => [
|
||||
@@ -7,6 +9,20 @@ function ModalContainer() {
|
||||
state.setModal,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
function handleKeyUp(e: KeyboardEvent) {
|
||||
if (e.key === "Escape") {
|
||||
setModal(null);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("keyup", handleKeyUp);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keyup", handleKeyUp);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Transition
|
||||
in={modal ? true : false}
|
||||
@@ -16,12 +32,9 @@ function ModalContainer() {
|
||||
>
|
||||
{(state) => (
|
||||
<div
|
||||
onClick={() => setModal(null)}
|
||||
className={`min-h-screen p-8 absolute z-20 top-0 left-0 w-full flex justify-center items-center bg-black bg-opacity-30 overflow-auto cursor-pointer transition-opacity ${state}`}
|
||||
className={`min-h-screen p-8 absolute z-20 top-0 left-0 w-full flex justify-center items-center bg-black bg-opacity-30 overflow-auto transition-opacity ${state}`}
|
||||
>
|
||||
<div onClick={(e) => e.stopPropagation()} className="cursor-default">
|
||||
{modal}
|
||||
</div>
|
||||
{modal}
|
||||
</div>
|
||||
)}
|
||||
</Transition>
|
||||
|
||||
@@ -91,7 +91,7 @@ function Schedule({ selectedDay, slots, events }: Props) {
|
||||
|
||||
try {
|
||||
const result: any = await api
|
||||
.post(`scheduled_sessions`, {
|
||||
.post(`scheduledSessions`, {
|
||||
json: {
|
||||
companyId: company!.id,
|
||||
buildId: selectedBuild?.id,
|
||||
|
||||
@@ -62,7 +62,7 @@ function AddManagerModal() {
|
||||
return (
|
||||
<div className="bg-white rounded-lg w-[400px]">
|
||||
<div className="border-b border-[#DAE0E5] flex items-center justify-between pl-6 pr-2">
|
||||
<ModalTabButton active>Добавить сотрудника</ModalTabButton>
|
||||
<ModalTabButton active>Новый сотрудник</ModalTabButton>
|
||||
<Button
|
||||
variant="tertiary"
|
||||
icon={<CloseIcon />}
|
||||
@@ -73,7 +73,7 @@ function AddManagerModal() {
|
||||
<form onSubmit={handleSubmitAddManager}>
|
||||
<div className="border-b border-[#DAE0E5] p-6 space-y-4">
|
||||
<p className="text-sm text-[#77828C]">
|
||||
Информация для входа будет отправлена на почтовый адрес
|
||||
Информация для входа будет отправлена на указанный почтовый адрес
|
||||
</p>
|
||||
<div className="space-y-1">
|
||||
<Label value="Email*" />
|
||||
|
||||
@@ -46,7 +46,15 @@ function CompanyModal() {
|
||||
{selectedTab === "company" && (
|
||||
<div>
|
||||
<div className="flex gap-6 p-6 border-b border-[#DAE0E5]">
|
||||
<div className="min-w-[88px] min-h-[88px] w-[88px] h-[88px] bg-[#E6ECF2] rounded-full"></div>
|
||||
<div className="min-w-[88px] min-h-[88px] w-[88px] h-[88px] bg-[#E6ECF2] rounded-full">
|
||||
{company?.avatar && (
|
||||
<img
|
||||
src={`/images/companies/${company.avatar}`}
|
||||
alt=""
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full space-y-6">
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<div className="space-y-4">
|
||||
@@ -58,11 +66,11 @@ function CompanyModal() {
|
||||
<DataField label="Адрес" value={company?.address} copyIcon />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
{/* <div>
|
||||
<a href="#" className="text-[#49A1F5] text-xs">
|
||||
Сообщить о проблеме
|
||||
</a>
|
||||
</div>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="p-6 space-y-4">
|
||||
@@ -131,7 +139,10 @@ function CompanyModal() {
|
||||
</div>
|
||||
{user?.role === "admin" && (
|
||||
<div className="px-6 py-4">
|
||||
<Button onClick={() => setModal(<AddManagerModal />)}>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => setModal(<AddManagerModal />)}
|
||||
>
|
||||
Добавить
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -29,7 +29,7 @@ function CreateScheduledSessionModal({ buildId, startAt, duration }: Props) {
|
||||
|
||||
try {
|
||||
await api
|
||||
.post(`scheduled_sessions`, {
|
||||
.post(`scheduledSessions`, {
|
||||
json: {
|
||||
buildId,
|
||||
startAt,
|
||||
|
||||
@@ -94,7 +94,7 @@ function CreateUserModal({ companyId }: Props) {
|
||||
|
||||
return (
|
||||
<div className="p-8 space-y-4 bg-white rounded-xl">
|
||||
<p className="text-xl font-semibold">Создание пользователя</p>
|
||||
<p className="text-xl font-semibold">Новый пользователь</p>
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-4">
|
||||
<Input
|
||||
placeholder="Имя Фамилия"
|
||||
@@ -110,6 +110,7 @@ function CreateUserModal({ companyId }: Props) {
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
autoComplete="new-password"
|
||||
type="password"
|
||||
placeholder="Пароль"
|
||||
className="w-64"
|
||||
|
||||
@@ -137,7 +137,7 @@ function AdminCompanyPage() {
|
||||
users.map((user) => (
|
||||
<div
|
||||
key={user.id}
|
||||
className="flex justify-between gap-4 p-4 rounded-lg shadow"
|
||||
className="flex items-start justify-between gap-4 p-4 rounded-lg shadow"
|
||||
>
|
||||
<div className="flex gap-4">
|
||||
<img
|
||||
@@ -162,7 +162,7 @@ function AdminCompanyPage() {
|
||||
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={<MoreIcon />}
|
||||
icon={<MoreIcon className="w-5 h-5" />}
|
||||
onlyIcon
|
||||
onClick={() =>
|
||||
companyId &&
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { format, addDays, subDays } from "date-fns";
|
||||
import { format, addDays, subDays, startOfDay, endOfDay } from "date-fns";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import api from "../utils/api";
|
||||
import { ru } from "date-fns/locale";
|
||||
@@ -109,7 +109,6 @@ function DashboardPage() {
|
||||
|
||||
async function getScheduledSessions(useLoader?: boolean) {
|
||||
if (!company) {
|
||||
// console.log("No ScheduledSessions");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -118,9 +117,9 @@ function DashboardPage() {
|
||||
try {
|
||||
const result: any = await api
|
||||
.get(
|
||||
`companies/${
|
||||
company.id
|
||||
}/scheduled_sessions?date=${selectedDay.toISOString()}`
|
||||
`companies/${company.id}/scheduledSessions?startDate=${startOfDay(
|
||||
selectedDay
|
||||
).toISOString()}&endDate=${endOfDay(selectedDay).toISOString()}`
|
||||
)
|
||||
.json();
|
||||
|
||||
|
||||
+1
-3
@@ -12,7 +12,6 @@ import usersRouter from "./routes/users.js";
|
||||
import companiesRouter from "./routes/companies.js";
|
||||
import buildsRouter from "./routes/builds.js";
|
||||
import actionsRouter from "./routes/actions.js";
|
||||
import schedulesRouter from "./routes/schedules.js";
|
||||
import scheduledSessionsRoute from "./routes/scheduledSessions.js";
|
||||
import adminCompaniesRoute from "./routes/admin/adminCompaniesRoute.js";
|
||||
import adminBuildsRoute from "./routes/admin/adminBuildsRoute.js";
|
||||
@@ -46,8 +45,7 @@ app.use("/reset", resetRoute);
|
||||
app.use("/resetConfirm", resetConfirmRoute);
|
||||
app.use("/actions", actionsRouter);
|
||||
app.use("/builds", buildsRouter);
|
||||
app.use("/scheduled_sessions", scheduledSessionsRoute);
|
||||
app.use("/schedules", schedulesRouter);
|
||||
app.use("/scheduledSessions", scheduledSessionsRoute);
|
||||
app.use("/admin/companies", adminCompaniesRoute);
|
||||
app.use("/admin/builds", adminBuildsRoute);
|
||||
app.use("/admin/users", adminUsersRoute);
|
||||
|
||||
+58
-186
@@ -13,43 +13,47 @@ const router = Router();
|
||||
// res.json(companies);
|
||||
// });
|
||||
|
||||
router.get("/:id", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
router.get("/:companyId", async (req, res) => {
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company = await Company.findById(req.params.id);
|
||||
const company = await Company.findById(req.params.companyId);
|
||||
|
||||
res.json(company);
|
||||
});
|
||||
|
||||
router.get("/:id/builds", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
router.get("/:companyId/builds", async (req, res) => {
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate("builds");
|
||||
const company: any = await Company.findById(req.params.companyId).populate(
|
||||
"builds"
|
||||
);
|
||||
const { builds } = company;
|
||||
|
||||
res.json(builds);
|
||||
});
|
||||
|
||||
router.get("/:id/users", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
router.get("/:companyId/users", async (req, res) => {
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate("users");
|
||||
const company: any = await Company.findById(req.params.companyId).populate(
|
||||
"users"
|
||||
);
|
||||
const { users } = company;
|
||||
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
router.get("/:id/builds/:buildId/users", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
router.get("/:companyId/builds/:buildId/users", async (req, res) => {
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
@@ -68,25 +72,25 @@ router.get("/:id/builds/:buildId/users", async (req, res) => {
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
router.get("/:id/scheduled_sessions", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
router.get("/:companyId/scheduledSessions", async (req, res) => {
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!req.query.date) {
|
||||
res.json({ error: "Query parameter `date` is required" });
|
||||
const { startDate, endDate } = req.query;
|
||||
|
||||
if (!startDate || !endDate) {
|
||||
res.json({ error: "Query parameter `startDate`, `endDate` is required" });
|
||||
return;
|
||||
}
|
||||
|
||||
const date = parseISO(req.query.date as string);
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate({
|
||||
const company: any = await Company.findById(req.params.companyId).populate({
|
||||
path: "scheduledSessions",
|
||||
match: {
|
||||
startAt: {
|
||||
$gte: startOfDay(date),
|
||||
$lte: endOfDay(date),
|
||||
$gte: startDate,
|
||||
$lt: endDate,
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -96,85 +100,11 @@ router.get("/:id/scheduled_sessions", async (req, res) => {
|
||||
res.json(scheduledSessions);
|
||||
});
|
||||
|
||||
// router.post(
|
||||
// "/:id/builds/:buildId/scheduled_sessions",
|
||||
// async (req, res) => {
|
||||
// if (req.params.id != res.locals.user.companyId) {
|
||||
// res.json({ error: "Access denied" });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (!req.params.buildId) {
|
||||
// res.json({ error: "req.params.buildId" });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const scheduledSession = await ScheduledSession.create({
|
||||
// companyId: req.params.id,
|
||||
// buildId: req.params.buildId,
|
||||
// ...req.body,
|
||||
// });
|
||||
|
||||
// res.json(scheduledSession);
|
||||
// }
|
||||
// );
|
||||
|
||||
router.put("/:id/scheduled_sessions/:scheduledSessionId", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const scheduledSession = await ScheduledSession.findById(
|
||||
req.params.scheduledSessionId
|
||||
);
|
||||
|
||||
const scheduledSessionAtSameTime = await ScheduledSession.findOne({
|
||||
startAt: scheduledSession?.startAt,
|
||||
userId: req.body.userId,
|
||||
});
|
||||
|
||||
if (scheduledSessionAtSameTime && req.body.userId !== null) {
|
||||
await ScheduledSession.updateMany(
|
||||
{
|
||||
userId: req.body.userId,
|
||||
startAt: scheduledSession?.startAt,
|
||||
},
|
||||
{
|
||||
userId: null,
|
||||
}
|
||||
);
|
||||
|
||||
await ScheduledSession.findByIdAndUpdate(req.params.scheduledSessionId, {
|
||||
userId: req.body.userId,
|
||||
});
|
||||
res.json({ error: "Scheduled session at same time" });
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedScheduledSession = await ScheduledSession.findByIdAndUpdate(
|
||||
req.params.scheduledSessionId,
|
||||
req.body,
|
||||
{
|
||||
new: true,
|
||||
upsert: true,
|
||||
}
|
||||
);
|
||||
|
||||
res.json(updatedScheduledSession);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
res.json({ error });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
router.get(
|
||||
"/:id/builds/:buildId/scheduled_sessions/:scheduledSessionId/availableManagers",
|
||||
router.put(
|
||||
"/:companyId/scheduledSessions/:scheduledSessionId",
|
||||
async (req, res) => {
|
||||
if (!req.query.startAt) {
|
||||
res.json({ error: "Query parameter `startAt` is required" });
|
||||
if (req.params.companyId != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -183,49 +113,42 @@ router.get(
|
||||
req.params.scheduledSessionId
|
||||
);
|
||||
|
||||
if (!scheduledSession) {
|
||||
res.json({ error: "Scheduled session not found" });
|
||||
const scheduledSessionAtSameTime = await ScheduledSession.findOne({
|
||||
startAt: scheduledSession?.startAt,
|
||||
userId: req.body.userId,
|
||||
});
|
||||
|
||||
if (scheduledSessionAtSameTime && req.body.userId !== null) {
|
||||
await ScheduledSession.updateMany(
|
||||
{
|
||||
userId: req.body.userId,
|
||||
startAt: scheduledSession?.startAt,
|
||||
},
|
||||
{
|
||||
userId: null,
|
||||
}
|
||||
);
|
||||
|
||||
await ScheduledSession.findByIdAndUpdate(
|
||||
req.params.scheduledSessionId,
|
||||
{
|
||||
userId: req.body.userId,
|
||||
}
|
||||
);
|
||||
res.json({ error: "Scheduled session at same time" });
|
||||
return;
|
||||
}
|
||||
|
||||
const buildUsers = await User.find({ buildIds: req.params.buildId });
|
||||
let buildUserIds = buildUsers.map((buildUser) => buildUser.toString());
|
||||
|
||||
const scheduledSessionsAtTime = await ScheduledSession.find({
|
||||
buildId: req.params.buildId,
|
||||
startAt: req.query.startAt,
|
||||
});
|
||||
|
||||
const scheduledSessionAtTimeUserIds: any[] = [];
|
||||
|
||||
for (const scheduledSessionAtTime of scheduledSessionsAtTime) {
|
||||
if (scheduledSessionAtTime.userId) {
|
||||
scheduledSessionAtTimeUserIds.push(
|
||||
scheduledSessionAtTime.userId.toString()
|
||||
);
|
||||
const updatedScheduledSession = await ScheduledSession.findByIdAndUpdate(
|
||||
req.params.scheduledSessionId,
|
||||
req.body,
|
||||
{
|
||||
new: true,
|
||||
upsert: true,
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
"scheduledSessionAtTimeUserIds",
|
||||
scheduledSessionAtTimeUserIds
|
||||
);
|
||||
|
||||
console.log("buildUserIds", buildUserIds);
|
||||
|
||||
const filteredUserIds: any[] = buildUserIds.filter(
|
||||
(buildUserId) => !scheduledSessionAtTimeUserIds.includes(buildUserId)
|
||||
);
|
||||
|
||||
console.log("filteredUserIds", filteredUserIds);
|
||||
|
||||
if (scheduledSession.userId) {
|
||||
filteredUserIds.push(scheduledSession.userId);
|
||||
}
|
||||
|
||||
console.log("filteredUserIds", filteredUserIds);
|
||||
|
||||
res.json(filteredUserIds);
|
||||
res.json(updatedScheduledSession);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
res.json({ error });
|
||||
@@ -234,57 +157,6 @@ router.get(
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/:id/builds/:buildId/schedules", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
const schedules = await Schedule.find({
|
||||
companyId: req.params.id,
|
||||
buildId: req.params.buildId,
|
||||
});
|
||||
|
||||
res.json(schedules);
|
||||
});
|
||||
|
||||
router.post("/:id/builds/:buildId/schedules", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied" });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const schedule = await Schedule.create({
|
||||
companyId: req.params.id,
|
||||
buildId: req.params.buildId,
|
||||
...req.body,
|
||||
});
|
||||
res.json(schedule);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
res.json({ error: error.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
router.get(
|
||||
"/:companyId/builds/:buildId/last_scheduled_session",
|
||||
async (req, res) => {
|
||||
const { buildId } = req.params;
|
||||
|
||||
try {
|
||||
const lastScheduledSession = await ScheduledSession.findOne({
|
||||
buildId,
|
||||
}).sort({ startAt: -1 });
|
||||
|
||||
res.json(lastScheduledSession);
|
||||
} catch (error) {
|
||||
res.json({ error: (error as Error).message });
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
router.get("/:companyId/users", async (req, res) => {
|
||||
try {
|
||||
const companyId = req.params.companyId;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import { Router } from "express";
|
||||
import Schedule from "../models/Schedule.js";
|
||||
|
||||
const schedulesRouter = Router();
|
||||
|
||||
schedulesRouter.get(
|
||||
"/companies/:companyId/builds/:buildId",
|
||||
async (req, res) => {
|
||||
const { companyId, buildId } = req.params;
|
||||
// const date = new Date();
|
||||
|
||||
const schedules = await Schedule.find({
|
||||
companyId,
|
||||
buildId,
|
||||
});
|
||||
|
||||
if (!schedules.length) {
|
||||
res.json({ error: "No data" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.query.date) {
|
||||
const schedule = await Schedule.findOne({
|
||||
companyId,
|
||||
buildId,
|
||||
});
|
||||
|
||||
res.json(schedule);
|
||||
return;
|
||||
}
|
||||
|
||||
res.json(schedules);
|
||||
}
|
||||
);
|
||||
|
||||
export default schedulesRouter;
|
||||
Reference in New Issue
Block a user