pl4y-data-library
Version:
This library contains the dtos, enums, schemas, and other data objects needed in the pl4y ecosystem.
64 lines (49 loc) • 1.6 kB
text/typescript
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { Document } from "mongoose";
import { ProductUOM } from "../enums/product-uom.enum";
import { ProductCategory } from "../enums/product-categories.enum";
// Defines the interface for your document
export type ProductDocument = Product & Document;
()
export class Product {
({ required: true, unique: true })
name: string;
({ required: true })
brand: string;
({
type: Number,
enum: Object.values(ProductCategory).filter((value) => typeof value === "number"),
default: ProductCategory.UNSPECIFIED,
})
category: ProductCategory;
/**
* Properties worked on by a restriction service
* */
({ required: false })
regulationType: string;
({ required: false })
minimumAge: number;
({ required: false })
requiresVerification: boolean;
/**
* Properties worked on by a restriction service
* */
({ default: false })
isWeighable: boolean;
({ required: true, default: 1 })
quantity: number;
({ default: 0.001 })
weight: number;
({
type: Number,
enum: Object.values(ProductUOM).filter((value) => typeof value === "number"), // Filter numeric values
default: ProductUOM.UNSPECIFIED,
})
uom: ProductUOM;
({ required: true })
upc: string;
({ required: true })
sku: string;
}
// Generates the actual Mongoose Schema
export const ProductSchema = SchemaFactory.createForClass(Product);