tt-entities 0.0.35 → 0.0.37
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/user-favorite-catalog.entity.d.ts +12 -0
- package/dist/libs/tatayab-entities-library/entities/user-favorite-catalog.entity.js +58 -0
- package/dist/libs/tatayab-entities-library/entities/user-favorite-catalog.entity.js.map +1 -0
- package/dist/libs/tatayab-entities-library/entities/user.entity.d.ts +2 -2
- package/dist/libs/tatayab-entities-library/entities/user.entity.js +2 -2
- package/dist/libs/tatayab-entities-library/entities/user.entity.js.map +1 -1
- package/dist/libs/tatayab-entities-library/index.d.ts +1 -0
- package/dist/libs/tatayab-entities-library/index.js +6 -2
- package/dist/libs/tatayab-entities-library/index.js.map +1 -1
- package/dist/src/main.js +82 -6
- package/libs/tatayab-entities-library/src/entities/user-favorite-catalog.entity.ts +43 -0
- package/libs/tatayab-entities-library/src/entities/user.entity.ts +3 -3
- package/libs/tatayab-entities-library/src/index.ts +3 -2
- package/package.json +1 -1
- package/src/main.ts +3 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Model, Table, Column, ForeignKey,
|
|
3
|
+
BelongsTo, DataType,
|
|
4
|
+
} from 'sequelize-typescript';
|
|
5
|
+
import { User } from './user.entity';
|
|
6
|
+
|
|
7
|
+
export enum FavoriteCatalogItemType {
|
|
8
|
+
PRODUCT = 'product',
|
|
9
|
+
BUNDLE = 'bundle',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Table({
|
|
13
|
+
indexes: [
|
|
14
|
+
{
|
|
15
|
+
// Prevent duplicate favorites for the same item
|
|
16
|
+
unique: true,
|
|
17
|
+
fields: ['userId', 'itemType', 'itemId'],
|
|
18
|
+
name: 'uq_user_favorite_catalog_item',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
// Fast lookup for all favorites of a user
|
|
22
|
+
fields: ['userId'],
|
|
23
|
+
name: 'idx_user_favorite_catalog_userId',
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
})
|
|
27
|
+
export class UserFavoriteCatalog extends Model {
|
|
28
|
+
@ForeignKey(() => User)
|
|
29
|
+
@Column({ allowNull: false })
|
|
30
|
+
declare userId: number;
|
|
31
|
+
|
|
32
|
+
@Column({
|
|
33
|
+
type: DataType.ENUM(...Object.values(FavoriteCatalogItemType)),
|
|
34
|
+
allowNull: false,
|
|
35
|
+
})
|
|
36
|
+
declare itemType: FavoriteCatalogItemType;
|
|
37
|
+
|
|
38
|
+
@Column({ allowNull: false })
|
|
39
|
+
declare itemId: number;
|
|
40
|
+
|
|
41
|
+
@BelongsTo(() => User)
|
|
42
|
+
declare user: User;
|
|
43
|
+
}
|
|
@@ -12,10 +12,10 @@ import { Language } from '../utils/enums/language';
|
|
|
12
12
|
import { Country } from './country.entity';
|
|
13
13
|
import { Gender } from '../utils/enums/gender';
|
|
14
14
|
import { UserAddress } from './user-address.entity';
|
|
15
|
-
import { UserFavorite } from './user-favorite.entity';
|
|
16
15
|
import { Cart } from './cart.entity';
|
|
17
16
|
import { Order } from './order.entity';
|
|
18
17
|
import { UserTransaction } from './user-transaction.entity';
|
|
18
|
+
import { UserFavoriteCatalog } from './user-favorite-catalog.entity';
|
|
19
19
|
|
|
20
20
|
@Table
|
|
21
21
|
export class User extends Model {
|
|
@@ -95,8 +95,8 @@ export class User extends Model {
|
|
|
95
95
|
@HasMany(() => UserAddress)
|
|
96
96
|
declare addresses: UserAddress[];
|
|
97
97
|
|
|
98
|
-
@HasMany(() =>
|
|
99
|
-
declare favorites:
|
|
98
|
+
@HasMany(() => UserFavoriteCatalog)
|
|
99
|
+
declare favorites: UserFavoriteCatalog[];
|
|
100
100
|
|
|
101
101
|
@HasMany(() => Cart)
|
|
102
102
|
declare carts: Cart[];
|
|
@@ -10,6 +10,7 @@ import { UserDevice } from './entities/userDevice.entity';
|
|
|
10
10
|
import { ApiKey } from './entities/apikey.entity';
|
|
11
11
|
import { UserAddress } from './entities/user-address.entity';
|
|
12
12
|
import { UserFavorite } from './entities/user-favorite.entity';
|
|
13
|
+
import { UserFavoriteCatalog } from './entities/user-favorite-catalog.entity';
|
|
13
14
|
|
|
14
15
|
// ─── Catalogue ────────────────────────────────────────────────────────────────
|
|
15
16
|
import { Category } from './entities/category.entity';
|
|
@@ -73,7 +74,6 @@ import { OrderStatusHistory } from './entities/order-status-history.entity';
|
|
|
73
74
|
import { UserTransaction } from './entities/user-transaction.entity';
|
|
74
75
|
import { PurchaseOrderOrderItem } from './entities/purchase-order-order-item.entity';
|
|
75
76
|
|
|
76
|
-
|
|
77
77
|
// =============================================================================
|
|
78
78
|
// EXPORTS
|
|
79
79
|
// =============================================================================
|
|
@@ -88,6 +88,7 @@ export { User } from './entities/user.entity';
|
|
|
88
88
|
export { UserDevice } from './entities/userDevice.entity';
|
|
89
89
|
export { UserAddress } from './entities/user-address.entity';
|
|
90
90
|
export { UserFavorite } from './entities/user-favorite.entity';
|
|
91
|
+
export { UserFavoriteCatalog } from './entities/user-favorite-catalog.entity';
|
|
91
92
|
|
|
92
93
|
// ─── Catalogue ────────────────────────────────────────────────────────────────
|
|
93
94
|
export { Category } from './entities/category.entity';
|
|
@@ -174,7 +175,6 @@ export {
|
|
|
174
175
|
} from './entities/user-transaction.entity';
|
|
175
176
|
export { PurchaseOrderOrderItem } from './entities/purchase-order-order-item.entity';
|
|
176
177
|
|
|
177
|
-
|
|
178
178
|
// ─── Enums ────────────────────────────────────────────────────────────────────
|
|
179
179
|
export { OsName } from './utils/enums/osName';
|
|
180
180
|
export { ProductApp } from './utils/enums/productApp';
|
|
@@ -201,6 +201,7 @@ export function getDbModels(): ModelCtor[] {
|
|
|
201
201
|
UserDevice,
|
|
202
202
|
UserAddress,
|
|
203
203
|
UserFavorite,
|
|
204
|
+
UserFavoriteCatalog,
|
|
204
205
|
|
|
205
206
|
// Catalogue
|
|
206
207
|
Category,
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import 'tsconfig-paths/register';
|
|
2
2
|
import { NestFactory } from '@nestjs/core';
|
|
3
3
|
import { AppModule } from './app.module';
|
|
4
|
+
import { Sequelize } from 'sequelize-typescript';
|
|
4
5
|
|
|
5
6
|
async function bootstrap() {
|
|
6
7
|
const app = await NestFactory.create(AppModule, { cors: true });
|
|
8
|
+
const sequelize = app.get(Sequelize);
|
|
9
|
+
await sequelize.sync({ alter: true });
|
|
7
10
|
await app.listen(process.env.SERVER_PORT ?? 9004);
|
|
8
11
|
}
|
|
9
12
|
bootstrap();
|