- Add WarehouseItem model with bilingual names (FA/EN) and bilingual counting units - Add WarehouseItemTransaction model for IN/OUT movements with reason and actor - Add WarehouseItemStock model for denormalized per-(item×warehouse) running balance - Add warehouseItemService with full CRUD, atomic stock updates via $inc, negative stock guard, and aggregation queries for per-item/per-warehouse/total stock - Add warehouseItemController and REST routes at /api/warehouse-items - Add warehouseService, warehouseController, warehouseRoutes for warehouse location CRUD at /api/warehouses - Register both route groups in routerEndpoints.js
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const mongoose = require('mongoose')
|
|
|
|
const warehouseItemSchema = new mongoose.Schema(
|
|
{
|
|
nameFa: {
|
|
type: String,
|
|
required: true, // نام فارسی — مثال: سیمان، آجر
|
|
},
|
|
nameEn: {
|
|
type: String,
|
|
required: true, // English name — e.g. Cement, Brick
|
|
},
|
|
code: {
|
|
type: String,
|
|
unique: true,
|
|
sparse: true, // optional unique code, e.g. CEM, BRK
|
|
},
|
|
unitFa: {
|
|
type: String,
|
|
required: true, // واحد شمارش فارسی — مثال: تن، عدد، متر
|
|
},
|
|
unitEn: {
|
|
type: String,
|
|
required: true, // English counting unit — e.g. Ton, Piece, Meter
|
|
},
|
|
category: {
|
|
type: String, // e.g. "مصالح ساختمانی", "تأسیسات"
|
|
},
|
|
description: String,
|
|
isActive: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
{
|
|
timestamps: true,
|
|
}
|
|
)
|
|
|
|
warehouseItemSchema.index({ nameFa: 'text', nameEn: 'text', code: 'text' })
|
|
|
|
const WarehouseItem = mongoose.model('WarehouseItem', warehouseItemSchema)
|
|
module.exports = WarehouseItem
|