upd
This commit is contained in:
+2
-2
@@ -7,11 +7,11 @@ import registrationRouter from "./routes/registration";
|
||||
import authMiddleware from "./middlewares/auth";
|
||||
import appRouter from "./routes/app";
|
||||
import companiesRouter from "./routes/companies";
|
||||
import scheduledSessionsRouter from "./routes/scheduledSessions";
|
||||
import usersRouter from "./routes/users";
|
||||
import buildsRouter from "./routes/builds";
|
||||
import actionsRouter from "./routes/actions";
|
||||
import schedulesRouter from "./routes/schedules";
|
||||
import scheduledSessionsRoute from "./routes/scheduledSessions";
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
@@ -25,7 +25,7 @@ app.use("/login", loginRouter);
|
||||
app.use("/registration", registrationRouter);
|
||||
app.use("/actions", actionsRouter);
|
||||
app.use("/builds", buildsRouter);
|
||||
app.use("/scheduled_sessions", scheduledSessionsRouter);
|
||||
app.use("/scheduled_sessions", scheduledSessionsRoute);
|
||||
app.use("/schedules", schedulesRouter);
|
||||
app.use("/app", authMiddleware, appRouter);
|
||||
app.use("/companies", authMiddleware, companiesRouter);
|
||||
|
||||
@@ -256,11 +256,10 @@ router.post("/:id/builds/:buildId/schedules", async (req, res) => {
|
||||
router.get(
|
||||
"/:companyId/builds/:buildId/last_scheduled_session",
|
||||
async (req, res) => {
|
||||
const { companyId, buildId } = req.params;
|
||||
const { buildId } = req.params;
|
||||
|
||||
try {
|
||||
const lastScheduledSession = await ScheduledSession.findOne({
|
||||
companyId,
|
||||
buildId,
|
||||
}).sort({ startAt: -1 });
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import {
|
||||
startOfDay,
|
||||
} from "date-fns";
|
||||
|
||||
const scheduledSessionsRouter = Router();
|
||||
const router = Router();
|
||||
|
||||
scheduledSessionsRouter.get("/", async (_req, res) => {
|
||||
router.get("/", async (_req, res) => {
|
||||
const scheduledSessions = await ScheduledSession.find({
|
||||
startAt: { $gte: startOfDay(new Date()) },
|
||||
endAt: { $lte: endOfDay(new Date()) },
|
||||
@@ -22,37 +22,34 @@ scheduledSessionsRouter.get("/", async (_req, res) => {
|
||||
res.json(scheduledSessions);
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.get("/:id", async (req, res) => {
|
||||
router.get("/:id", async (req, res) => {
|
||||
const scheduledSessionId = req.params.id;
|
||||
const scheduledSession = await ScheduledSession.findById(scheduledSessionId);
|
||||
|
||||
res.json(scheduledSession);
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.get(
|
||||
"/companies/:companyId/builds/:buildId",
|
||||
async (req, res) => {
|
||||
const { companyId, buildId } = req.params;
|
||||
const { date } = req.query;
|
||||
router.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)),
|
||||
},
|
||||
});
|
||||
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 });
|
||||
}
|
||||
res.json(scheduledSessions);
|
||||
} catch (error) {
|
||||
res.json({ error: (error as Error).message });
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.get("/:buildId", async (req, res) => {
|
||||
router.get("/:buildId", async (req, res) => {
|
||||
if (!req.params.buildId) {
|
||||
res.json({ error: "Parameter `buildId` is required" });
|
||||
return;
|
||||
@@ -76,9 +73,11 @@ scheduledSessionsRouter.get("/:buildId", async (req, res) => {
|
||||
res.json(scheduledSessions);
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.post("/", async (req, res) => {
|
||||
router.post("/", async (req, res) => {
|
||||
const { buildId, startAt, client, duration } = req.body;
|
||||
|
||||
console.log("client", client);
|
||||
|
||||
if (!buildId || !startAt) {
|
||||
return res.json({
|
||||
status: "error",
|
||||
@@ -217,7 +216,7 @@ scheduledSessionsRouter.post("/", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.put("/:id", async (req, res) => {
|
||||
router.put("/:id", async (req, res) => {
|
||||
const scheduledSessionId = req.params.id;
|
||||
|
||||
let {
|
||||
@@ -248,7 +247,7 @@ scheduledSessionsRouter.put("/:id", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
scheduledSessionsRouter.delete("/:id", async (req, res) => {
|
||||
router.delete("/:id", async (req, res) => {
|
||||
const scheduledSessionId = req.params.id;
|
||||
|
||||
try {
|
||||
@@ -262,4 +261,6 @@ scheduledSessionsRouter.delete("/:id", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
export default scheduledSessionsRouter;
|
||||
const scheduledSessionsRoute = router;
|
||||
|
||||
export default scheduledSessionsRoute;
|
||||
|
||||
Reference in New Issue
Block a user