Compare commits
3 Commits
6f59f75b41
...
3a79526eda
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a79526eda | |||
| 0b3a911611 | |||
| 02a05231d1 |
@ -1,7 +1,7 @@
|
|||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { generateId } from '../../utils.js';
|
import { generateId } from '../../utils.js';
|
||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose;
|
||||||
import { aggregateRollups, aggregateRollupsHistory } from '../../database.js';
|
import { aggregateRollups, aggregateRollupsHistory, editObject } from '../../database.js';
|
||||||
|
|
||||||
// Define the moonraker connection schema
|
// Define the moonraker connection schema
|
||||||
const moonrakerSchema = new Schema(
|
const moonrakerSchema = new Schema(
|
||||||
@ -123,6 +123,28 @@ printerSchema.statics.history = async function (from, to) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
printerSchema.statics.recalculate = async function (printer, user) {
|
||||||
|
if (printer.active === false && printer.state?.type !== 'inactive') {
|
||||||
|
await editObject({
|
||||||
|
model: this,
|
||||||
|
id: printer._id,
|
||||||
|
updateData: { state: { type: 'inactive' } },
|
||||||
|
user,
|
||||||
|
recalculate: false,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (printer.active === true && printer.state?.type === 'inactive' && printer.online === false) {
|
||||||
|
await editObject({
|
||||||
|
model: this,
|
||||||
|
id: printer._id,
|
||||||
|
updateData: { state: { type: 'offline' } },
|
||||||
|
user,
|
||||||
|
recalculate: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Add virtual id getter
|
// Add virtual id getter
|
||||||
printerSchema.virtual('id').get(function () {
|
printerSchema.virtual('id').get(function () {
|
||||||
return this._id;
|
return this._id;
|
||||||
|
|||||||
@ -142,6 +142,7 @@ export const newHostRouteHandler = async (req, res) => {
|
|||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
active: req.body.active,
|
active: req.body.active,
|
||||||
|
tags: req.body.tags,
|
||||||
};
|
};
|
||||||
const result = await newObject({
|
const result = await newObject({
|
||||||
model: hostModel,
|
model: hostModel,
|
||||||
|
|||||||
@ -50,6 +50,7 @@ const trimSpotlightObject = (object, objectType) => {
|
|||||||
objectType: objectType || undefined,
|
objectType: objectType || undefined,
|
||||||
online: object.online || undefined,
|
online: object.online || undefined,
|
||||||
amount: object.amount || undefined,
|
amount: object.amount || undefined,
|
||||||
|
unit: object.unit || undefined,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user