This repository has been archived on 2026-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
allotment/packages/server/db/models/WaterSchedule.schema.js

39 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import mongoose from "mongoose";
const START_AT_TYPES = ["sunset", "daylight"];
const waterScheduleSchema = new mongoose.Schema(
{
/** MongoDB ref to the `Patch` document (not the logical `patchId` string). */
patch: {
type: mongoose.Schema.Types.ObjectId,
ref: "Patch",
required: true,
index: true,
},
/** Calendar / anchor date (and optional wall-clock context for future use). */
startAt: { type: Date, required: true },
startAtType: {
type: String,
enum: START_AT_TYPES,
required: true,
},
/** Minutes from the anchor implied by `startAtType` (see `timelineMinutesFromSchedule`). */
offset: { type: Number, default: 0 },
/** How long watering should run, in minutes; `endAt` is derived from `startAt` + this. */
durationMinutes: { type: Number, default: 30 },
/** Inclusive end of the watering window (computed on save from `startAt` + `durationMinutes`). */
endAt: { type: Date },
targetSoilHumidityEnabled: { type: Boolean, default: false },
/** 0–100 when enabled; otherwise unset. */
targetSoilHumidity: { type: Number, default: null },
/** Pump / flow intensity 0–100. */
waterPower: { type: Number, default: 100 },
},
{ timestamps: true },
);
waterScheduleSchema.index({ patch: 1, startAt: 1 });
export const WaterSchedule = mongoose.model("WaterSchedule", waterScheduleSchema);