@ashutoshvohra136/tenant-db-contract 1.0.11 → 1.0.12
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/entities/Brands.d.ts +2 -0
- package/dist/entities/Brands.js +5 -0
- package/dist/entities/Category.d.ts +3 -0
- package/dist/entities/Category.js +9 -0
- package/dist/entities/target.d.ts +17 -3
- package/dist/entities/target.js +111 -20
- package/package.json +1 -1
- package/src/entities/Brands.ts +4 -0
- package/src/entities/Category.ts +9 -0
- package/src/entities/target.ts +138 -17
|
@@ -10,6 +10,7 @@ import { BeatPlanVisits } from './BeatPlanVisits';
|
|
|
10
10
|
import { MerchandiserBrandsMappings } from './MerchandiserBrandsMappings';
|
|
11
11
|
import { BrandPromotionSchemes } from './BrandPromotionSchemes';
|
|
12
12
|
import { NotificationBrandMapping } from './NotificationBrandMapping';
|
|
13
|
+
import { Target } from './target';
|
|
13
14
|
export declare class Brands extends BaseEntity {
|
|
14
15
|
id: string;
|
|
15
16
|
name: string | null;
|
|
@@ -28,4 +29,5 @@ export declare class Brands extends BaseEntity {
|
|
|
28
29
|
merchandiserBrandsMappings?: MerchandiserBrandsMappings[];
|
|
29
30
|
brandPromotionscheme: BrandPromotionSchemes[];
|
|
30
31
|
notificationBrandMappings?: NotificationBrandMapping[];
|
|
32
|
+
targets: Target[];
|
|
31
33
|
}
|
package/dist/entities/Brands.js
CHANGED
|
@@ -22,6 +22,7 @@ const BeatPlanVisits_1 = require("./BeatPlanVisits");
|
|
|
22
22
|
const MerchandiserBrandsMappings_1 = require("./MerchandiserBrandsMappings");
|
|
23
23
|
const BrandPromotionSchemes_1 = require("./BrandPromotionSchemes");
|
|
24
24
|
const NotificationBrandMapping_1 = require("./NotificationBrandMapping");
|
|
25
|
+
const target_1 = require("./target");
|
|
25
26
|
let Brands = class Brands extends typeorm_1.BaseEntity {
|
|
26
27
|
};
|
|
27
28
|
exports.Brands = Brands;
|
|
@@ -98,6 +99,10 @@ __decorate([
|
|
|
98
99
|
(0, typeorm_1.OneToMany)(() => NotificationBrandMapping_1.NotificationBrandMapping, (mapping) => mapping.brand),
|
|
99
100
|
__metadata("design:type", Array)
|
|
100
101
|
], Brands.prototype, "notificationBrandMappings", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
(0, typeorm_1.OneToMany)(() => target_1.Target, (target) => target.brand),
|
|
104
|
+
__metadata("design:type", Array)
|
|
105
|
+
], Brands.prototype, "targets", void 0);
|
|
101
106
|
exports.Brands = Brands = __decorate([
|
|
102
107
|
(0, typeorm_1.Index)('code', ['code'], { unique: true })
|
|
103
108
|
// @Index("IDX_1687d82f42d8b3f8162a29e7df", ["code"], { unique: true })
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseEntity } from 'typeorm';
|
|
2
2
|
import { Product } from './Products';
|
|
3
3
|
import { BrandWiseCategory } from './BrandWiseCategory';
|
|
4
|
+
import { Target } from './target';
|
|
4
5
|
export declare class Catagory extends BaseEntity {
|
|
5
6
|
id: number;
|
|
6
7
|
name: string;
|
|
@@ -12,6 +13,8 @@ export declare class Catagory extends BaseEntity {
|
|
|
12
13
|
products: Product[];
|
|
13
14
|
subCategoryProducts: Product[];
|
|
14
15
|
brandCategory: BrandWiseCategory[];
|
|
16
|
+
categoryTargets: Target[];
|
|
17
|
+
subCategoryTargets: Target[];
|
|
15
18
|
created_at: Date;
|
|
16
19
|
updated_at: Date;
|
|
17
20
|
}
|
|
@@ -13,6 +13,7 @@ exports.Catagory = void 0;
|
|
|
13
13
|
const typeorm_1 = require("typeorm");
|
|
14
14
|
const Products_1 = require("./Products");
|
|
15
15
|
const BrandWiseCategory_1 = require("./BrandWiseCategory");
|
|
16
|
+
const target_1 = require("./target");
|
|
16
17
|
// import {SalesProduct} from './SalesProducts'
|
|
17
18
|
let Catagory = class Catagory extends typeorm_1.BaseEntity {
|
|
18
19
|
};
|
|
@@ -57,6 +58,14 @@ __decorate([
|
|
|
57
58
|
(0, typeorm_1.OneToMany)(() => BrandWiseCategory_1.BrandWiseCategory, (brandWiseCategory) => brandWiseCategory.brand),
|
|
58
59
|
__metadata("design:type", Array)
|
|
59
60
|
], Catagory.prototype, "brandCategory", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.OneToMany)(() => target_1.Target, (target) => target.category),
|
|
63
|
+
__metadata("design:type", Array)
|
|
64
|
+
], Catagory.prototype, "categoryTargets", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typeorm_1.OneToMany)(() => target_1.Target, (target) => target.subCategory),
|
|
67
|
+
__metadata("design:type", Array)
|
|
68
|
+
], Catagory.prototype, "subCategoryTargets", void 0);
|
|
60
69
|
__decorate([
|
|
61
70
|
(0, typeorm_1.CreateDateColumn)({ type: 'datetime' }),
|
|
62
71
|
__metadata("design:type", Date)
|
|
@@ -3,15 +3,29 @@ import { Users } from './Users';
|
|
|
3
3
|
import { Months } from './Enum/Months';
|
|
4
4
|
import { Product } from './Products';
|
|
5
5
|
import { AchievementHistory } from './AchievementHistory';
|
|
6
|
+
import { Catagory } from './Category';
|
|
7
|
+
import { Brands } from './Brands';
|
|
8
|
+
export declare enum TargetLevel {
|
|
9
|
+
SKU = "sku",
|
|
10
|
+
PRODUCT = "product",
|
|
11
|
+
SUBCATEGORY = "subcategory",
|
|
12
|
+
CATEGORY = "category"
|
|
13
|
+
}
|
|
6
14
|
export declare class Target extends BaseEntity {
|
|
7
15
|
id: string;
|
|
16
|
+
storeId: number;
|
|
8
17
|
month: Months;
|
|
9
18
|
year: number;
|
|
10
19
|
target: number;
|
|
11
|
-
|
|
20
|
+
targetLevel: TargetLevel;
|
|
21
|
+
sku?: string;
|
|
22
|
+
product?: Product;
|
|
23
|
+
category?: Catagory;
|
|
24
|
+
subCategory?: Catagory;
|
|
25
|
+
brand?: Brands;
|
|
26
|
+
users: Users;
|
|
27
|
+
createdBy?: number;
|
|
12
28
|
created_at: Date;
|
|
13
29
|
updated_at: Date;
|
|
14
|
-
product: Product;
|
|
15
|
-
users: Users;
|
|
16
30
|
AchHistory: AchievementHistory[];
|
|
17
31
|
}
|
package/dist/entities/target.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// import {
|
|
3
|
+
// BaseEntity,
|
|
4
|
+
// Column,
|
|
5
|
+
// CreateDateColumn,
|
|
6
|
+
// Entity,
|
|
7
|
+
// JoinColumn,
|
|
8
|
+
// ManyToOne,
|
|
9
|
+
// OneToMany,
|
|
10
|
+
// PrimaryGeneratedColumn,
|
|
11
|
+
// UpdateDateColumn,
|
|
12
|
+
// } from 'typeorm';
|
|
13
|
+
// import { Users } from './Users';
|
|
14
|
+
// import { Months } from './Enum/Months';
|
|
15
|
+
// import { Product } from './Products';
|
|
16
|
+
// import { AchievementHistory } from './AchievementHistory';
|
|
2
17
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
18
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
19
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9,64 +24,140 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
24
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
25
|
};
|
|
11
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Target = void 0;
|
|
27
|
+
exports.Target = exports.TargetLevel = void 0;
|
|
28
|
+
// @Entity('targets')
|
|
29
|
+
// export class Target extends BaseEntity {
|
|
30
|
+
// @PrimaryGeneratedColumn({ type: 'bigint', name: 'id' })
|
|
31
|
+
// id!: string; // Use `string` if your application handles bigint as strings
|
|
32
|
+
// @Column({
|
|
33
|
+
// type: 'enum',
|
|
34
|
+
// enum: Months,
|
|
35
|
+
// nullable: false, // Make it non-nullable if required
|
|
36
|
+
// })
|
|
37
|
+
// month!: Months;
|
|
38
|
+
// @Column({ type: 'int', nullable: false }) // Use `int` for year
|
|
39
|
+
// year!: number;
|
|
40
|
+
// @Column({ type: 'int', nullable: false, default: 0 }) // Use `int` for target
|
|
41
|
+
// target!: number;
|
|
42
|
+
// @Column({ type: 'varchar', nullable: true, default: '0' }) // Keep as `varchar` if achievement is a string
|
|
43
|
+
// achievement!: string;
|
|
44
|
+
// @CreateDateColumn({ type: 'datetime' })
|
|
45
|
+
// created_at!: Date;
|
|
46
|
+
// @UpdateDateColumn({ type: 'datetime' })
|
|
47
|
+
// updated_at!: Date;
|
|
48
|
+
// @ManyToOne(() => Product, (product) => product.targets)
|
|
49
|
+
// @JoinColumn({ name: 'product_id' })
|
|
50
|
+
// product!: Product;
|
|
51
|
+
// @ManyToOne(() => Users, (user) => user.targets)
|
|
52
|
+
// @JoinColumn({ name: 'user_id' })
|
|
53
|
+
// users!: Users;
|
|
54
|
+
// @OneToMany(() => AchievementHistory, (achievementHistory) => achievementHistory.target)
|
|
55
|
+
// AchHistory!: AchievementHistory[];
|
|
56
|
+
// }
|
|
13
57
|
const typeorm_1 = require("typeorm");
|
|
14
58
|
const Users_1 = require("./Users");
|
|
15
59
|
const Months_1 = require("./Enum/Months");
|
|
16
60
|
const Products_1 = require("./Products");
|
|
17
61
|
const AchievementHistory_1 = require("./AchievementHistory");
|
|
62
|
+
const Category_1 = require("./Category");
|
|
63
|
+
const Brands_1 = require("./Brands");
|
|
64
|
+
var TargetLevel;
|
|
65
|
+
(function (TargetLevel) {
|
|
66
|
+
TargetLevel["SKU"] = "sku";
|
|
67
|
+
TargetLevel["PRODUCT"] = "product";
|
|
68
|
+
TargetLevel["SUBCATEGORY"] = "subcategory";
|
|
69
|
+
TargetLevel["CATEGORY"] = "category";
|
|
70
|
+
})(TargetLevel || (exports.TargetLevel = TargetLevel = {}));
|
|
18
71
|
let Target = class Target extends typeorm_1.BaseEntity {
|
|
19
72
|
};
|
|
20
73
|
exports.Target = Target;
|
|
21
74
|
__decorate([
|
|
22
|
-
(0, typeorm_1.PrimaryGeneratedColumn)({ type: 'bigint'
|
|
75
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({ type: 'bigint' }),
|
|
23
76
|
__metadata("design:type", String)
|
|
24
77
|
], Target.prototype, "id", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
(0, typeorm_1.Column)({ type: 'int', name: 'store_id' }),
|
|
80
|
+
__metadata("design:type", Number)
|
|
81
|
+
], Target.prototype, "storeId", void 0);
|
|
25
82
|
__decorate([
|
|
26
83
|
(0, typeorm_1.Column)({
|
|
27
84
|
type: 'enum',
|
|
28
85
|
enum: Months_1.Months,
|
|
29
|
-
nullable: false, // Make it non-nullable if required
|
|
30
86
|
}),
|
|
31
87
|
__metadata("design:type", String)
|
|
32
88
|
], Target.prototype, "month", void 0);
|
|
33
89
|
__decorate([
|
|
34
|
-
(0, typeorm_1.Column)({ type: 'int'
|
|
35
|
-
,
|
|
90
|
+
(0, typeorm_1.Column)({ type: 'int' }),
|
|
36
91
|
__metadata("design:type", Number)
|
|
37
92
|
], Target.prototype, "year", void 0);
|
|
38
93
|
__decorate([
|
|
39
|
-
(0, typeorm_1.Column)({ type: '
|
|
40
|
-
,
|
|
94
|
+
(0, typeorm_1.Column)({ type: 'decimal', precision: 15, scale: 2 }),
|
|
41
95
|
__metadata("design:type", Number)
|
|
42
96
|
], Target.prototype, "target", void 0);
|
|
43
97
|
__decorate([
|
|
44
|
-
(0, typeorm_1.Column)({
|
|
45
|
-
|
|
98
|
+
(0, typeorm_1.Column)({
|
|
99
|
+
type: 'enum',
|
|
100
|
+
enum: TargetLevel,
|
|
101
|
+
name: 'target_level',
|
|
102
|
+
}),
|
|
46
103
|
__metadata("design:type", String)
|
|
47
|
-
], Target.prototype, "
|
|
104
|
+
], Target.prototype, "targetLevel", void 0);
|
|
48
105
|
__decorate([
|
|
49
|
-
(0, typeorm_1.
|
|
50
|
-
__metadata("design:type",
|
|
51
|
-
], Target.prototype, "
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, typeorm_1.UpdateDateColumn)({ type: 'datetime' }),
|
|
54
|
-
__metadata("design:type", Date)
|
|
55
|
-
], Target.prototype, "updated_at", void 0);
|
|
106
|
+
(0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
|
|
107
|
+
__metadata("design:type", String)
|
|
108
|
+
], Target.prototype, "sku", void 0);
|
|
56
109
|
__decorate([
|
|
57
|
-
(0, typeorm_1.ManyToOne)(() => Products_1.Product, (product) => product.targets),
|
|
110
|
+
(0, typeorm_1.ManyToOne)(() => Products_1.Product, (product) => product.targets, { nullable: true }),
|
|
58
111
|
(0, typeorm_1.JoinColumn)({ name: 'product_id' }),
|
|
59
112
|
__metadata("design:type", Products_1.Product)
|
|
60
113
|
], Target.prototype, "product", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
(0, typeorm_1.ManyToOne)(() => Category_1.Catagory, { nullable: true }),
|
|
116
|
+
(0, typeorm_1.JoinColumn)({ name: 'category_id' }),
|
|
117
|
+
__metadata("design:type", Category_1.Catagory)
|
|
118
|
+
], Target.prototype, "category", void 0);
|
|
119
|
+
__decorate([
|
|
120
|
+
(0, typeorm_1.ManyToOne)(() => Category_1.Catagory, { nullable: true }),
|
|
121
|
+
(0, typeorm_1.JoinColumn)({ name: 'subcategory_id' }),
|
|
122
|
+
__metadata("design:type", Category_1.Catagory)
|
|
123
|
+
], Target.prototype, "subCategory", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
(0, typeorm_1.ManyToOne)(() => Brands_1.Brands, { nullable: true }),
|
|
126
|
+
(0, typeorm_1.JoinColumn)({ name: 'brand_id' }),
|
|
127
|
+
__metadata("design:type", Brands_1.Brands)
|
|
128
|
+
], Target.prototype, "brand", void 0);
|
|
61
129
|
__decorate([
|
|
62
130
|
(0, typeorm_1.ManyToOne)(() => Users_1.Users, (user) => user.targets),
|
|
63
131
|
(0, typeorm_1.JoinColumn)({ name: 'user_id' }),
|
|
64
132
|
__metadata("design:type", Users_1.Users)
|
|
65
133
|
], Target.prototype, "users", void 0);
|
|
66
134
|
__decorate([
|
|
67
|
-
(0, typeorm_1.
|
|
135
|
+
(0, typeorm_1.Column)({ type: 'int', name: 'created_by', nullable: true }),
|
|
136
|
+
__metadata("design:type", Number)
|
|
137
|
+
], Target.prototype, "createdBy", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, typeorm_1.CreateDateColumn)({ type: 'datetime' }),
|
|
140
|
+
__metadata("design:type", Date)
|
|
141
|
+
], Target.prototype, "created_at", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
(0, typeorm_1.UpdateDateColumn)({ type: 'datetime' }),
|
|
144
|
+
__metadata("design:type", Date)
|
|
145
|
+
], Target.prototype, "updated_at", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
(0, typeorm_1.OneToMany)(() => AchievementHistory_1.AchievementHistory, (ah) => ah.target),
|
|
68
148
|
__metadata("design:type", Array)
|
|
69
149
|
], Target.prototype, "AchHistory", void 0);
|
|
70
150
|
exports.Target = Target = __decorate([
|
|
71
|
-
(0, typeorm_1.Entity)('targets')
|
|
151
|
+
(0, typeorm_1.Entity)('targets'),
|
|
152
|
+
(0, typeorm_1.Index)([
|
|
153
|
+
'user',
|
|
154
|
+
'storeId',
|
|
155
|
+
'month',
|
|
156
|
+
'year',
|
|
157
|
+
'targetLevel',
|
|
158
|
+
'sku',
|
|
159
|
+
'product',
|
|
160
|
+
'subCategory',
|
|
161
|
+
'category',
|
|
162
|
+
], { unique: true })
|
|
72
163
|
], Target);
|
package/package.json
CHANGED
package/src/entities/Brands.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { BeatPlanVisits } from './BeatPlanVisits';
|
|
|
20
20
|
import { MerchandiserBrandsMappings } from './MerchandiserBrandsMappings';
|
|
21
21
|
import { BrandPromotionSchemes } from './BrandPromotionSchemes';
|
|
22
22
|
import { NotificationBrandMapping } from './NotificationBrandMapping';
|
|
23
|
+
import { Target } from './target';
|
|
23
24
|
|
|
24
25
|
@Index('code', ['code'], { unique: true })
|
|
25
26
|
|
|
@@ -84,5 +85,8 @@ export class Brands extends BaseEntity {
|
|
|
84
85
|
|
|
85
86
|
@OneToMany(() => NotificationBrandMapping, (mapping) => mapping.brand)
|
|
86
87
|
notificationBrandMappings?: NotificationBrandMapping[];
|
|
88
|
+
|
|
89
|
+
@OneToMany(() => Target, (target) => target.brand)
|
|
90
|
+
targets!: Target[];
|
|
87
91
|
}
|
|
88
92
|
|
package/src/entities/Category.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from 'typeorm';
|
|
10
10
|
import { Product } from './Products';
|
|
11
11
|
import { BrandWiseCategory } from './BrandWiseCategory';
|
|
12
|
+
import { Target } from './target';
|
|
12
13
|
// import {SalesProduct} from './SalesProducts'
|
|
13
14
|
|
|
14
15
|
@Entity({ name: 'categories' })
|
|
@@ -49,6 +50,14 @@ export class Catagory extends BaseEntity {
|
|
|
49
50
|
@OneToMany(() => BrandWiseCategory, (brandWiseCategory) => brandWiseCategory.brand)
|
|
50
51
|
brandCategory!: BrandWiseCategory[];
|
|
51
52
|
|
|
53
|
+
|
|
54
|
+
@OneToMany(() => Target, (target) => target.category)
|
|
55
|
+
categoryTargets!: Target[];
|
|
56
|
+
|
|
57
|
+
@OneToMany(() => Target, (target) => target.subCategory)
|
|
58
|
+
subCategoryTargets!: Target[];
|
|
59
|
+
|
|
60
|
+
|
|
52
61
|
@CreateDateColumn({ type: 'datetime' })
|
|
53
62
|
created_at!: Date;
|
|
54
63
|
|
package/src/entities/target.ts
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
// import {
|
|
2
|
+
// BaseEntity,
|
|
3
|
+
// Column,
|
|
4
|
+
// CreateDateColumn,
|
|
5
|
+
// Entity,
|
|
6
|
+
// JoinColumn,
|
|
7
|
+
// ManyToOne,
|
|
8
|
+
// OneToMany,
|
|
9
|
+
// PrimaryGeneratedColumn,
|
|
10
|
+
// UpdateDateColumn,
|
|
11
|
+
// } from 'typeorm';
|
|
12
|
+
// import { Users } from './Users';
|
|
13
|
+
// import { Months } from './Enum/Months';
|
|
14
|
+
// import { Product } from './Products';
|
|
15
|
+
// import { AchievementHistory } from './AchievementHistory';
|
|
16
|
+
|
|
17
|
+
// @Entity('targets')
|
|
18
|
+
// export class Target extends BaseEntity {
|
|
19
|
+
// @PrimaryGeneratedColumn({ type: 'bigint', name: 'id' })
|
|
20
|
+
// id!: string; // Use `string` if your application handles bigint as strings
|
|
21
|
+
|
|
22
|
+
// @Column({
|
|
23
|
+
// type: 'enum',
|
|
24
|
+
// enum: Months,
|
|
25
|
+
// nullable: false, // Make it non-nullable if required
|
|
26
|
+
// })
|
|
27
|
+
// month!: Months;
|
|
28
|
+
|
|
29
|
+
// @Column({ type: 'int', nullable: false }) // Use `int` for year
|
|
30
|
+
// year!: number;
|
|
31
|
+
|
|
32
|
+
// @Column({ type: 'int', nullable: false, default: 0 }) // Use `int` for target
|
|
33
|
+
// target!: number;
|
|
34
|
+
|
|
35
|
+
// @Column({ type: 'varchar', nullable: true, default: '0' }) // Keep as `varchar` if achievement is a string
|
|
36
|
+
// achievement!: string;
|
|
37
|
+
|
|
38
|
+
// @CreateDateColumn({ type: 'datetime' })
|
|
39
|
+
// created_at!: Date;
|
|
40
|
+
|
|
41
|
+
// @UpdateDateColumn({ type: 'datetime' })
|
|
42
|
+
// updated_at!: Date;
|
|
43
|
+
|
|
44
|
+
// @ManyToOne(() => Product, (product) => product.targets)
|
|
45
|
+
// @JoinColumn({ name: 'product_id' })
|
|
46
|
+
// product!: Product;
|
|
47
|
+
|
|
48
|
+
// @ManyToOne(() => Users, (user) => user.targets)
|
|
49
|
+
// @JoinColumn({ name: 'user_id' })
|
|
50
|
+
// users!: Users;
|
|
51
|
+
|
|
52
|
+
// @OneToMany(() => AchievementHistory, (achievementHistory) => achievementHistory.target)
|
|
53
|
+
// AchHistory!: AchievementHistory[];
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
1
58
|
import {
|
|
2
59
|
BaseEntity,
|
|
3
60
|
Column,
|
|
@@ -8,47 +65,111 @@ import {
|
|
|
8
65
|
OneToMany,
|
|
9
66
|
PrimaryGeneratedColumn,
|
|
10
67
|
UpdateDateColumn,
|
|
68
|
+
Index,
|
|
11
69
|
} from 'typeorm';
|
|
70
|
+
|
|
12
71
|
import { Users } from './Users';
|
|
13
72
|
import { Months } from './Enum/Months';
|
|
14
73
|
import { Product } from './Products';
|
|
15
74
|
import { AchievementHistory } from './AchievementHistory';
|
|
75
|
+
import { Catagory } from './Category';
|
|
76
|
+
import { Brands } from './Brands';
|
|
77
|
+
|
|
78
|
+
export enum TargetLevel {
|
|
79
|
+
SKU = 'sku',
|
|
80
|
+
PRODUCT = 'product',
|
|
81
|
+
SUBCATEGORY = 'subcategory',
|
|
82
|
+
CATEGORY = 'category',
|
|
83
|
+
}
|
|
16
84
|
|
|
17
85
|
@Entity('targets')
|
|
86
|
+
@Index(
|
|
87
|
+
[
|
|
88
|
+
'user',
|
|
89
|
+
'storeId',
|
|
90
|
+
'month',
|
|
91
|
+
'year',
|
|
92
|
+
'targetLevel',
|
|
93
|
+
'sku',
|
|
94
|
+
'product',
|
|
95
|
+
'subCategory',
|
|
96
|
+
'category',
|
|
97
|
+
],
|
|
98
|
+
{ unique: true }
|
|
99
|
+
)
|
|
18
100
|
export class Target extends BaseEntity {
|
|
19
|
-
@PrimaryGeneratedColumn({ type: 'bigint'
|
|
20
|
-
id!: string;
|
|
101
|
+
@PrimaryGeneratedColumn({ type: 'bigint' })
|
|
102
|
+
id!: string;
|
|
103
|
+
|
|
104
|
+
// 🔹 Mandatory
|
|
105
|
+
@Column({ type: 'int', name: 'store_id' })
|
|
106
|
+
storeId!: number;
|
|
21
107
|
|
|
22
108
|
@Column({
|
|
23
109
|
type: 'enum',
|
|
24
110
|
enum: Months,
|
|
25
|
-
nullable: false, // Make it non-nullable if required
|
|
26
111
|
})
|
|
27
112
|
month!: Months;
|
|
28
113
|
|
|
29
|
-
@Column({ type: 'int'
|
|
114
|
+
@Column({ type: 'int' })
|
|
30
115
|
year!: number;
|
|
31
116
|
|
|
32
|
-
@Column({ type: '
|
|
117
|
+
@Column({ type: 'decimal', precision: 15, scale: 2 })
|
|
33
118
|
target!: number;
|
|
34
119
|
|
|
35
|
-
@Column({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
120
|
+
@Column({
|
|
121
|
+
type: 'enum',
|
|
122
|
+
enum: TargetLevel,
|
|
123
|
+
name: 'target_level',
|
|
124
|
+
})
|
|
125
|
+
targetLevel!: TargetLevel;
|
|
40
126
|
|
|
41
|
-
|
|
42
|
-
|
|
127
|
+
// 🔹 SKU (only for sku-level)
|
|
128
|
+
@Column({ type: 'varchar', nullable: true })
|
|
129
|
+
sku?: string;
|
|
43
130
|
|
|
44
|
-
|
|
131
|
+
// 🔹 Product (sku + product level)
|
|
132
|
+
@ManyToOne(() => Product, (product) => product.targets, { nullable: true })
|
|
45
133
|
@JoinColumn({ name: 'product_id' })
|
|
46
|
-
product
|
|
134
|
+
product?: Product;
|
|
135
|
+
|
|
136
|
+
// 🔹 Category (always useful for reporting)
|
|
137
|
+
@ManyToOne(() => Catagory, { nullable: true })
|
|
138
|
+
@JoinColumn({ name: 'category_id' })
|
|
139
|
+
category?: Catagory;
|
|
140
|
+
|
|
141
|
+
// 🔹 SubCategory
|
|
142
|
+
@ManyToOne(() => Catagory, { nullable: true })
|
|
143
|
+
@JoinColumn({ name: 'subcategory_id' })
|
|
144
|
+
subCategory?: Catagory;
|
|
145
|
+
|
|
146
|
+
// 🔹 Brand (optional but useful)
|
|
147
|
+
@ManyToOne(() => Brands, { nullable: true })
|
|
148
|
+
@JoinColumn({ name: 'brand_id' })
|
|
149
|
+
brand?: Brands;
|
|
150
|
+
|
|
151
|
+
// 🔹 User
|
|
152
|
+
|
|
153
|
+
// @ManyToOne(() => Users, (user) => user.targets)
|
|
154
|
+
// @JoinColumn({ name: 'user_id' })
|
|
155
|
+
// user!: Users;
|
|
47
156
|
|
|
48
|
-
|
|
157
|
+
@ManyToOne(() => Users, (user) => user.targets)
|
|
49
158
|
@JoinColumn({ name: 'user_id' })
|
|
50
159
|
users!: Users;
|
|
51
160
|
|
|
52
|
-
|
|
161
|
+
|
|
162
|
+
// 🔹 Audit
|
|
163
|
+
@Column({ type: 'int', name: 'created_by', nullable: true })
|
|
164
|
+
createdBy?: number;
|
|
165
|
+
|
|
166
|
+
@CreateDateColumn({ type: 'datetime' })
|
|
167
|
+
created_at!: Date;
|
|
168
|
+
|
|
169
|
+
@UpdateDateColumn({ type: 'datetime' })
|
|
170
|
+
updated_at!: Date;
|
|
171
|
+
|
|
172
|
+
// 🔹 Achievement history
|
|
173
|
+
@OneToMany(() => AchievementHistory, (ah) => ah.target)
|
|
53
174
|
AchHistory!: AchievementHistory[];
|
|
54
|
-
}
|
|
175
|
+
}
|