entity bugs

This commit is contained in:
2026-01-14 15:19:18 +03:30
parent 209a4fc723
commit aed4a1b333
12 changed files with 35 additions and 24 deletions
@@ -1,11 +1,11 @@
import { Entity, Enum, Index, Property } from '@mikro-orm/core';
import { Entity, Enum, Index, PrimaryKey, Property } from '@mikro-orm/core';
import { RefreshTokenType } from '../interfaces/IToken-payload';
@Entity({ tableName: 'refreshtokens' })
@Index({ properties: ['hashedToken'] })
export class RefreshToken {
@Property({ type: 'varchar', length: 255 })
export class RefreshToken {
@PrimaryKey({ type: 'varchar', length: 255 })
hashedToken!: string;
@Property()
@@ -1,11 +1,13 @@
import { Entity, Property, ManyToOne, Unique } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, Unique, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { NotifTitleEnum } from '../interfaces/notification.interface';
import { NotifChannelEnum } from '../interfaces/notification.interface';
@Entity({ tableName: 'notification_preferences' })
export class NotificationPreference extends BaseEntity {
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: bigint
@Property()
title!: NotifTitleEnum;
@@ -1,4 +1,4 @@
import { Entity, Property, ManyToOne, Enum } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, Enum, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from '../../user/entities/user.entity';
import { NotifTitleEnum } from '../interfaces/notification.interface';
@@ -6,6 +6,8 @@ import { Admin } from 'src/modules/admin/entities/admin.entity';
@Entity({ tableName: 'notifications' })
export class Notification extends BaseEntity {
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: bigint
@ManyToOne(() => User, { nullable: true })
user?: User;
@@ -1,10 +1,14 @@
import { Entity, ManyToOne, Property, Enum, Index } from '@mikro-orm/core';
import { Entity, ManyToOne, Property, Enum, Index, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { Order } from '../../order/entities/order.entity';
import { PaymentGatewayEnum, PaymentMethodEnum, PaymentStatusEnum } from '../interface/payment';
import { ulid } from 'ulid';
@Entity({ tableName: 'payments' })
export class Payment extends BaseEntity {
@PrimaryKey({ type: 'string', columnType:'char(26)' })
id: string=ulid()
@ManyToOne(() => Order)
@Index()
order!: Order;
@@ -1,11 +1,12 @@
import { Entity, Enum, Property } from '@mikro-orm/core';
import { Entity, Enum, ManyToOne, Property } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { AttributeType } from '../interface/product.interface';
import { Product } from './product.entity';
@Entity({ tableName: 'attributes' })
export class Attribute extends BaseEntity {
@Property({ type: 'bigint' })
productId: string
@ManyToOne(()=>Product)
product: Product
@Property({ primary: true })
id: bigint;
@@ -12,7 +12,7 @@ export class Product extends BaseEntity {
@ManyToOne(() => Category)
category: Category
@OneToMany(() => Attribute, (attr) => attr.productId)
@OneToMany(() => Attribute, (attr) => attr.product)
attributes = new Collection<Attribute>(this)
@Property()
+3 -2
View File
@@ -10,6 +10,7 @@ import { AttributeValue } from './entities/attribute-value.entity';
import { AuthModule } from '../auth/auth.module';
import { JwtModule } from '@nestjs/jwt';
import { UtilsModule } from '../util/utils.module';
import { CategoryRepository } from './repositories/category.repository';
@Module({
imports: [
@@ -19,7 +20,7 @@ import { UtilsModule } from '../util/utils.module';
UtilsModule,
],
controllers: [productController,],
providers: [productService, ProductRepository,],
exports: [ProductRepository,],
providers: [productService, ProductRepository,CategoryRepository],
exports: [ProductRepository,CategoryRepository],
})
export class productModule { }
+1 -3
View File
@@ -2,7 +2,6 @@ import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, Property } from
import { BaseEntity } from '../../../common/entities/base.entity';
import { Permission } from './permission.entity';
import { RolePermission } from './rolePermission.entity';
import { Admin } from 'src/modules/admin/entities/admin.entity';
import { ulid } from 'ulid';
@Entity({ tableName: 'roles' })
@@ -22,6 +21,5 @@ export class Role extends BaseEntity {
@ManyToMany({ entity: () => Permission, pivotEntity: () => RolePermission, inversedBy: p => p.roles })
permissions = new Collection<Permission>(this);
@OneToMany(() => Admin, admin => admin.role)
admins = new Collection<Admin>(this);
}
@@ -107,9 +107,6 @@ export class RolesService {
if (!role) {
throw new NotFoundException('Role not found');
}
if (!role.admins.isEmpty()) {
throw new BadRequestException('Role has admins');
}
// Hard delete pivot table entries (role_permissions) before soft deleting the role
await this.em.nativeDelete(RolePermission, { role: { id: role.id } });
@@ -1,4 +1,4 @@
import { Entity, Property, ManyToOne, Index, Enum } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, Index, Enum, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';
import { CreditTransactionType } from '../interface/credit';
@@ -6,6 +6,9 @@ import { CreditTransactionType } from '../interface/credit';
@Entity({ tableName: 'credit_transactions' })
@Index({ properties: ['user'] })
export class CreditTransaction extends BaseEntity {
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: bigint
@ManyToOne(() => User)
user!: User;
@@ -1,9 +1,12 @@
import { Entity, Property, ManyToOne } from '@mikro-orm/core';
import { Entity, Property, ManyToOne, PrimaryKey } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from './user.entity';
@Entity({ tableName: 'user_addresses' })
export class UserAddress extends BaseEntity {
@PrimaryKey({ type: 'bigint', autoincrement: true })
id: bigint
@ManyToOne(() => User)
user!: User;
+2 -2
View File
@@ -10,8 +10,8 @@ import { CreditTransaction } from '../entities/credit-transaction.entity';
@Injectable()
export class WalletService {
constructor(
private readonly walletTransactionRepository: CreditTransactionRepository,
private readonly pointTransactionRepository: CreditTransaction,
// private readonly walletTransactionRepository: CreditTransactionRepository,
) { }
// async getUserWalletTransactions(