39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
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);
|