tt-entities 0.0.30 → 0.0.32

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 (34) hide show
  1. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.d.ts +13 -0
  2. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.js +54 -0
  3. package/dist/libs/tatayab-entities-library/entities/cart-item-bundle-selection.entity.js.map +1 -0
  4. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.d.ts +26 -0
  5. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.js +93 -0
  6. package/dist/libs/tatayab-entities-library/entities/cart-item.entity.js.map +1 -0
  7. package/dist/libs/tatayab-entities-library/entities/cart.entity.d.ts +20 -0
  8. package/dist/libs/tatayab-entities-library/entities/cart.entity.js +68 -0
  9. package/dist/libs/tatayab-entities-library/entities/cart.entity.js.map +1 -0
  10. package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.d.ts +12 -0
  11. package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.js +50 -0
  12. package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.js.map +1 -0
  13. package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.d.ts +9 -0
  14. package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.js +40 -0
  15. package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.js.map +1 -0
  16. package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.d.ts +11 -0
  17. package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.js +48 -0
  18. package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.js.map +1 -0
  19. package/dist/libs/tatayab-entities-library/entities/coupon.entity.d.ts +44 -0
  20. package/dist/libs/tatayab-entities-library/entities/coupon.entity.js +145 -0
  21. package/dist/libs/tatayab-entities-library/entities/coupon.entity.js.map +1 -0
  22. package/dist/libs/tatayab-entities-library/index.d.ts +7 -0
  23. package/dist/libs/tatayab-entities-library/index.js +35 -2
  24. package/dist/libs/tatayab-entities-library/index.js.map +1 -1
  25. package/dist/src/main.js +604 -3
  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/entities/coupon-product.entity.ts +25 -0
  30. package/libs/tatayab-entities-library/src/entities/coupon-store.entity.ts +17 -0
  31. package/libs/tatayab-entities-library/src/entities/coupon-user.entity.ts +27 -0
  32. package/libs/tatayab-entities-library/src/entities/coupon.entity.ts +126 -0
  33. package/libs/tatayab-entities-library/src/index.ts +38 -0
  34. package/package.json +1 -1
@@ -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
+ }
@@ -0,0 +1,25 @@
1
+ import { Table, Column, Model, ForeignKey, BelongsTo } from 'sequelize-typescript';
2
+ import { Coupon } from './coupon.entity';
3
+ import { Product } from './product.entity';
4
+ import { ProductVariant } from './product-variant.entity';
5
+
6
+ @Table
7
+ export class CouponProduct extends Model {
8
+ @ForeignKey(() => Coupon)
9
+ @Column({ allowNull: false })
10
+ declare couponId: number;
11
+
12
+ @ForeignKey(() => Product)
13
+ @Column({ allowNull: false })
14
+ declare productId: number;
15
+
16
+ // null = applies to all variants of this product
17
+ // set = applies only to this specific variant
18
+ @ForeignKey(() => ProductVariant)
19
+ @Column({ allowNull: true })
20
+ declare productVariantId?: number;
21
+
22
+ @BelongsTo(() => Coupon) declare coupon: Coupon;
23
+ @BelongsTo(() => Product) declare product: Product;
24
+ @BelongsTo(() => ProductVariant) declare variant?: ProductVariant;
25
+ }
@@ -0,0 +1,17 @@
1
+ import { Table, Column, Model, ForeignKey, BelongsTo } from 'sequelize-typescript';
2
+ import { Coupon } from './coupon.entity';
3
+ import { Store } from './store.entity';
4
+
5
+ @Table
6
+ export class CouponStore extends Model {
7
+ @ForeignKey(() => Coupon)
8
+ @Column({ allowNull: false })
9
+ declare couponId: number;
10
+
11
+ @ForeignKey(() => Store)
12
+ @Column({ allowNull: false })
13
+ declare storeId: number;
14
+
15
+ @BelongsTo(() => Coupon) declare coupon: Coupon;
16
+ @BelongsTo(() => Store) declare store: Store;
17
+ }
@@ -0,0 +1,27 @@
1
+ import { Table, Column, Model, ForeignKey, BelongsTo } from 'sequelize-typescript';
2
+ import { Coupon } from './coupon.entity';
3
+ import { User } from './user.entity';
4
+
5
+ @Table
6
+ export class CouponUser extends Model {
7
+ @ForeignKey(() => Coupon)
8
+ @Column({ allowNull: false })
9
+ declare couponId: number;
10
+
11
+ @ForeignKey(() => User)
12
+ @Column({ allowNull: false })
13
+ declare userId: number;
14
+
15
+ // How many times this specific user has used this coupon
16
+ @Column({ allowNull: false, defaultValue: 0 })
17
+ declare usedCount: number;
18
+
19
+ // Whether this coupon was pre-assigned to this user
20
+ // true = user-specific coupon (isUserSpecific=true on coupon)
21
+ // false = just tracking usage of a public coupon
22
+ @Column({ allowNull: false, defaultValue: false })
23
+ declare isPreAssigned: boolean;
24
+
25
+ @BelongsTo(() => Coupon) declare coupon: Coupon;
26
+ @BelongsTo(() => User) declare user: User;
27
+ }
@@ -0,0 +1,126 @@
1
+ import {
2
+ Table, Column, Model, HasMany, DataType,
3
+ } from 'sequelize-typescript';
4
+ import { CouponStore } from './coupon-store.entity';
5
+ import { CouponProduct } from './coupon-product.entity';
6
+ import { CouponUser } from './coupon-user.entity';
7
+
8
+ export enum CouponDiscountType {
9
+ FIXED = 'fixed', // Fixed amount deducted e.g. KD 2.000
10
+ PERCENTAGE = 'percentage', // Percentage e.g. 15% off
11
+ }
12
+
13
+ export enum CouponAppliesTo {
14
+ SUBTOTAL = 'subtotal', // Applies to cart item total
15
+ DELIVERY = 'delivery', // Applies to shipping fee only
16
+ VAT = 'vat', // VAT free (removes VAT amount)
17
+ }
18
+
19
+ export enum CouponOsTarget {
20
+ ALL = 'all',
21
+ IOS = 'ios',
22
+ ANDROID = 'android',
23
+ WEB = 'web',
24
+ }
25
+
26
+ @Table
27
+ export class Coupon extends Model {
28
+ // ── Identity ──────────────────────────────────────────────────────────────────
29
+ @Column({ allowNull: false, unique: true })
30
+ declare code: string; // The code the user types e.g. WELCOME20
31
+
32
+ @Column({ allowNull: false })
33
+ declare nameEn: string;
34
+
35
+ @Column({ allowNull: false })
36
+ declare nameAr: string;
37
+
38
+ @Column({ type: DataType.TEXT, allowNull: true })
39
+ declare descriptionEn?: string;
40
+
41
+ @Column({ type: DataType.TEXT, allowNull: true })
42
+ declare descriptionAr?: string;
43
+
44
+ // ── Validity period ───────────────────────────────────────────────────────────
45
+ @Column({ type: DataType.DATE, allowNull: false })
46
+ declare startsAt: Date;
47
+
48
+ @Column({ type: DataType.DATE, allowNull: false })
49
+ declare expiresAt: Date;
50
+
51
+ // ── Discount ──────────────────────────────────────────────────────────────────
52
+ @Column({
53
+ type: DataType.ENUM(...Object.values(CouponDiscountType)),
54
+ allowNull: false,
55
+ defaultValue: CouponDiscountType.PERCENTAGE,
56
+ })
57
+ declare discountType: CouponDiscountType;
58
+
59
+ // The amount or percentage value
60
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: false })
61
+ declare discountValue: number;
62
+
63
+ // Max deduction cap (only relevant for percentage type)
64
+ // e.g. 20% off but max KD 5 deduction
65
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: true })
66
+ declare maxDiscountAmount?: number;
67
+
68
+ // ── Applies to ────────────────────────────────────────────────────────────────
69
+ @Column({
70
+ type: DataType.ENUM(...Object.values(CouponAppliesTo)),
71
+ allowNull: false,
72
+ defaultValue: CouponAppliesTo.SUBTOTAL,
73
+ })
74
+ declare appliesTo: CouponAppliesTo;
75
+
76
+ // ── Minimum order value required ─────────────────────────────────────────────
77
+ @Column({ type: DataType.DECIMAL(10, 3), allowNull: true, defaultValue: 0 })
78
+ declare minOrderAmount?: number;
79
+
80
+ // ── OS targeting ─────────────────────────────────────────────────────────────
81
+ @Column({
82
+ type: DataType.ENUM(...Object.values(CouponOsTarget)),
83
+ allowNull: false,
84
+ defaultValue: CouponOsTarget.ALL,
85
+ })
86
+ declare osTarget: CouponOsTarget;
87
+
88
+ // ── Usage limits ──────────────────────────────────────────────────────────────
89
+ // null = unlimited uses globally
90
+ @Column({ type: DataType.INTEGER, allowNull: true })
91
+ declare maxUsesTotal?: number;
92
+
93
+ // null = unlimited per user
94
+ @Column({ type: DataType.INTEGER, allowNull: true, defaultValue: 1 })
95
+ declare maxUsesPerUser?: number;
96
+
97
+ // Counter — incremented on each successful use (checked against maxUsesTotal)
98
+ @Column({ type: DataType.INTEGER, allowNull: false, defaultValue: 0 })
99
+ declare totalUsed: number;
100
+
101
+ // ── Scope flags ───────────────────────────────────────────────────────────────
102
+ // When true: applies only to products/stores/users in the junction tables
103
+ // When false: applies globally regardless of junction table contents
104
+ @Column({ allowNull: false, defaultValue: false })
105
+ declare isStoreSpecific: boolean;
106
+
107
+ @Column({ allowNull: false, defaultValue: false })
108
+ declare isProductSpecific: boolean;
109
+
110
+ @Column({ allowNull: false, defaultValue: false })
111
+ declare isUserSpecific: boolean;
112
+
113
+ @Column({ allowNull: false, defaultValue: true })
114
+ declare isActive: boolean;
115
+
116
+ // ── Associations ──────────────────────────────────────────────────────────────
117
+
118
+ @HasMany(() => CouponStore)
119
+ declare couponStores: CouponStore[];
120
+
121
+ @HasMany(() => CouponProduct)
122
+ declare couponProducts: CouponProduct[];
123
+
124
+ @HasMany(() => CouponUser)
125
+ declare couponUsers: CouponUser[];
126
+ }
@@ -53,6 +53,17 @@ 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
+
61
+ // ─── Coupons ───────────────────────────────────────────────────────────────────
62
+ import { Coupon } from './entities/coupon.entity';
63
+ import { CouponStore } from './entities/coupon-store.entity';
64
+ import { CouponProduct } from './entities/coupon-product.entity';
65
+ import { CouponUser } from './entities/coupon-user.entity';
66
+
56
67
  // =============================================================================
57
68
  // EXPORTS
58
69
  // =============================================================================
@@ -120,6 +131,22 @@ export {
120
131
  export { PaymentMethodCountry } from './entities/payment-method-country.entity';
121
132
  export { StorePaymentMethod } from './entities/store-payment-method.entity';
122
133
 
134
+ // ─── Carts ────────────────────────────────────────────────────────────────────
135
+ export { Cart, CartStatus } from './entities/cart.entity';
136
+ export { CartItem, CartItemType } from './entities/cart-item.entity';
137
+ export { CartItemBundleSelection } from './entities/cart-item-bundle-selection.entity';
138
+
139
+ // ─── Coupons ───────────────────────────────────────────────────────────────────
140
+ export {
141
+ Coupon,
142
+ CouponDiscountType,
143
+ CouponAppliesTo,
144
+ CouponOsTarget,
145
+ } from './entities/coupon.entity';
146
+ export { CouponStore } from './entities/coupon-store.entity';
147
+ export { CouponProduct } from './entities/coupon-product.entity';
148
+ export { CouponUser } from './entities/coupon-user.entity';
149
+
123
150
  // ─── Enums ────────────────────────────────────────────────────────────────────
124
151
  export { OsName } from './utils/enums/osName';
125
152
  export { ProductApp } from './utils/enums/productApp';
@@ -188,5 +215,16 @@ export function getDbModels(): ModelCtor[] {
188
215
  PaymentMethod,
189
216
  PaymentMethodCountry,
190
217
  StorePaymentMethod,
218
+
219
+ // Cart
220
+ Cart,
221
+ CartItem,
222
+ CartItemBundleSelection,
223
+
224
+ //Coupon
225
+ Coupon,
226
+ CouponStore,
227
+ CouponProduct,
228
+ CouponUser,
191
229
  ];
192
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-entities",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
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",