Spaces:
Sleeping
Sleeping
Download models/ProductModel.js from Mahmoud7456/MultiUsersSalesSystem: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/spaces/Mahmoud7456/MultiUsersSalesSystem/resolve/main/models/ProductModel.js
- Command line
-
hf download hf://spaces/Mahmoud7456/MultiUsersSalesSystem/models/ProductModel.js
-
curl -L -o ProductModel.js https://huggingface.co/spaces/Mahmoud7456/MultiUsersSalesSystem/resolve/main/models/ProductModel.js
1.76 kB
| import mongoose from "mongoose"; | |
| const productSchema = new mongoose.Schema( | |
| { | |
| tenant: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: "Tenant", | |
| required: true, | |
| index: true, | |
| }, | |
| branch: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: "Branch", | |
| default: null, | |
| index: true, | |
| }, | |
| name: { | |
| type: String, | |
| required: true, | |
| }, | |
| description: { | |
| type: String, | |
| default: "", | |
| }, | |
| price: { | |
| type: Number, | |
| required: true, | |
| }, | |
| costPrice: { | |
| type: Number, | |
| default: 0, | |
| }, | |
| stock: { | |
| type: Number, | |
| required: true, | |
| default: 0, | |
| }, | |
| barcode: { | |
| type: String, | |
| default: "", | |
| }, | |
| sku: { | |
| type: String, | |
| default: "", | |
| }, | |
| unit: { | |
| type: String, | |
| default: "piece", | |
| }, | |
| category: { | |
| type: String, | |
| default: "عام", | |
| }, | |
| lowStockThreshold: { | |
| type: Number, | |
| default: 5, | |
| }, | |
| createdBy: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: "User", | |
| default: null, | |
| }, | |
| }, | |
| { timestamps: true } | |
| ); | |
| // Product name must be unique per branch | |
| productSchema.index( | |
| { tenant: 1, branch: 1, name: 1 }, | |
| { unique: true } | |
| ); | |
| // Barcode must be unique per branch (only if exists) | |
| productSchema.index( | |
| { tenant: 1, branch: 1, barcode: 1 }, | |
| { | |
| unique: true, | |
| partialFilterExpression: { barcode: { $exists: true, $gt: "" } } | |
| } | |
| ); | |
| export default mongoose.model("Product", productSchema); | |