tt-entities 0.0.30 → 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.
@@ -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
+ }
@@ -53,6 +53,11 @@ import { PaymentMethod } from './entities/payment-method.entity';
53
53
  import { PaymentMethodCountry } from './entities/payment-method-country.entity';
54
54
  import { StorePaymentMethod } from './entities/store-payment-method.entity';
55
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
+
56
61
  // =============================================================================
57
62
  // EXPORTS
58
63
  // =============================================================================
@@ -120,6 +125,11 @@ export {
120
125
  export { PaymentMethodCountry } from './entities/payment-method-country.entity';
121
126
  export { StorePaymentMethod } from './entities/store-payment-method.entity';
122
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
+
123
133
  // ─── Enums ────────────────────────────────────────────────────────────────────
124
134
  export { OsName } from './utils/enums/osName';
125
135
  export { ProductApp } from './utils/enums/productApp';
@@ -188,5 +198,10 @@ export function getDbModels(): ModelCtor[] {
188
198
  PaymentMethod,
189
199
  PaymentMethodCountry,
190
200
  StorePaymentMethod,
201
+
202
+ // Cart
203
+ Cart,
204
+ CartItem,
205
+ CartItemBundleSelection,
191
206
  ];
192
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-entities",
3
- "version": "0.0.30",
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",