tt-entities 0.0.29 → 0.0.31

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.
Files changed (30) hide show
  1. package/dist/libs/tatayab-entities-library/entities/bundle-product.entity.d.ts +13 -0
  2. package/dist/libs/tatayab-entities-library/entities/bundle-product.entity.js +54 -0
  3. package/dist/libs/tatayab-entities-library/entities/bundle-product.entity.js.map +1 -0
  4. package/dist/libs/tatayab-entities-library/entities/bundle-store.entity.d.ts +11 -0
  5. package/dist/libs/tatayab-entities-library/entities/bundle-store.entity.js +56 -0
  6. package/dist/libs/tatayab-entities-library/entities/bundle-store.entity.js.map +1 -0
  7. package/dist/libs/tatayab-entities-library/entities/bundle.entity.d.ts +27 -0
  8. package/dist/libs/tatayab-entities-library/entities/bundle.entity.js +102 -0
  9. package/dist/libs/tatayab-entities-library/entities/bundle.entity.js.map +1 -0
  10. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.d.ts +13 -0
  11. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.js +54 -0
  12. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.js.map +1 -0
  13. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.d.ts +26 -0
  14. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.js +93 -0
  15. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.js.map +1 -0
  16. package/dist/libs/tatayab-entities-library/entities/cart.entity.d.ts +20 -0
  17. package/dist/libs/tatayab-entities-library/entities/cart.entity.js +68 -0
  18. package/dist/libs/tatayab-entities-library/entities/cart.entity.js.map +1 -0
  19. package/dist/libs/tatayab-entities-library/index.d.ts +6 -0
  20. package/dist/libs/tatayab-entities-library/index.js +28 -1
  21. package/dist/libs/tatayab-entities-library/index.js.map +1 -1
  22. package/dist/src/main.js +520 -6
  23. package/libs/tatayab-entities-library/src/entities/bundle-product.entity.ts +38 -0
  24. package/libs/tatayab-entities-library/src/entities/bundle-store.entity.ts +37 -0
  25. package/libs/tatayab-entities-library/src/entities/bundle.entity.ts +77 -0
  26. package/libs/tatayab-entities-library/src/entities/cart-item-bundle-selection.entity.ts +36 -0
  27. package/libs/tatayab-entities-library/src/entities/cart-item.entity.ts +75 -0
  28. package/libs/tatayab-entities-library/src/entities/cart.entity.ts +58 -0
  29. package/libs/tatayab-entities-library/src/index.ts +24 -0
  30. package/package.json +1 -1
@@ -0,0 +1,38 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, BelongsTo, DataType,
3
+ } from 'sequelize-typescript';
4
+ import { Bundle } from './bundle.entity';
5
+ import { Product } from './product.entity';
6
+ import { ProductVariant } from './product-variant.entity';
7
+
8
+ @Table
9
+ export class BundleProduct extends Model {
10
+ @ForeignKey(() => Bundle)
11
+ @Column({ allowNull: false })
12
+ declare bundleId: number;
13
+
14
+ @ForeignKey(() => Product)
15
+ @Column({ allowNull: false })
16
+ declare productId: number;
17
+
18
+ // Optional — if set, only this specific variant is part of the bundle
19
+ // null = customer can pick any variant of this product
20
+ @ForeignKey(() => ProductVariant)
21
+ @Column({ allowNull: true })
22
+ declare productVariantId?: number;
23
+
24
+ // Display order inside the bundle picker UI
25
+ @Column({ defaultValue: 0 })
26
+ declare sortOrder: number;
27
+
28
+ // ─── Associations ─────────────────────────────────────────────────────────────
29
+
30
+ @BelongsTo(() => Bundle)
31
+ declare bundle: Bundle;
32
+
33
+ @BelongsTo(() => Product)
34
+ declare product: Product;
35
+
36
+ @BelongsTo(() => ProductVariant)
37
+ declare variant?: ProductVariant;
38
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, DataType,
3
+ } from 'sequelize-typescript';
4
+ import { Bundle } from './bundle.entity';
5
+ import { Store } from './store.entity';
6
+ import { Status } from '../utils/enums/status';
7
+
8
+ @Table
9
+ export class BundleStore extends Model {
10
+ @ForeignKey(() => Bundle)
11
+ @Column({ allowNull: false })
12
+ declare bundleId: number;
13
+
14
+ @ForeignKey(() => Store)
15
+ @Column({ allowNull: false })
16
+ declare storeId: number;
17
+
18
+ // Store-specific regular price — null = use bundle.defaultPrice
19
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: true })
20
+ declare price?: number;
21
+
22
+ // Sale price — active only within saleStartDate → saleEndDate
23
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: true })
24
+ declare salePrice?: number;
25
+
26
+ @Column({ type: DataType.DATE, allowNull: true })
27
+ declare saleStartDate?: Date;
28
+
29
+ @Column({ type: DataType.DATE, allowNull: true })
30
+ declare saleEndDate?: Date;
31
+
32
+ @Column({
33
+ type: DataType.ENUM(...Object.values(Status)),
34
+ defaultValue: Status.ACTIVE,
35
+ })
36
+ declare status: Status;
37
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, BelongsTo,
3
+ HasMany, BelongsToMany, DataType,
4
+ } from 'sequelize-typescript';
5
+ import { Category } from './category.entity';
6
+ import { Store } from './store.entity';
7
+ import { BundleProduct } from './bundle-product.entity';
8
+ import { BundleStore } from './bundle-store.entity';
9
+ import { Product } from './product.entity';
10
+ import { Status } from '../utils/enums/status';
11
+
12
+ @Table
13
+ export class Bundle extends Model {
14
+ @Column({ allowNull: false, unique: true })
15
+ declare sku: string; // Bundle SKU e.g. BNDL-001
16
+
17
+ @Column({ allowNull: false })
18
+ declare nameEn: string;
19
+
20
+ @Column({ allowNull: false })
21
+ declare nameAr: string;
22
+
23
+ @Column({ type: DataType.TEXT, allowNull: true })
24
+ declare descriptionEn?: string;
25
+
26
+ @Column({ type: DataType.TEXT, allowNull: true })
27
+ declare descriptionAr?: string;
28
+
29
+ @Column({ allowNull: true })
30
+ declare image?: string;
31
+
32
+ // Total products available to choose from in this bundle
33
+ @Column({ allowNull: false, defaultValue: 0 })
34
+ declare totalProducts: number;
35
+
36
+ // How many the customer must choose
37
+ // e.g. totalProducts=10, choiceCount=3 → pick any 3 from 10
38
+ @Column({ allowNull: false, defaultValue: 1 })
39
+ declare choiceCount: number;
40
+
41
+ // Default price (fallback if no store-specific price)
42
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: false, defaultValue: 0 })
43
+ declare defaultPrice: number;
44
+
45
+ @ForeignKey(() => Category)
46
+ @Column({ allowNull: true })
47
+ declare categoryId?: number;
48
+
49
+ @Column({ defaultValue: 0 })
50
+ declare sortOrder: number;
51
+
52
+ @Column({ defaultValue: false })
53
+ declare isFeatured: boolean;
54
+
55
+ @Column({
56
+ type: DataType.ENUM(...Object.values(Status)),
57
+ defaultValue: Status.ACTIVE,
58
+ })
59
+ declare status: Status;
60
+
61
+ // ─── Associations ─────────────────────────────────────────────────────────────
62
+
63
+ @BelongsTo(() => Category)
64
+ declare category?: Category;
65
+
66
+ @HasMany(() => BundleProduct)
67
+ declare bundleProducts: BundleProduct[];
68
+
69
+ @BelongsToMany(() => Product, () => BundleProduct)
70
+ declare products: Product[];
71
+
72
+ @HasMany(() => BundleStore)
73
+ declare bundleStores: BundleStore[];
74
+
75
+ @BelongsToMany(() => Store, () => BundleStore)
76
+ declare stores: Store[];
77
+ }
@@ -0,0 +1,36 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, BelongsTo,
3
+ } from 'sequelize-typescript';
4
+ import { CartItem } from './cart-item.entity';
5
+ import { Product } from './product.entity';
6
+ import { ProductVariant } from './product-variant.entity';
7
+
8
+ @Table
9
+ export class CartItemBundleSelection extends Model {
10
+ @ForeignKey(() => CartItem)
11
+ @Column({ allowNull: false })
12
+ declare cartItemId: number;
13
+
14
+ @ForeignKey(() => Product)
15
+ @Column({ allowNull: false })
16
+ declare productId: number;
17
+
18
+ @ForeignKey(() => ProductVariant)
19
+ @Column({ allowNull: true })
20
+ declare productVariantId?: number;
21
+
22
+ // Display order within the bundle selection
23
+ @Column({ allowNull: false, defaultValue: 0 })
24
+ declare sortOrder: number;
25
+
26
+ // ── Associations ──────────────────────────────────────────────────────────────
27
+
28
+ @BelongsTo(() => CartItem)
29
+ declare cartItem: CartItem;
30
+
31
+ @BelongsTo(() => Product)
32
+ declare product: Product;
33
+
34
+ @BelongsTo(() => ProductVariant)
35
+ declare variant?: ProductVariant;
36
+ }
@@ -0,0 +1,75 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, BelongsTo,
3
+ HasMany, DataType,
4
+ } from 'sequelize-typescript';
5
+ import { Cart } from './cart.entity';
6
+ import { Product } from './product.entity';
7
+ import { ProductVariant } from './product-variant.entity';
8
+ import { Bundle } from './bundle.entity';
9
+ import { CartItemBundleSelection } from './cart-item-bundle-selection.entity';
10
+
11
+ export enum CartItemType {
12
+ PRODUCT = 'product',
13
+ BUNDLE = 'bundle',
14
+ }
15
+
16
+ @Table
17
+ export class CartItem extends Model {
18
+ @ForeignKey(() => Cart)
19
+ @Column({ allowNull: false })
20
+ declare cartId: number;
21
+
22
+ @Column({
23
+ type: DataType.ENUM(...Object.values(CartItemType)),
24
+ allowNull: false,
25
+ })
26
+ declare itemType: CartItemType;
27
+
28
+ // ── Product fields (null when itemType = bundle) ───────────────────────────
29
+ @ForeignKey(() => Product)
30
+ @Column({ allowNull: true })
31
+ declare productId?: number;
32
+
33
+ @ForeignKey(() => ProductVariant)
34
+ @Column({ allowNull: true })
35
+ declare productVariantId?: number;
36
+
37
+ // ── Bundle fields (null when itemType = product) ───────────────────────────
38
+ @ForeignKey(() => Bundle)
39
+ @Column({ allowNull: true })
40
+ declare bundleId?: number;
41
+
42
+ // Composed SKU built at selection time e.g. BNDL-001+PERF-M-001-V3+PERF-W-002
43
+ @Column({ allowNull: true })
44
+ declare composedSku?: string;
45
+
46
+ // ── Shared ────────────────────────────────────────────────────────────────────
47
+ @Column({ allowNull: false, defaultValue: 1 })
48
+ declare quantity: number;
49
+
50
+ // Price captured at time of adding — so price changes don't silently update cart
51
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: false })
52
+ declare unitPrice: number;
53
+
54
+ // ── Stock flag — set true by the stock-check endpoint ─────────────────────────
55
+ // Cleared when user updates qty or item is re-validated
56
+ @Column({ allowNull: false, defaultValue: false })
57
+ declare isOutOfStock: boolean;
58
+
59
+ // ── Associations ──────────────────────────────────────────────────────────────
60
+
61
+ @BelongsTo(() => Cart)
62
+ declare cart: Cart;
63
+
64
+ @BelongsTo(() => Product)
65
+ declare product?: Product;
66
+
67
+ @BelongsTo(() => ProductVariant)
68
+ declare variant?: ProductVariant;
69
+
70
+ @BelongsTo(() => Bundle)
71
+ declare bundle?: Bundle;
72
+
73
+ @HasMany(() => CartItemBundleSelection)
74
+ declare bundleSelections: CartItemBundleSelection[];
75
+ }
@@ -0,0 +1,58 @@
1
+ import {
2
+ Table, Column, Model, ForeignKey, BelongsTo,
3
+ HasMany, DataType,
4
+ } from 'sequelize-typescript';
5
+ import { User } from './user.entity';
6
+ import { Store } from './store.entity';
7
+ import { CartItem } from './cart-item.entity';
8
+
9
+ export enum CartStatus {
10
+ ACTIVE = 'active', // In use
11
+ MERGED = 'merged', // Guest cart merged into user cart
12
+ CONVERTED = 'converted', // Converted to an order
13
+ ABANDONED = 'abandoned', // Expired / not used
14
+ }
15
+
16
+ @Table
17
+ export class Cart extends Model {
18
+ // ── Identity — one of these two will always be set, never both null ──────────
19
+
20
+ // Logged-in user — null for guests
21
+ @ForeignKey(() => User)
22
+ @Column({ allowNull: true })
23
+ declare userId?: number;
24
+
25
+ // Guest identifier — UUID generated on first cart creation, stored on device
26
+ // null once cart is merged/claimed by a logged-in user
27
+ @Column({ allowNull: true })
28
+ declare guestToken?: string;
29
+
30
+ // ── Store scope ───────────────────────────────────────────────────────────────
31
+ @ForeignKey(() => Store)
32
+ @Column({ allowNull: false })
33
+ declare storeId: number;
34
+
35
+ // ── State ─────────────────────────────────────────────────────────────────────
36
+ @Column({
37
+ type: DataType.ENUM(...Object.values(CartStatus)),
38
+ allowNull: false,
39
+ defaultValue: CartStatus.ACTIVE,
40
+ })
41
+ declare status: CartStatus;
42
+
43
+ // Guest carts expire after 30 days of inactivity
44
+ // User carts expire after 90 days
45
+ @Column({ type: DataType.DATE, allowNull: true })
46
+ declare expiresAt?: Date;
47
+
48
+ // ── Associations ──────────────────────────────────────────────────────────────
49
+
50
+ @BelongsTo(() => User)
51
+ declare user?: User;
52
+
53
+ @BelongsTo(() => Store)
54
+ declare store: Store;
55
+
56
+ @HasMany(() => CartItem)
57
+ declare items: CartItem[];
58
+ }
@@ -22,6 +22,9 @@ import { ProductVariant } from './entities/product-variant.entity';
22
22
  import { ProductVariantOption } from './entities/product-variant-option.entity';
23
23
  import { Tag } from './entities/tag.entity';
24
24
  import { ProductTag } from './entities/product-tag.entity';
25
+ import { Bundle } from './entities/bundle.entity';
26
+ import { BundleProduct } from './entities/bundle-product.entity';
27
+ import { BundleStore } from './entities/bundle-store.entity';
25
28
 
26
29
  // ─── Stores ───────────────────────────────────────────────────────────────────
27
30
  import { Store } from './entities/store.entity';
@@ -50,6 +53,11 @@ import { PaymentMethod } from './entities/payment-method.entity';
50
53
  import { PaymentMethodCountry } from './entities/payment-method-country.entity';
51
54
  import { StorePaymentMethod } from './entities/store-payment-method.entity';
52
55
 
56
+ // ─── Carts ────────────────────────────────────────────────────────────────────
57
+ import { Cart } from './entities/cart.entity';
58
+ import { CartItem } from './entities/cart-item.entity';
59
+ import { CartItemBundleSelection } from './entities/cart-item-bundle-selection.entity';
60
+
53
61
  // =============================================================================
54
62
  // EXPORTS
55
63
  // =============================================================================
@@ -76,6 +84,9 @@ export { ProductVariant } from './entities/product-variant.entity';
76
84
  export { ProductVariantOption } from './entities/product-variant-option.entity';
77
85
  export { Tag } from './entities/tag.entity';
78
86
  export { ProductTag } from './entities/product-tag.entity';
87
+ export { Bundle } from './entities/bundle.entity';
88
+ export { BundleProduct } from './entities/bundle-product.entity';
89
+ export { BundleStore } from './entities/bundle-store.entity';
79
90
 
80
91
  // ─── Stores ───────────────────────────────────────────────────────────────────
81
92
  export { Store } from './entities/store.entity';
@@ -114,6 +125,11 @@ export {
114
125
  export { PaymentMethodCountry } from './entities/payment-method-country.entity';
115
126
  export { StorePaymentMethod } from './entities/store-payment-method.entity';
116
127
 
128
+ // ─── Carts ────────────────────────────────────────────────────────────────────
129
+ export { Cart, CartStatus } from './entities/cart.entity';
130
+ export { CartItem, CartItemType } from './entities/cart-item.entity';
131
+ export { CartItemBundleSelection } from './entities/cart-item-bundle-selection.entity';
132
+
117
133
  // ─── Enums ────────────────────────────────────────────────────────────────────
118
134
  export { OsName } from './utils/enums/osName';
119
135
  export { ProductApp } from './utils/enums/productApp';
@@ -152,6 +168,9 @@ export function getDbModels(): ModelCtor[] {
152
168
  ProductVariantOption,
153
169
  Tag,
154
170
  ProductTag,
171
+ Bundle,
172
+ BundleProduct,
173
+ BundleStore,
155
174
 
156
175
  // Stores
157
176
  Store,
@@ -179,5 +198,10 @@ export function getDbModels(): ModelCtor[] {
179
198
  PaymentMethod,
180
199
  PaymentMethodCountry,
181
200
  StorePaymentMethod,
201
+
202
+ // Cart
203
+ Cart,
204
+ CartItem,
205
+ CartItemBundleSelection,
182
206
  ];
183
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-entities",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "Tatayab entities library",
5
5
  "main": "dist/libs/tatayab-entities-library/index.js",
6
6
  "types": "dist/libs/tatayab-entities-library/index.d.ts",