Code Monkey home page Code Monkey logo

ad_mongo2's Introduction

Advance Schema

Brand Schema ::

    const mongoose = require("mongoose");
    const validator = require("validator");
    const { ObjectId } = mongoose.Schema.Types;

    const brandSchema = mongoose.Schema(
    {
        name: {
        type: String,
        trim: true,
        required: [true, "Provide a brand name"],
        maxLength: 100,
        unique: true,
        lowercase: true,
        },
        description: String,
        email: {
        type: String,
        validator: [validator.isEmail, "Please provide a valid Email"],
        },
        website: {
        type: String,
        validator: [validator.isURL, "Please provide a valid Number"],
        },
        products: [
        {
            name: String,
            contactNumber: String,
            id: {
            type: ObjectId,
            ref: "Supplier",
            },
        },
        ],
        status: {
        type: String,
        enum: ["active", "inactive"],
        default: "active",
        },
    },
    {
        timestamps: true,
    }
    );

Category Schema :::

    const validator = require("validator");
    const { ObjectId } = mongoose.Schema.Types;

    const categorySchemas = -mongoose.Schema(
    {
        name: {
        type: String,
        trim: true,
        required: [true, "Please provide a name"],
        lowercase: true,
        unique: true,
        },
        description: String,
        imageURL: {
        type: String,
        validator: [validator.isURL, "Please provide a valid url"],
        },
    },
    {
        timeStamps: true,
    }
    );

Product Schema :::

        const mongoose = require("mongoose");
        const validator = require("validator");
        const { ObjectId } = mongoose.Schema.Types;

        const ProductSchema = mongoose.Schema(
        {
            name: {
            type: String,
            trim: true,
            required: [true, "Provide a Product name"],
            maxLength: [100, "Name is too longer"],
            unique: [true, "Name must be Unique"],
            minLength: [2, "Name must be 2 character."],
            },
            description: {
            type: String,
            required: true,
            },
            price: {
            type: String,
            required: true,
            min: [0, "Price cannot be negative"],
            },
            unit: {
            type: String,
            required: true,
            enum: {
                values: ["kg", "litre", "pcs", "bag"],
                message: "unit value can not be {VALUE} . must be kg/litre/pcs/bag",
            },
            },
            imageURL: {
            type: String,
            required: true,
            validate: {
                validator: (value) => {
                if (!Array.isArray(value)) {
                    return false; 
                }
                let isValid = true;
                value.forEach((url) => {
                    if (!validator.isURL(url)) {
                    isValid = false;
                    }
                });
                return isValid;
                },
                message: "Please provide valid url",
            },
            },
            category: {
            type: String,
            required: true,
            },
            brand: {
            name: {
                type: String,
                required: true,
            },
            id: {
                type: ObjectId,
                ref: "Brand",
                required: true,
            },
            },
        },
        {
            timestamps: true,
        }
        );

Stock Schemas

const mongoose = require("mongoose");
const validator = require("validator");
const { ObjectId } = mongoose.Schema.Types;

const StockSchema = mongoose.Schema(
{
    productId: {
    type: ObjectId,
    ref: "Product",
    required: true,
    },
    name: {
    type: String,
    trim: true,
    required: [true, "Provide a Stock name"],
    maxLength: [100, "Name is too longer"],
    unique: [true, "Name must be Unique"],
    minLength: [2, "Name must be 2 character."],
    },
    description: {
    type: String,
    required: true,
    },
    price: {
    type: String,
    required: true,
    min: [0, "Price cannot be negative"],
    },
    quantity: {
    type: String,
    required: true,
    min: [0, "Product quantity cannot be negative"],
    },
    
    unit: {
    type: String,
    required: true,
    enum: {
        values: ["kg", "litre", "pcs", "bag"],
        message: "unit value can not be {VALUE} . must be kg/litre/pcs/bag",
    },
    },
    imageURL: {
    type: String,
    required: true,
    validate: {
        validator: (value) => {
        if (!Array.isArray(value)) {
            return false;
        }
        let isValid = true;
        value.forEach((url) => {
            if (!validator.isURL(url)) {
            isValid = false;
            }
        });
        return isValid;
        },
        message: "Please provide valid url",
    },
    },
    category: {
    type: String,
    required: true,
    },

    brand: {
    name: {
        type: String,
        required: true,
    },
    id: {
        type: ObjectId,
        ref: "Brand",
        required: true,
    },
    },
    status: {
    type: String,
    required: true,
    enum: {
        values: ["in-stock", "out-of-stock", "discontinued"],
        message: "status  can not be  {VALUES} ",
    },
    },
    store:{
        name: {
            type: String,
            trim: true,
            required: [true, "Provide a Store name"],
            maxLength: 100,
            unique: true,
            lowercase: true,
            enum: {
            values: ["dhaka", "chattogram","rajshahi","khulna", "barishal", "mymansing","rangpur", ],
            message: "{VALUE} is not value name",
            },
        },
        id:{
            type:ObjectId,
            required:true,
            ref:"Store"
        }
    },
    supplierBy:{
        name:{
            type: String,
            trim: true,
            required: [true, "Provide a Store name"]
        },
        id:{
            type:ObjectId,
            required:true,
            ref:"Supplier"
            
        }
    }
},
{
    timestamps: true,
}
);

ad_mongo2's People

Contributors

sarwarasik avatar sarwar-asik avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.