All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Removed unnecessary line breaks in the subjob schema to enhance code clarity. - Ensured all required fields maintain their definitions for better data integrity. - Updated formatting for the `state` field to align with coding standards.
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
import mongoose from 'mongoose';
|
|
import { generateId } from '../../utils.js';
|
|
const { Schema } = mongoose;
|
|
|
|
const subJobSchema = new mongoose.Schema({
|
|
_reference: { type: String, default: () => generateId()() },
|
|
printer: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'printer',
|
|
required: true
|
|
},
|
|
job: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'job',
|
|
required: true
|
|
},
|
|
moonrakerJobId: {
|
|
type: String,
|
|
required: false
|
|
},
|
|
gcodeFile: {
|
|
type: Schema.Types.ObjectId,
|
|
ref: 'gcodeFile',
|
|
required: true
|
|
},
|
|
state: {
|
|
type: { required: true, type: String },
|
|
progress: { required: false, type: Number }
|
|
},
|
|
number: {
|
|
type: Number,
|
|
required: true
|
|
},
|
|
createdAt: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
updatedAt: {
|
|
type: Date,
|
|
default: Date.now
|
|
},
|
|
startedAt: { required: false, type: Date, default: null },
|
|
finishedAt: { required: false, type: Date, default: null }
|
|
});
|
|
|
|
subJobSchema.index({ moonrakerJobId: 'text', 'state.type': 'text' });
|
|
|
|
subJobSchema.virtual('id').get(function () {
|
|
return this._id;
|
|
});
|
|
|
|
subJobSchema.set('toJSON', { virtuals: true });
|
|
|
|
export const subJobModel = mongoose.model('subJob', subJobSchema);
|