39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Cascade, Collection, Entity, Enum, Index, ManyToOne, OneToMany, Property, Unique } from '@mikro-orm/core';
|
|
import { BaseEntity } from '../../../common/entities/base.entity';
|
|
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
|
|
import { PaymentGatewayEnum, PaymentMethodEnum } from '../interface/payment';
|
|
import { PaymentMethodCard } from './payment-method-card.entity';
|
|
|
|
@Entity({ tableName: 'payment_methods' })
|
|
@Unique({ properties: ['restaurant', 'method'] })
|
|
@Index({ properties: ['restaurant', 'enabled'] })
|
|
@Index({ properties: ['restaurant'] })
|
|
export class PaymentMethod extends BaseEntity {
|
|
@ManyToOne(() => Restaurant)
|
|
restaurant!: Restaurant;
|
|
|
|
@Enum(() => PaymentMethodEnum)
|
|
method!: PaymentMethodEnum;
|
|
|
|
@Enum(() => PaymentGatewayEnum)
|
|
gateway: PaymentGatewayEnum | null = null;
|
|
|
|
@Property({ nullable: true })
|
|
description?: string;
|
|
|
|
@OneToMany(() => PaymentMethodCard, card => card.paymentMethod, {
|
|
cascade: [Cascade.ALL],
|
|
orphanRemoval: true,
|
|
})
|
|
cards = new Collection<PaymentMethodCard>(this);
|
|
|
|
@Property({ default: true })
|
|
enabled: boolean = true;
|
|
|
|
@Property({ type: 'integer', default: 0 })
|
|
order: number = 0;
|
|
|
|
@Property({ nullable: true })
|
|
merchantId?: string;
|
|
}
|