Refactor stock transfer schema to improve location management
Some checks failed
farmcontrol/farmcontrol-ws/pipeline/head There was a failure building this commit

- Removed the `toStockLocation` field from the `stockTransferLineSchema` to streamline the schema.
- Introduced `fromLocation` and `toLocation` fields in the `stockTransferSchema` for better clarity in stock transfer processes.
- Updated the text index to focus on `state.type` for improved search capabilities.
This commit is contained in:
Tom Butcher 2026-09-01 16:04:38 +01:00
parent 5349538046
commit 6bf0568f23

View File

@ -15,11 +15,6 @@ const stockTransferLineSchema = new Schema(
required: true,
},
quantity: { type: Number, required: true },
toStockLocation: {
type: Schema.Types.ObjectId,
ref: 'stockLocation',
required: true,
},
toStockType: {
type: String,
required: false,
@ -37,18 +32,27 @@ const stockTransferLineSchema = new Schema(
const stockTransferSchema = new Schema(
{
_reference: { type: String, default: () => generateId()() },
name: { type: String, required: true },
state: {
type: { type: String, required: true, default: 'draft' },
progress: { type: Number, required: false },
},
postedAt: { type: Date, required: false },
fromLocation: {
type: Schema.Types.ObjectId,
ref: 'stockLocation',
required: true,
},
toLocation: {
type: Schema.Types.ObjectId,
ref: 'stockLocation',
required: true,
},
lines: { type: [stockTransferLineSchema], default: [] },
},
{ timestamps: true }
);
stockTransferSchema.index({ name: 'text' });
stockTransferSchema.index({ 'state.type': 'text' });
stockTransferSchema.statics.stats = async function () {
const [draft, posted] = await Promise.all([