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