api/resources/Products/ProductModel.js
2024-02-07 10:09:40 +05:30

63 lines
1.4 KiB
JavaScript

import mongoose from "mongoose";
const { Schema, model } = mongoose;
const productSchema = new Schema(
{
name: {
type: String,
maxLength: [25, "name cannot exceed 25 characters"],
required: [true, "Please Enter product Name"],
trim: true,
},
uniqueId: {
type: String,
required: true,
},
description: {
type: String,
maxLength: [100, "description cannot exceed 100 characters"],
required: [true, "Please Enter product Description"],
},
price: {
type: Number,
required: [true, "Please Enter product Price"],
maxLength: [8, "Price can not exceed 8 characters"],
},
category: {
type: Schema.Types.ObjectId,
ref: "CategoryModel",
},
gst: {
type: Schema.Types.ObjectId,
ref: "Tax",
},
total_amount: {
type: Number,
required: true,
},
gst_amount: {
type: Number,
required: true,
},
image: [
{
public_id: {
type: String,
required: true,
},
url: {
type: String,
required: true,
},
},
],
addedBy: {
type: Schema.Types.ObjectId,
ref: "User",
},
},
{ timestamps: true }
);
export const Product = model("Product", productSchema);