UNPKG

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
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; @Schema() export class Product { @Prop({ required: true, unique: true }) name: string; @Prop({ required: true }) brand: string; @Prop({ type: Number, enum: Object.values(ProductCategory).filter((value) => typeof value === "number"), default: ProductCategory.UNSPECIFIED, }) category: ProductCategory; /** * Properties worked on by a restriction service * */ @Prop({ required: false }) regulationType: string; @Prop({ required: false }) minimumAge: number; @Prop({ required: false }) requiresVerification: boolean; /** * Properties worked on by a restriction service * */ @Prop({ default: false }) isWeighable: boolean; @Prop({ required: true, default: 1 }) quantity: number; @Prop({ default: 0.001 }) weight: number; @Prop({ type: Number, enum: Object.values(ProductUOM).filter((value) => typeof value === "number"), // Filter numeric values default: ProductUOM.UNSPECIFIED, }) uom: ProductUOM; @Prop({ required: true }) upc: string; @Prop({ required: true }) sku: string; } // Generates the actual Mongoose Schema export const ProductSchema = SchemaFactory.createForClass(Product);