@tabletennisshop/common 1.0.33 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- export declare enum ProductStatus {
1
+ export declare enum ProductStatusEnum {
2
2
  ENABLE = "enable",
3
3
  DISABLE = "disable",
4
4
  OUT_OF_STOCK = "out_of_stock"
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProductStatus = void 0;
4
- var ProductStatus;
5
- (function (ProductStatus) {
6
- ProductStatus["ENABLE"] = "enable";
7
- ProductStatus["DISABLE"] = "disable";
8
- ProductStatus["OUT_OF_STOCK"] = "out_of_stock";
9
- })(ProductStatus || (exports.ProductStatus = ProductStatus = {}));
3
+ exports.ProductStatusEnum = void 0;
4
+ var ProductStatusEnum;
5
+ (function (ProductStatusEnum) {
6
+ ProductStatusEnum["ENABLE"] = "enable";
7
+ ProductStatusEnum["DISABLE"] = "disable";
8
+ ProductStatusEnum["OUT_OF_STOCK"] = "out_of_stock";
9
+ })(ProductStatusEnum || (exports.ProductStatusEnum = ProductStatusEnum = {}));
@@ -0,0 +1,16 @@
1
+ import { Document } from "mongoose";
2
+ export interface IInventory {
3
+ product_id: string;
4
+ total_quantity: number;
5
+ serials?: string[];
6
+ }
7
+ interface InventoryDoc extends IInventory, Document {
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ }
11
+ export declare const InventoryModel: import("mongoose").Model<InventoryDoc, {}, {}, {}, Document<unknown, {}, InventoryDoc, {}> & InventoryDoc & Required<{
12
+ _id: unknown;
13
+ }> & {
14
+ __v: number;
15
+ }, any>;
16
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InventoryModel = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ // Define the schema for the inventory model
6
+ const InventorySchema = new mongoose_1.Schema({
7
+ product_id: { type: String, required: true, ref: 'Product' }, // Reference to the Product model
8
+ total_quantity: { type: Number, required: true, default: 0 }, // Total quantity of the product
9
+ serials: { type: [String], required: false }, // Optional array of serial numbers
10
+ }, {
11
+ timestamps: true, // Automatically manage createdAt and updatedAt fields
12
+ collection: 'inventory' // Name of the collection in MongoDB
13
+ });
14
+ InventorySchema.statics.build = (attrs) => {
15
+ return new exports.InventoryModel(attrs);
16
+ };
17
+ // Create the Inventory model
18
+ exports.InventoryModel = (0, mongoose_1.model)('Inventory', InventorySchema);
@@ -5,6 +5,8 @@ import { IStatusTimestamps } from './status-timestamp.schema';
5
5
  import { PaymentMethodEnum } from '../enums/payment-method.enum';
6
6
  export interface IOrderProduct {
7
7
  product_id: Types.ObjectId;
8
+ serial?: string;
9
+ price: number;
8
10
  quantity: number;
9
11
  }
10
12
  export interface OrderAttrs {
@@ -19,7 +21,7 @@ export interface OrderDoc extends Document {
19
21
  user_id: Types.ObjectId;
20
22
  address: IAddress;
21
23
  products: IOrderProduct[];
22
- status?: OrderStatusEnum;
24
+ status: OrderStatusEnum;
23
25
  statusTimestamps: IStatusTimestamps;
24
26
  payment_method: PaymentMethodEnum;
25
27
  }
@@ -3,20 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OrderModel = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const address_schema_1 = require("./address.schema");
6
+ const order_status_enum_1 = require("../enums/order-status.enum");
6
7
  const status_timestamp_schema_1 = require("./status-timestamp.schema");
7
8
  const payment_method_enum_1 = require("../enums/payment-method.enum");
8
9
  const OrderSchema = new mongoose_1.Schema({
9
10
  user_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', required: true }, // FK to User
10
11
  address: { type: address_schema_1.AddressSchema, required: true },
11
- products: [
12
- {
13
- product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true }, // FK to Product
14
- quantity: { type: Number, required: true },
15
- },
16
- ],
17
- status: { type: String, required: true },
12
+ products: {
13
+ type: [
14
+ {
15
+ product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true }, // FK to Product
16
+ serial: { type: String, required: false }, // Optional serial number for the product
17
+ price: { type: Number, required: true }, // Price of the product at the time of order
18
+ quantity: { type: Number, required: true },
19
+ },
20
+ ]
21
+ },
22
+ status: { type: String, enum: order_status_enum_1.OrderStatusEnum, required: true },
18
23
  statusTimestamps: { type: status_timestamp_schema_1.StatusTimestampsSchema, require: true },
19
- payment_method: { type: String, enum: payment_method_enum_1.PaymentMethodEnum, required: true }
24
+ payment_method: { type: String, enum: Object.values(payment_method_enum_1.PaymentMethodEnum), required: true }
20
25
  }, { collection: 'order' });
21
26
  OrderSchema.statics.build = (attrs) => {
22
27
  return new exports.OrderModel(attrs);
@@ -1,16 +1,16 @@
1
1
  import mongoose, { Document } from 'mongoose';
2
2
  import { ProductTypeEnum } from '../enums/product-type.enum';
3
- import { ProductStatus } from '../enums/product-status.enum';
3
+ import { ProductStatusEnum } from '../enums/product-status.enum';
4
4
  export interface ProductAttrsBase {
5
5
  name: string;
6
6
  slug: string;
7
7
  brand: string;
8
8
  description: string;
9
- type: ProductTypeEnum;
10
9
  sport: string;
11
- attributes: any;
12
- status: ProductStatus;
10
+ type: ProductTypeEnum;
11
+ attributes?: any;
13
12
  price: number;
13
+ status: ProductStatusEnum;
14
14
  }
15
15
  export interface ProductDoc extends Document {
16
16
  name: string;
@@ -19,8 +19,8 @@ export interface ProductDoc extends Document {
19
19
  description: string;
20
20
  type: ProductTypeEnum;
21
21
  sport: string;
22
- attributes: any;
23
- status: ProductStatus;
22
+ attributes?: any;
23
+ status: ProductStatusEnum;
24
24
  price: number;
25
25
  createdAt: Date;
26
26
  updatedAt: Date;
@@ -61,10 +61,10 @@ const ProductSchema = new mongoose_1.Schema({
61
61
  slug: { type: String, required: true, unique: true },
62
62
  brand: { type: String, required: true },
63
63
  description: { type: String, required: false },
64
- type: { type: String, enum: Object.values(product_type_enum_1.ProductTypeEnum), required: true },
64
+ type: { type: String, enum: Object.values(product_type_enum_1.ProductTypeEnum), required: true }, // Discriminator key
65
65
  sport: { type: String, required: true },
66
66
  attributes: { type: [mongoose_1.Schema.Types.Mixed], required: false },
67
- status: { type: String, enum: Object.values(product_status_enum_1.ProductStatus), default: product_status_enum_1.ProductStatus.ENABLE },
67
+ status: { type: String, enum: Object.values(product_status_enum_1.ProductStatusEnum), default: product_status_enum_1.ProductStatusEnum.ENABLE },
68
68
  price: { type: Number, required: true },
69
69
  }, baseOptions);
70
70
  ProductSchema.pre("save", function (next) {
@@ -1,3 +1,4 @@
1
+ import { Model } from "mongoose";
1
2
  import { ProductTypeEnum } from "../enums/product-type.enum";
2
3
  import { ProductAttrsBase, ProductDoc } from "./product.model";
3
4
  export interface ShirtAttrs extends ProductAttrsBase {
@@ -6,3 +7,8 @@ export interface ShirtAttrs extends ProductAttrsBase {
6
7
  export interface ShirtDoc extends ProductDoc {
7
8
  type: ProductTypeEnum.SHIRT;
8
9
  }
10
+ export declare const ShirtModel: Model<unknown, {}, {}, {}, import("mongoose").Document<unknown, {}, unknown, {}> & {
11
+ _id: import("mongoose").Types.ObjectId;
12
+ } & {
13
+ __v: number;
14
+ }, any>;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShirtModel = void 0;
3
4
  const mongoose_1 = require("mongoose");
4
5
  const product_type_enum_1 = require("../enums/product-type.enum");
5
6
  const product_model_1 = require("./product.model");
6
7
  const shirtSchema = new mongoose_1.Schema({});
7
8
  shirtSchema.statics.build = (attrs) => {
8
- return new ShirtModel(attrs);
9
+ return new exports.ShirtModel(attrs);
9
10
  };
10
- const ShirtModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SHIRT, new mongoose_1.Schema({}));
11
+ exports.ShirtModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SHIRT, new mongoose_1.Schema({}));
@@ -1,3 +1,4 @@
1
+ import { Model } from "mongoose";
1
2
  import { ProductTypeEnum } from "../enums/product-type.enum";
2
3
  import { ProductAttrsBase, ProductDoc } from "./product.model";
3
4
  export interface SpongeAttrs extends ProductAttrsBase {
@@ -6,3 +7,8 @@ export interface SpongeAttrs extends ProductAttrsBase {
6
7
  export interface SpongeDoc extends ProductDoc {
7
8
  type: ProductTypeEnum.SPONGE;
8
9
  }
10
+ interface SpongeModel extends Model<SpongeDoc> {
11
+ build(attrs: SpongeAttrs): SpongeDoc;
12
+ }
13
+ export declare const SpongeModel: SpongeModel;
14
+ export {};
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpongeModel = void 0;
3
4
  const mongoose_1 = require("mongoose");
4
5
  const product_type_enum_1 = require("../enums/product-type.enum");
5
6
  const product_model_1 = require("./product.model");
6
7
  const spongeSchema = new mongoose_1.Schema({});
7
8
  spongeSchema.statics.build = (attrs) => {
8
- return new SpongeModel(attrs);
9
+ return new exports.SpongeModel(attrs);
9
10
  };
10
11
  // ─────────── Sponge ───────────
11
- const SpongeModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SPONGE, new mongoose_1.Schema({}));
12
+ exports.SpongeModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SPONGE, new mongoose_1.Schema({}));
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StatusTimestampsSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  exports.StatusTimestampsSchema = new mongoose_1.Schema({
6
- pending_at: { type: Date },
7
- confirmed_at: { type: Date },
8
- delivering_at: { type: Date },
9
- finished_at: { type: Date },
10
- cancelled_at: { type: Date },
11
- returned_at: { type: Date },
12
- failed_at: { type: Date },
6
+ pending_at: { type: Date, required: false },
7
+ confirmed_at: { type: Date, required: false },
8
+ delivering_at: { type: Date, required: false },
9
+ finished_at: { type: Date, required: false },
10
+ cancelled_at: { type: Date, required: false },
11
+ returned_at: { type: Date, required: false },
12
+ failed_at: { type: Date, required: false },
13
13
  }, { _id: false });
@@ -18,6 +18,8 @@ interface UserDoc extends Document {
18
18
  addresses: IAddress[];
19
19
  type: string;
20
20
  status: UserStatusEnum;
21
+ createdAt: Date;
22
+ updatedAt: Date;
21
23
  }
22
24
  interface UserModel extends Model<UserDoc> {
23
25
  build(attrs: UserAttrs): UserDoc;
@@ -20,9 +20,10 @@ const UserSchema = new mongoose_1.Schema({
20
20
  email: { type: String, required: true, unique: true },
21
21
  password: { type: String, required: true, minlength: 4 },
22
22
  full_name: { type: String, required: true },
23
- addresses: [
24
- { type: address_schema_1.AddressSchema, required: true }
25
- ],
23
+ addresses: {
24
+ type: [address_schema_1.AddressSchema], // Use the AddressSchema defined in address.schema.ts
25
+ required: true
26
+ },
26
27
  type: { type: String, enum: Object.values(user_enum_1.UserEnum), required: true },
27
28
  status: { type: String, enum: Object.values(user_status_enum_1.UserStatusEnum), required: true }
28
29
  }, {
@@ -3,12 +3,15 @@ export interface IVendorPurchase {
3
3
  vendor_id: Types.ObjectId;
4
4
  products: {
5
5
  product_id: Types.ObjectId;
6
+ serials?: string[];
6
7
  price: number;
7
8
  quantity: number;
8
9
  }[];
9
10
  date: Date;
10
11
  }
11
12
  interface VendorPurchaseDoc extends IVendorPurchase, Document {
13
+ createdAt: Date;
14
+ updatedAt: Date;
12
15
  }
13
16
  export declare const VendorPurchaseModel: import("mongoose").Model<VendorPurchaseDoc, {}, {}, {}, Document<unknown, {}, VendorPurchaseDoc, {}> & VendorPurchaseDoc & Required<{
14
17
  _id: unknown;
@@ -4,16 +4,21 @@ exports.VendorPurchaseModel = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  const VendorPurchaseSchema = new mongoose_1.Schema({
6
6
  vendor_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Vendor', required: true },
7
- products: [
8
- {
9
- product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true },
10
- price: { type: Number, required: true },
11
- quantity: { type: Number, required: true },
12
- },
13
- ],
7
+ products: {
8
+ type: [{
9
+ product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true },
10
+ serials: { type: [String], required: false },
11
+ price: { type: Number, required: true },
12
+ quantity: { type: Number, required: true },
13
+ }],
14
+ required: true
15
+ },
14
16
  date: { type: Date, required: true },
15
17
  }, {
16
18
  collection: 'vendor_purchase',
17
19
  timestamps: true,
18
20
  });
21
+ VendorPurchaseSchema.statics.build = (attrs) => {
22
+ return new exports.VendorPurchaseModel(attrs);
23
+ };
19
24
  exports.VendorPurchaseModel = (0, mongoose_1.model)('VendorPurchase', VendorPurchaseSchema);
@@ -5,9 +5,10 @@ const mongoose_1 = require("mongoose");
5
5
  const address_schema_1 = require("./address.schema");
6
6
  const VendorSchema = new mongoose_1.Schema({
7
7
  name: { type: String, required: true },
8
- addresses: [
9
- { type: address_schema_1.AddressSchema, required: true }
10
- ]
8
+ addresses: {
9
+ type: [address_schema_1.AddressSchema],
10
+ required: true
11
+ }
11
12
  }, {
12
13
  timestamps: true,
13
14
  collection: "vendor"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tabletennisshop/common",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",