This commit is contained in:
2024-10-15 17:54:13 +05:00
parent ba69acf1ad
commit 45e972780a
11 changed files with 126 additions and 199 deletions
+4 -4
View File
@@ -21,14 +21,14 @@ companySchema.virtual("users", {
foreignField: "companyId",
});
companySchema.virtual("scheduledSessions", {
ref: "Scheduled_Session",
companySchema.virtual("builds", {
ref: "Build",
localField: "_id",
foreignField: "companyId",
});
companySchema.virtual("builds", {
ref: "Build",
companySchema.virtual("scheduledSessions", {
ref: "Scheduled_Session",
localField: "_id",
foreignField: "companyId",
});
+1 -1
View File
@@ -5,7 +5,7 @@ const scheduledSessionSchema = new Schema(
companyId: {
type: Schema.Types.ObjectId,
ref: "Company",
// required: true,
required: true,
},
buildId: {
type: Schema.Types.ObjectId,
+6 -12
View File
@@ -68,7 +68,7 @@ router.get("/:id/builds/:buildId/users", async (req, res) => {
res.json(users);
});
router.get("/:id/builds/:buildId/scheduled_sessions", async (req, res) => {
router.get("/:id/scheduled_sessions", async (req, res) => {
if (req.params.id != res.locals.user.companyId) {
res.json({ error: "Access denied" });
return;
@@ -82,22 +82,16 @@ router.get("/:id/builds/:buildId/scheduled_sessions", async (req, res) => {
const date = parseISO(req.query.date as string);
const company: any = await Company.findById(req.params.id).populate({
path: "builds",
path: "scheduledSessions",
match: {
_id: req.params.buildId,
},
populate: {
path: "scheduledSessions",
match: {
startAt: {
$gte: startOfDay(date),
$lte: endOfDay(date),
},
startAt: {
$gte: startOfDay(date),
$lte: endOfDay(date),
},
},
});
const { scheduledSessions } = company.builds[0];
const { scheduledSessions } = company;
res.json(scheduledSessions);
});
+4 -2
View File
@@ -75,9 +75,9 @@ router.get("/:buildId", async (req, res) => {
});
router.post("/", async (req, res) => {
const { buildId, slot, startAt, client, duration } = req.body;
const { companyId, buildId, slot, startAt, client, duration } = req.body;
if (!buildId || !startAt || !slot) {
if (!companyId || !buildId || !startAt || !slot) {
return res.json({
status: "error",
message: "Parameters `buildId`, `startAt`, `slot` are required!", // Параметры `buildId`, `startAt`, `slot` обязательны!
@@ -104,6 +104,7 @@ router.post("/", async (req, res) => {
if (duration) {
const scheduledSessions = await ScheduledSession.find({
companyId,
buildId,
slot,
startAt: {
@@ -141,6 +142,7 @@ router.post("/", async (req, res) => {
}
const scheduledSession = await ScheduledSession.create({
companyId,
buildId,
slot,
startAt: startAtISO,