Update stock audit level schema to require tags and improve code readability

This commit modifies the `stockAuditLevel` schema by making the `tags` field required, ensuring that all stock audit levels have associated tags for better categorization. Additionally, it enhances the readability of the `normalizeAuditLevelLine` function by adjusting the formatting of the item and itemSku assignments, improving overall code clarity.
This commit is contained in:
Tom Butcher 2026-09-01 15:51:25 +01:00
parent bce40ce30d
commit 6623bf9bfd

View File

@ -13,8 +13,8 @@ const toId = (value) => {
export function normalizeAuditLevelLine(line) { export function normalizeAuditLevelLine(line) {
const allItems = Boolean(line?.allItems); const allItems = Boolean(line?.allItems);
const allSkus = allItems ? true : Boolean(line?.allSkus); const allSkus = allItems ? true : Boolean(line?.allSkus);
const item = allItems ? null : line?.item?._id ?? line?.item ?? null; const item = allItems ? null : (line?.item?._id ?? line?.item ?? null);
const itemSku = allItems || allSkus ? null : line?.itemSku?._id ?? line?.itemSku ?? null; const itemSku = allItems || allSkus ? null : (line?.itemSku?._id ?? line?.itemSku ?? null);
return { return {
_id: line?._id, _id: line?._id,
@ -62,7 +62,7 @@ const stockAuditLevelSchema = new Schema(
{ {
_reference: { type: String, default: () => generateId()() }, _reference: { type: String, default: () => generateId()() },
name: { type: String, required: true }, name: { type: String, required: true },
tags: [{ type: String }], tags: [{ type: String, required: true }],
auditLines: { type: [stockAuditLevelLineSchema], default: [] }, auditLines: { type: [stockAuditLevelLineSchema], default: [] },
}, },
{ timestamps: true } { timestamps: true }