@tabletennisshop/common 1.0.63 → 1.0.67
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.
- package/build/events/CartEventInterface.d.ts +11 -1
- package/build/events/OrderEventInterface.d.ts +21 -2
- package/build/events/PublisherAbstract.js +1 -0
- package/build/index.d.ts +0 -12
- package/build/index.js +0 -12
- package/build/types/base.d.ts +1 -0
- package/package.json +1 -1
- package/build/events/RatingEventInterface.d.ts +0 -16
- package/build/events/RatingEventInterface.js +0 -2
- package/build/events/UserEventInterface.d.ts +0 -18
- package/build/events/UserEventInterface.js +0 -2
- package/build/models/cart.model.d.ts +0 -20
- package/build/models/cart.model.js +0 -21
- package/build/models/inventory.model.d.ts +0 -16
- package/build/models/inventory.model.js +0 -16
- package/build/models/order.model.d.ts +0 -30
- package/build/models/order.model.js +0 -28
- package/build/models/product.model.d.ts +0 -33
- package/build/models/product.model.js +0 -87
- package/build/models/racket.model.d.ts +0 -14
- package/build/models/racket.model.js +0 -13
- package/build/models/rating.model.d.ts +0 -16
- package/build/models/rating.model.js +0 -50
- package/build/models/shirt.model.d.ts +0 -14
- package/build/models/shirt.model.js +0 -11
- package/build/models/sponge.model.d.ts +0 -14
- package/build/models/sponge.model.js +0 -12
- package/build/models/status-timestamp.schema.d.ts +0 -19
- package/build/models/status-timestamp.schema.js +0 -13
- package/build/models/user.model.d.ts +0 -28
- package/build/models/user.model.js +0 -46
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { Types } from "mongoose";
|
|
1
2
|
import { SubjectsEnum } from "../enums/event-subject.enum";
|
|
2
|
-
|
|
3
|
+
interface ICartAttrs {
|
|
4
|
+
_id: Types.ObjectId;
|
|
5
|
+
user_id: Types.ObjectId;
|
|
6
|
+
products: {
|
|
7
|
+
product_id: Types.ObjectId;
|
|
8
|
+
quantity: number;
|
|
9
|
+
}[];
|
|
10
|
+
version: number;
|
|
11
|
+
}
|
|
3
12
|
export interface CartCreatedEventInterface {
|
|
4
13
|
subject: SubjectsEnum.CartCreated;
|
|
5
14
|
data: ICartAttrs;
|
|
@@ -14,3 +23,4 @@ export interface CartDeletedEventInterface {
|
|
|
14
23
|
id: string;
|
|
15
24
|
};
|
|
16
25
|
}
|
|
26
|
+
export {};
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
import { Types } from "mongoose";
|
|
1
2
|
import { SubjectsEnum } from "../enums/event-subject.enum";
|
|
2
|
-
import {
|
|
3
|
+
import { OrderStatusEnum } from "../enums/order-status.enum";
|
|
4
|
+
import { PaymentMethodEnum } from "../enums/payment-method.enum";
|
|
5
|
+
interface IOrderProduct {
|
|
6
|
+
product_id: Types.ObjectId;
|
|
7
|
+
price: number;
|
|
8
|
+
quantity: number;
|
|
9
|
+
}
|
|
10
|
+
interface OrderAttrs {
|
|
11
|
+
_id: Types.ObjectId;
|
|
12
|
+
user_id: Types.ObjectId;
|
|
13
|
+
products: IOrderProduct[];
|
|
14
|
+
status: OrderStatusEnum;
|
|
15
|
+
payment_method: PaymentMethodEnum;
|
|
16
|
+
version: number;
|
|
17
|
+
}
|
|
3
18
|
export interface OrderCreatedEventInterface {
|
|
4
19
|
subject: SubjectsEnum.OrderCreated;
|
|
5
20
|
data: OrderAttrs;
|
|
@@ -10,5 +25,9 @@ export interface OrderUpdatedEventInterface {
|
|
|
10
25
|
}
|
|
11
26
|
export interface OrderCancelledEventInterface {
|
|
12
27
|
subject: SubjectsEnum.OrderCancelled;
|
|
13
|
-
data:
|
|
28
|
+
data: {
|
|
29
|
+
id: Types.ObjectId;
|
|
30
|
+
version: number;
|
|
31
|
+
};
|
|
14
32
|
}
|
|
33
|
+
export {};
|
package/build/index.d.ts
CHANGED
|
@@ -6,16 +6,6 @@ export * from './middlewares/check-authorized-middleware';
|
|
|
6
6
|
export * from './middlewares/error-handler';
|
|
7
7
|
export * from './middlewares/validate-request-middleware';
|
|
8
8
|
export * from './middlewares/current-user-middleware';
|
|
9
|
-
export * from './models/user.model';
|
|
10
|
-
export * from './models/product.model';
|
|
11
|
-
export * from './models/racket.model';
|
|
12
|
-
export * from './models/rating.model';
|
|
13
|
-
export * from './models/shirt.model';
|
|
14
|
-
export * from './models/sponge.model';
|
|
15
|
-
export * from './models/order.model';
|
|
16
|
-
export * from './models/cart.model';
|
|
17
|
-
export * from './models/inventory.model';
|
|
18
|
-
export * from './models/status-timestamp.schema';
|
|
19
9
|
export * from './helper/password';
|
|
20
10
|
export * from './enums/product-type.enum';
|
|
21
11
|
export * from './enums/order-status.enum';
|
|
@@ -26,6 +16,4 @@ export * from './events/CartEventInterface';
|
|
|
26
16
|
export * from './events/ListenerAbstract';
|
|
27
17
|
export * from './events/OrderEventInterface';
|
|
28
18
|
export * from './events/PublisherAbstract';
|
|
29
|
-
export * from './events/RatingEventInterface';
|
|
30
|
-
export * from './events/UserEventInterface';
|
|
31
19
|
export * from './types/base';
|
package/build/index.js
CHANGED
|
@@ -22,16 +22,6 @@ __exportStar(require("./middlewares/check-authorized-middleware"), exports);
|
|
|
22
22
|
__exportStar(require("./middlewares/error-handler"), exports);
|
|
23
23
|
__exportStar(require("./middlewares/validate-request-middleware"), exports);
|
|
24
24
|
__exportStar(require("./middlewares/current-user-middleware"), exports);
|
|
25
|
-
__exportStar(require("./models/user.model"), exports);
|
|
26
|
-
__exportStar(require("./models/product.model"), exports);
|
|
27
|
-
__exportStar(require("./models/racket.model"), exports);
|
|
28
|
-
__exportStar(require("./models/rating.model"), exports);
|
|
29
|
-
__exportStar(require("./models/shirt.model"), exports);
|
|
30
|
-
__exportStar(require("./models/sponge.model"), exports);
|
|
31
|
-
__exportStar(require("./models/order.model"), exports);
|
|
32
|
-
__exportStar(require("./models/cart.model"), exports);
|
|
33
|
-
__exportStar(require("./models/inventory.model"), exports);
|
|
34
|
-
__exportStar(require("./models/status-timestamp.schema"), exports);
|
|
35
25
|
__exportStar(require("./helper/password"), exports);
|
|
36
26
|
__exportStar(require("./enums/product-type.enum"), exports);
|
|
37
27
|
__exportStar(require("./enums/order-status.enum"), exports);
|
|
@@ -42,6 +32,4 @@ __exportStar(require("./events/CartEventInterface"), exports);
|
|
|
42
32
|
__exportStar(require("./events/ListenerAbstract"), exports);
|
|
43
33
|
__exportStar(require("./events/OrderEventInterface"), exports);
|
|
44
34
|
__exportStar(require("./events/PublisherAbstract"), exports);
|
|
45
|
-
__exportStar(require("./events/RatingEventInterface"), exports);
|
|
46
|
-
__exportStar(require("./events/UserEventInterface"), exports);
|
|
47
35
|
__exportStar(require("./types/base"), exports);
|
package/build/types/base.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SubjectsEnum } from "../enums/event-subject.enum";
|
|
2
|
-
import { IRatingAttrs } from "../models/rating.model";
|
|
3
|
-
export interface RatingCreatedEventInterface {
|
|
4
|
-
subject: SubjectsEnum.RatingCreated;
|
|
5
|
-
data: IRatingAttrs;
|
|
6
|
-
}
|
|
7
|
-
export interface RatingUpdatedEventInterface {
|
|
8
|
-
subject: SubjectsEnum.RatingUpdated;
|
|
9
|
-
data: Partial<IRatingAttrs>;
|
|
10
|
-
}
|
|
11
|
-
export interface RatingDeletedEventInterface {
|
|
12
|
-
subject: SubjectsEnum.RatingDeleted;
|
|
13
|
-
data: {
|
|
14
|
-
id: string;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SubjectsEnum } from "../enums/event-subject.enum";
|
|
2
|
-
import { UserAttrs } from "../models/user.model";
|
|
3
|
-
type OptionalUser = Partial<UserAttrs>;
|
|
4
|
-
export interface UserUpdatedEventInterface {
|
|
5
|
-
subject: SubjectsEnum.UserUpdated;
|
|
6
|
-
data: OptionalUser;
|
|
7
|
-
}
|
|
8
|
-
export interface UserDeletedEventInterface {
|
|
9
|
-
subject: SubjectsEnum.UserDeleted;
|
|
10
|
-
data: {
|
|
11
|
-
id: string;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export interface UserCreatedEventInterface {
|
|
15
|
-
subject: SubjectsEnum.UserCreated;
|
|
16
|
-
data: UserAttrs;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Document, Model, Types } from "mongoose";
|
|
2
|
-
export interface ICartAttrs {
|
|
3
|
-
user_id: Types.ObjectId;
|
|
4
|
-
products: {
|
|
5
|
-
product_id: Types.ObjectId;
|
|
6
|
-
quantity: number;
|
|
7
|
-
}[];
|
|
8
|
-
}
|
|
9
|
-
export interface CartDoc extends Document {
|
|
10
|
-
user_id: Types.ObjectId;
|
|
11
|
-
products: {
|
|
12
|
-
product_id: Types.ObjectId;
|
|
13
|
-
quantity: number;
|
|
14
|
-
}[];
|
|
15
|
-
}
|
|
16
|
-
interface CartModel extends Model<CartDoc> {
|
|
17
|
-
build(attrs: ICartAttrs): CartDoc;
|
|
18
|
-
}
|
|
19
|
-
export declare const CartModel: CartModel;
|
|
20
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CartModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const CartSchema = new mongoose_1.Schema({
|
|
6
|
-
user_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', required: true },
|
|
7
|
-
products: {
|
|
8
|
-
type: [{
|
|
9
|
-
product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true },
|
|
10
|
-
quantity: { type: Number, required: true },
|
|
11
|
-
_id: false // Disable automatic _id generation for subdocuments
|
|
12
|
-
}],
|
|
13
|
-
required: true
|
|
14
|
-
}
|
|
15
|
-
}, {
|
|
16
|
-
collection: "cart"
|
|
17
|
-
});
|
|
18
|
-
CartSchema.statics.build = (attrs) => {
|
|
19
|
-
return new exports.CartModel(attrs);
|
|
20
|
-
};
|
|
21
|
-
exports.CartModel = (0, mongoose_1.model)('Cart', CartSchema);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Document, Model, Types } from "mongoose";
|
|
2
|
-
export interface IInventory {
|
|
3
|
-
product_id: Types.ObjectId;
|
|
4
|
-
total_quantity: number;
|
|
5
|
-
serials?: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface InventoryDoc extends IInventory, Document {
|
|
8
|
-
_id: Types.ObjectId;
|
|
9
|
-
createdAt: Date;
|
|
10
|
-
updatedAt: Date;
|
|
11
|
-
}
|
|
12
|
-
interface InventoryModelType extends Model<InventoryDoc> {
|
|
13
|
-
build(attrs: IInventory): InventoryDoc;
|
|
14
|
-
}
|
|
15
|
-
export declare const InventoryModel: InventoryModelType;
|
|
16
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InventoryModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const InventorySchema = new mongoose_1.Schema({
|
|
6
|
-
product_id: { type: mongoose_1.Schema.Types.ObjectId, required: true, ref: 'Product' },
|
|
7
|
-
total_quantity: { type: Number, required: true, default: 0 },
|
|
8
|
-
serials: { type: [String], required: false },
|
|
9
|
-
}, {
|
|
10
|
-
timestamps: true,
|
|
11
|
-
collection: 'inventory'
|
|
12
|
-
});
|
|
13
|
-
InventorySchema.statics.build = (attrs) => {
|
|
14
|
-
return new exports.InventoryModel(attrs);
|
|
15
|
-
};
|
|
16
|
-
exports.InventoryModel = (0, mongoose_1.model)('Inventory', InventorySchema);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Document, Model, Types } from 'mongoose';
|
|
2
|
-
import { OrderStatusEnum } from '../enums/order-status.enum';
|
|
3
|
-
import { IStatusTimestamps } from './status-timestamp.schema';
|
|
4
|
-
import { PaymentMethodEnum } from '../enums/payment-method.enum';
|
|
5
|
-
export interface IOrderProduct {
|
|
6
|
-
product_id: Types.ObjectId;
|
|
7
|
-
serial?: string;
|
|
8
|
-
price: number;
|
|
9
|
-
quantity: number;
|
|
10
|
-
}
|
|
11
|
-
export interface OrderAttrs {
|
|
12
|
-
user_id: Types.ObjectId;
|
|
13
|
-
products: IOrderProduct[];
|
|
14
|
-
status: OrderStatusEnum;
|
|
15
|
-
statusTimestamps: IStatusTimestamps;
|
|
16
|
-
payment_method: PaymentMethodEnum;
|
|
17
|
-
}
|
|
18
|
-
export interface OrderDoc extends Document {
|
|
19
|
-
_id: Types.ObjectId;
|
|
20
|
-
user_id: Types.ObjectId;
|
|
21
|
-
products: IOrderProduct[];
|
|
22
|
-
status: OrderStatusEnum;
|
|
23
|
-
statusTimestamps: IStatusTimestamps;
|
|
24
|
-
payment_method: PaymentMethodEnum;
|
|
25
|
-
}
|
|
26
|
-
interface OrderModel extends Model<OrderDoc> {
|
|
27
|
-
build(attrs: OrderAttrs): OrderDoc;
|
|
28
|
-
}
|
|
29
|
-
export declare const OrderModel: OrderModel;
|
|
30
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const order_status_enum_1 = require("../enums/order-status.enum");
|
|
6
|
-
const status_timestamp_schema_1 = require("./status-timestamp.schema");
|
|
7
|
-
const payment_method_enum_1 = require("../enums/payment-method.enum");
|
|
8
|
-
const OrderSchema = new mongoose_1.Schema({
|
|
9
|
-
user_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'User', required: true }, // FK to User
|
|
10
|
-
products: {
|
|
11
|
-
type: [
|
|
12
|
-
{
|
|
13
|
-
product_id: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Product', required: true }, // FK to Product
|
|
14
|
-
serial: { type: String, required: false }, // Optional serial number for the product
|
|
15
|
-
price: { type: Number, required: true }, // Price of the product at the time of order
|
|
16
|
-
quantity: { type: Number, required: true },
|
|
17
|
-
_id: false // Disable automatic creation of _id for subdocuments
|
|
18
|
-
},
|
|
19
|
-
]
|
|
20
|
-
},
|
|
21
|
-
status: { type: String, enum: order_status_enum_1.OrderStatusEnum, required: true },
|
|
22
|
-
statusTimestamps: { type: status_timestamp_schema_1.StatusTimestampsSchema, require: true },
|
|
23
|
-
payment_method: { type: String, enum: Object.values(payment_method_enum_1.PaymentMethodEnum), required: true }
|
|
24
|
-
}, { collection: 'order' });
|
|
25
|
-
OrderSchema.statics.build = (attrs) => {
|
|
26
|
-
return new exports.OrderModel(attrs);
|
|
27
|
-
};
|
|
28
|
-
exports.OrderModel = (0, mongoose_1.model)('Order', OrderSchema);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import mongoose, { Document, Types } from 'mongoose';
|
|
2
|
-
import { ProductTypeEnum } from '../enums/product-type.enum';
|
|
3
|
-
import { ProductStatusEnum } from '../enums/product-status.enum';
|
|
4
|
-
export interface ProductAttrsBase {
|
|
5
|
-
name: string;
|
|
6
|
-
slug: string;
|
|
7
|
-
brand: string;
|
|
8
|
-
description: string;
|
|
9
|
-
sport: string;
|
|
10
|
-
type: ProductTypeEnum;
|
|
11
|
-
attributes?: any;
|
|
12
|
-
price: number;
|
|
13
|
-
status: ProductStatusEnum;
|
|
14
|
-
}
|
|
15
|
-
export interface ProductDoc extends Document {
|
|
16
|
-
_id: Types.ObjectId;
|
|
17
|
-
name: string;
|
|
18
|
-
slug: string;
|
|
19
|
-
brand: string;
|
|
20
|
-
description: string;
|
|
21
|
-
type: ProductTypeEnum;
|
|
22
|
-
sport: string;
|
|
23
|
-
attributes?: any;
|
|
24
|
-
status: ProductStatusEnum;
|
|
25
|
-
price: number;
|
|
26
|
-
createdAt: Date;
|
|
27
|
-
updatedAt: Date;
|
|
28
|
-
}
|
|
29
|
-
export declare const ProductModel: mongoose.Model<ProductDoc, {}, {}, {}, mongoose.Document<unknown, {}, ProductDoc, {}> & ProductDoc & Required<{
|
|
30
|
-
_id: Types.ObjectId;
|
|
31
|
-
}> & {
|
|
32
|
-
__v: number;
|
|
33
|
-
}, any>;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.ProductModel = void 0;
|
|
46
|
-
// src/models/product.model.ts
|
|
47
|
-
const mongoose_1 = __importStar(require("mongoose"));
|
|
48
|
-
const product_type_enum_1 = require("../enums/product-type.enum");
|
|
49
|
-
const product_status_enum_1 = require("../enums/product-status.enum");
|
|
50
|
-
//We don't need "interface ProductModel extends Model<>" for this
|
|
51
|
-
// because we don't have any static methods or custom instance methods
|
|
52
|
-
// like "build" or "findById" in this model.
|
|
53
|
-
// Define the base options for the schema
|
|
54
|
-
const baseOptions = {
|
|
55
|
-
discriminatorKey: 'type', // This is used to differentiate between different types of products
|
|
56
|
-
collection: 'product', // The name of the collection in MongoDB
|
|
57
|
-
timestamps: true
|
|
58
|
-
};
|
|
59
|
-
const ProductSchema = new mongoose_1.Schema({
|
|
60
|
-
name: { type: String, required: true, unique: true },
|
|
61
|
-
slug: { type: String, required: true, unique: true },
|
|
62
|
-
brand: { type: String, required: true },
|
|
63
|
-
description: { type: String, required: false },
|
|
64
|
-
type: { type: String, enum: Object.values(product_type_enum_1.ProductTypeEnum), required: true }, // Discriminator key
|
|
65
|
-
sport: { type: String, required: true },
|
|
66
|
-
attributes: { type: [mongoose_1.Schema.Types.Mixed], required: false },
|
|
67
|
-
status: { type: String, enum: Object.values(product_status_enum_1.ProductStatusEnum), default: product_status_enum_1.ProductStatusEnum.ENABLE },
|
|
68
|
-
price: { type: Number, required: true },
|
|
69
|
-
}, baseOptions);
|
|
70
|
-
ProductSchema.pre("save", function (next) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
if (this.isModified('name') || !this.slug) {
|
|
73
|
-
this.slug = generateUniqueSlug(this.name);
|
|
74
|
-
}
|
|
75
|
-
next();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
exports.ProductModel = mongoose_1.default.model('Product', ProductSchema);
|
|
79
|
-
const generateUniqueSlug = (name, currentId) => {
|
|
80
|
-
const baseSlug = name
|
|
81
|
-
.toLowerCase()
|
|
82
|
-
.trim()
|
|
83
|
-
.replace(/[^\w\s-]/g, '') // remove non-word characters
|
|
84
|
-
.replace(/\s+/g, '-') // replace spaces with hyphens
|
|
85
|
-
.replace(/-+/g, '-'); // collapse multiple hyphens
|
|
86
|
-
return baseSlug;
|
|
87
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Model } from "mongoose";
|
|
2
|
-
import { ProductTypeEnum } from "../enums/product-type.enum";
|
|
3
|
-
import { ProductAttrsBase, ProductDoc } from "./product.model";
|
|
4
|
-
export interface RacketAttrs extends ProductAttrsBase {
|
|
5
|
-
type: ProductTypeEnum.RACKET;
|
|
6
|
-
}
|
|
7
|
-
export interface RacketDoc extends ProductDoc {
|
|
8
|
-
type: ProductTypeEnum.RACKET;
|
|
9
|
-
}
|
|
10
|
-
interface RacketModel extends Model<RacketDoc> {
|
|
11
|
-
build(attrs: RacketAttrs): RacketDoc;
|
|
12
|
-
}
|
|
13
|
-
export declare const RacketModel: RacketModel;
|
|
14
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RacketModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const product_type_enum_1 = require("../enums/product-type.enum");
|
|
6
|
-
const product_model_1 = require("./product.model");
|
|
7
|
-
;
|
|
8
|
-
;
|
|
9
|
-
const racketSchema = new mongoose_1.Schema({});
|
|
10
|
-
racketSchema.statics.build = (attrs) => {
|
|
11
|
-
return new exports.RacketModel(attrs);
|
|
12
|
-
};
|
|
13
|
-
exports.RacketModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.RACKET, racketSchema);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Document, Model, Types } from "mongoose";
|
|
2
|
-
export interface IRatingAttrs {
|
|
3
|
-
user_id: Types.ObjectId;
|
|
4
|
-
product_id: Types.ObjectId;
|
|
5
|
-
comment?: string;
|
|
6
|
-
rate_score: number;
|
|
7
|
-
}
|
|
8
|
-
export interface RatingDoc extends IRatingAttrs, Document {
|
|
9
|
-
_id: Types.ObjectId;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
updatedAt: Date;
|
|
12
|
-
}
|
|
13
|
-
export interface RatingModel extends Model<RatingDoc> {
|
|
14
|
-
build(attrs: IRatingAttrs): RatingDoc;
|
|
15
|
-
}
|
|
16
|
-
export declare const RatingModel: RatingModel;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.RatingModel = void 0;
|
|
37
|
-
const mongoose_1 = __importStar(require("mongoose"));
|
|
38
|
-
const RatingSchema = new mongoose_1.Schema({
|
|
39
|
-
user_id: { type: mongoose_1.Schema.Types.ObjectId, required: true, ref: 'User' },
|
|
40
|
-
product_id: { type: mongoose_1.Schema.Types.ObjectId, required: true, ref: 'Product' },
|
|
41
|
-
comment: { type: String, required: false },
|
|
42
|
-
rate_score: { type: Number, required: true, min: 1, max: 5 } // Assuming rate_score is between 1 and 5
|
|
43
|
-
}, {
|
|
44
|
-
timestamps: true,
|
|
45
|
-
collection: 'rating'
|
|
46
|
-
});
|
|
47
|
-
RatingSchema.statics.build = (attrs) => {
|
|
48
|
-
return new exports.RatingModel(attrs);
|
|
49
|
-
};
|
|
50
|
-
exports.RatingModel = mongoose_1.default.model('Rating', RatingSchema);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Model } from "mongoose";
|
|
2
|
-
import { ProductTypeEnum } from "../enums/product-type.enum";
|
|
3
|
-
import { ProductAttrsBase, ProductDoc } from "./product.model";
|
|
4
|
-
export interface ShirtAttrs extends ProductAttrsBase {
|
|
5
|
-
type: ProductTypeEnum.SHIRT;
|
|
6
|
-
}
|
|
7
|
-
export interface ShirtDoc extends ProductDoc {
|
|
8
|
-
type: ProductTypeEnum.SHIRT;
|
|
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,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShirtModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const product_type_enum_1 = require("../enums/product-type.enum");
|
|
6
|
-
const product_model_1 = require("./product.model");
|
|
7
|
-
const shirtSchema = new mongoose_1.Schema({});
|
|
8
|
-
shirtSchema.statics.build = (attrs) => {
|
|
9
|
-
return new exports.ShirtModel(attrs);
|
|
10
|
-
};
|
|
11
|
-
exports.ShirtModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SHIRT, new mongoose_1.Schema({}));
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Model } from "mongoose";
|
|
2
|
-
import { ProductTypeEnum } from "../enums/product-type.enum";
|
|
3
|
-
import { ProductAttrsBase, ProductDoc } from "./product.model";
|
|
4
|
-
export interface SpongeAttrs extends ProductAttrsBase {
|
|
5
|
-
type: ProductTypeEnum.SPONGE;
|
|
6
|
-
}
|
|
7
|
-
export interface SpongeDoc extends ProductDoc {
|
|
8
|
-
type: ProductTypeEnum.SPONGE;
|
|
9
|
-
}
|
|
10
|
-
interface SpongeModel extends Model<SpongeDoc> {
|
|
11
|
-
build(attrs: SpongeAttrs): SpongeDoc;
|
|
12
|
-
}
|
|
13
|
-
export declare const SpongeModel: SpongeModel;
|
|
14
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SpongeModel = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const product_type_enum_1 = require("../enums/product-type.enum");
|
|
6
|
-
const product_model_1 = require("./product.model");
|
|
7
|
-
const spongeSchema = new mongoose_1.Schema({});
|
|
8
|
-
spongeSchema.statics.build = (attrs) => {
|
|
9
|
-
return new exports.SpongeModel(attrs);
|
|
10
|
-
};
|
|
11
|
-
// ─────────── Sponge ───────────
|
|
12
|
-
exports.SpongeModel = product_model_1.ProductModel.discriminator(product_type_enum_1.ProductTypeEnum.SPONGE, new mongoose_1.Schema({}));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
2
|
-
export interface IStatusTimestamps {
|
|
3
|
-
pending_at?: Date;
|
|
4
|
-
confirmed_at?: Date;
|
|
5
|
-
delivering_at?: Date;
|
|
6
|
-
finished_at?: Date;
|
|
7
|
-
cancelled_at?: Date;
|
|
8
|
-
returned_at?: Date;
|
|
9
|
-
failed_at?: Date;
|
|
10
|
-
}
|
|
11
|
-
export declare const StatusTimestampsSchema: Schema<IStatusTimestamps, import("mongoose").Model<IStatusTimestamps, any, any, any, import("mongoose").Document<unknown, any, IStatusTimestamps, any> & IStatusTimestamps & {
|
|
12
|
-
_id: import("mongoose").Types.ObjectId;
|
|
13
|
-
} & {
|
|
14
|
-
__v: number;
|
|
15
|
-
}, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, IStatusTimestamps, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<IStatusTimestamps>, {}> & import("mongoose").FlatRecord<IStatusTimestamps> & {
|
|
16
|
-
_id: import("mongoose").Types.ObjectId;
|
|
17
|
-
} & {
|
|
18
|
-
__v: number;
|
|
19
|
-
}>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatusTimestampsSchema = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
exports.StatusTimestampsSchema = new mongoose_1.Schema({
|
|
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
|
-
}, { _id: false });
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Model, Document, Types } from 'mongoose';
|
|
2
|
-
import { UserStatusEnum } from '../enums/user-status.enum';
|
|
3
|
-
export interface UserAttrs {
|
|
4
|
-
username: string;
|
|
5
|
-
email: string;
|
|
6
|
-
password: string;
|
|
7
|
-
full_name: string;
|
|
8
|
-
address: string;
|
|
9
|
-
type: string;
|
|
10
|
-
status: UserStatusEnum;
|
|
11
|
-
}
|
|
12
|
-
export interface UserDoc extends Document {
|
|
13
|
-
_id: Types.ObjectId;
|
|
14
|
-
username: string;
|
|
15
|
-
email: string;
|
|
16
|
-
password: string;
|
|
17
|
-
full_name: string;
|
|
18
|
-
address: string;
|
|
19
|
-
type: string;
|
|
20
|
-
status: UserStatusEnum;
|
|
21
|
-
createdAt: Date;
|
|
22
|
-
updatedAt: Date;
|
|
23
|
-
}
|
|
24
|
-
interface UserModel extends Model<UserDoc> {
|
|
25
|
-
build(attrs: UserAttrs): UserDoc;
|
|
26
|
-
}
|
|
27
|
-
export declare const UserModel: UserModel;
|
|
28
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.UserModel = void 0;
|
|
13
|
-
const mongoose_1 = require("mongoose");
|
|
14
|
-
const password_1 = require("../helper/password");
|
|
15
|
-
const user_enum_1 = require("../enums/user.enum");
|
|
16
|
-
const user_status_enum_1 = require("../enums/user-status.enum");
|
|
17
|
-
const UserSchema = new mongoose_1.Schema({
|
|
18
|
-
username: { type: String, required: true, unique: true, minlength: 5 },
|
|
19
|
-
email: { type: String, required: true, unique: true },
|
|
20
|
-
password: { type: String, required: true, minlength: 4 },
|
|
21
|
-
full_name: { type: String, required: true },
|
|
22
|
-
address: { type: String, required: true },
|
|
23
|
-
type: { type: String, enum: Object.values(user_enum_1.UserEnum), required: true },
|
|
24
|
-
status: { type: String, enum: Object.values(user_status_enum_1.UserStatusEnum), required: true }
|
|
25
|
-
}, {
|
|
26
|
-
timestamps: true, // Adds createdAt and updatedAt fields automatically
|
|
27
|
-
collection: "user"
|
|
28
|
-
});
|
|
29
|
-
UserSchema.statics.build = (attrs) => {
|
|
30
|
-
return new exports.UserModel(attrs);
|
|
31
|
-
};
|
|
32
|
-
UserSchema.pre('save', function (next) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
if (this.isModified('email')) {
|
|
35
|
-
const existingUser = yield exports.UserModel.findOne({ email: this.email });
|
|
36
|
-
if (existingUser) {
|
|
37
|
-
throw new Error("Email already exists!");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (this.isModified('password')) {
|
|
41
|
-
this.password = yield password_1.Password.toHash(this.password);
|
|
42
|
-
}
|
|
43
|
-
next();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
exports.UserModel = (0, mongoose_1.model)('User', UserSchema);
|