This commit is contained in:
2024-06-11 21:18:54 +05:00
parent ac1a705187
commit e155066534
20 changed files with 520 additions and 113 deletions
+1 -2
View File
@@ -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 });
+28 -27
View File
@@ -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;