tt-entities 0.0.31 → 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.
- package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.d.ts +12 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.js +50 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-product.entity.js.map +1 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.d.ts +9 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.js +40 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-store.entity.js.map +1 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.d.ts +11 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.js +48 -0
- package/dist/libs/tatayab-entities-library/entities/coupon-user.entity.js.map +1 -0
- package/dist/libs/tatayab-entities-library/entities/coupon.entity.d.ts +44 -0
- package/dist/libs/tatayab-entities-library/entities/coupon.entity.js +145 -0
- package/dist/libs/tatayab-entities-library/entities/coupon.entity.js.map +1 -0
- package/dist/libs/tatayab-entities-library/index.d.ts +4 -0
- package/dist/libs/tatayab-entities-library/index.js +21 -2
- package/dist/libs/tatayab-entities-library/index.js.map +1 -1
- package/dist/src/main.js +345 -3
- package/libs/tatayab-entities-library/src/entities/coupon-product.entity.ts +25 -0
- package/libs/tatayab-entities-library/src/entities/coupon-store.entity.ts +17 -0
- package/libs/tatayab-entities-library/src/entities/coupon-user.entity.ts +27 -0
- package/libs/tatayab-entities-library/src/entities/coupon.entity.ts +126 -0
- package/libs/tatayab-entities-library/src/index.ts +23 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -58,6 +58,12 @@ import { Cart } from './entities/cart.entity';
|
|
|
58
58
|
import { CartItem } from './entities/cart-item.entity';
|
|
59
59
|
import { CartItemBundleSelection } from './entities/cart-item-bundle-selection.entity';
|
|
60
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
|
+
|
|
61
67
|
// =============================================================================
|
|
62
68
|
// EXPORTS
|
|
63
69
|
// =============================================================================
|
|
@@ -130,6 +136,17 @@ export { Cart, CartStatus } from './entities/cart.entity';
|
|
|
130
136
|
export { CartItem, CartItemType } from './entities/cart-item.entity';
|
|
131
137
|
export { CartItemBundleSelection } from './entities/cart-item-bundle-selection.entity';
|
|
132
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
|
+
|
|
133
150
|
// ─── Enums ────────────────────────────────────────────────────────────────────
|
|
134
151
|
export { OsName } from './utils/enums/osName';
|
|
135
152
|
export { ProductApp } from './utils/enums/productApp';
|
|
@@ -203,5 +220,11 @@ export function getDbModels(): ModelCtor[] {
|
|
|
203
220
|
Cart,
|
|
204
221
|
CartItem,
|
|
205
222
|
CartItemBundleSelection,
|
|
223
|
+
|
|
224
|
+
//Coupon
|
|
225
|
+
Coupon,
|
|
226
|
+
CouponStore,
|
|
227
|
+
CouponProduct,
|
|
228
|
+
CouponUser,
|
|
206
229
|
];
|
|
207
230
|
}
|