change entity names
This commit is contained in:
@@ -5,7 +5,7 @@ import { PaymentMethodRepository } from '../repositories/payment-method.reposito
|
||||
import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
|
||||
import { UpdatePaymentMethodDto } from '../dto/update-payment-method.dto';
|
||||
import { RequiredEntityData } from '@mikro-orm/core';
|
||||
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
|
||||
import { Shop } from ../../..shops/entities/shop.entity';
|
||||
import { RestMessage, PaymentMessage } from 'src/common/enums/message.enum';
|
||||
|
||||
@Injectable()
|
||||
@@ -16,14 +16,14 @@ export class PaymentMethodService {
|
||||
) {}
|
||||
|
||||
async create(restId: string, createPaymentMethodDto: CreatePaymentMethodDto): Promise<PaymentMethod> {
|
||||
// Check if restaurant exists
|
||||
const restaurant = await this.em.findOne(Restaurant, { id: restId });
|
||||
if (!restaurant) {
|
||||
// Check if shop exists
|
||||
const shop = await this.em.findOne(Shop, { id: restId });
|
||||
if (!shop) {
|
||||
throw new NotFoundException(RestMessage.NOT_FOUND);
|
||||
}
|
||||
|
||||
const paymentMethod = this.paymentMethodRepository.create({
|
||||
restaurant,
|
||||
shop,
|
||||
...createPaymentMethodDto,
|
||||
} as unknown as RequiredEntityData<PaymentMethod>);
|
||||
await this.em.persistAndFlush(paymentMethod);
|
||||
@@ -31,11 +31,11 @@ export class PaymentMethodService {
|
||||
}
|
||||
|
||||
async findAll(): Promise<PaymentMethod[]> {
|
||||
return this.paymentMethodRepository.findAll({ populate: ['restaurant'] });
|
||||
return this.paymentMethodRepository.findAll({ populate: ['shop'] });
|
||||
}
|
||||
|
||||
async findOne(id: string): Promise<PaymentMethod> {
|
||||
const paymentMethod = await this.paymentMethodRepository.findOne({ id }, { populate: ['restaurant'] });
|
||||
const paymentMethod = await this.paymentMethodRepository.findOne({ id }, { populate: ['shop'] });
|
||||
if (!paymentMethod) {
|
||||
throw new NotFoundException(PaymentMessage.PAYMENT_METHOD_NOT_FOUND);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export class PaymentMethodService {
|
||||
}
|
||||
|
||||
async findByRestaurant(restaurantId: string): Promise<PaymentMethod[]> {
|
||||
return this.paymentMethodRepository.find({ restaurant: { id: restaurantId } }, { populate: ['restaurant'] });
|
||||
return this.paymentMethodRepository.find({ shop: { id: restaurantId } }, { populate: ['shop'] });
|
||||
}
|
||||
|
||||
async update(id: string, updatePaymentMethodDto: UpdatePaymentMethodDto): Promise<PaymentMethod> {
|
||||
|
||||
Reference in New Issue
Block a user