feat: add backend server
This commit is contained in:
79
server/model/stability.js
Normal file
79
server/model/stability.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import mongoose from 'mongoose'
|
||||
import User from './user.js'
|
||||
|
||||
const CheckSchema = new mongoose.Schema(
|
||||
{
|
||||
// 检查日期
|
||||
date: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
// 是否已经检查
|
||||
checked: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
// 检查人
|
||||
checker: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
},
|
||||
// 备注
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
|
||||
// 稳定性实验 模型
|
||||
const StabilitySchema = new mongoose.Schema(
|
||||
{
|
||||
// 实验批次号
|
||||
batch: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
// 实验类型
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['长期', '加速', '其它'],
|
||||
},
|
||||
// 检查点列表
|
||||
checks: {
|
||||
type: [CheckSchema],
|
||||
default: [],
|
||||
},
|
||||
// 是否完成
|
||||
ended: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 创建人
|
||||
creater: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
},
|
||||
// 备注
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
)
|
||||
|
||||
StabilitySchema.pre('save', async function () {
|
||||
try {
|
||||
this.checks = this.checks.sort((a, b) => {
|
||||
return new Date(a.date) - new Date(b.date)
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
})
|
||||
|
||||
const Stability = mongoose.model('Stability', StabilitySchema)
|
||||
|
||||
export default Stability
|
||||
Reference in New Issue
Block a user