change entity names

This commit is contained in:
2026-02-08 09:18:20 +03:30
parent 6be6a66079
commit 9a7010dcea
180 changed files with 2751 additions and 2513 deletions
+24 -24
View File
@@ -2,7 +2,7 @@ import { Injectable, NotFoundException, BadRequestException } from '@nestjs/comm
import { FilterQuery, RequiredEntityData } from '@mikro-orm/core';
import { User } from '../entities/user.entity';
import { UserAddress } from '../entities/user-address.entity';
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
import { Shop } from ../../..shops/entities/shop.entity';
import { EntityManager } from '@mikro-orm/postgresql';
import { UpdateUserDto } from '../dto/update-user.dto';
import { FindUsersDto } from '../dto/find-user.dto';
@@ -12,8 +12,8 @@ import { CreateUserAddressDto } from '../dto/create-user-address.dto';
import { UpdateUserAddressDto } from '../dto/update-user-address.dto';
import { PaginatedResult } from 'src/common/interfaces/pagination.interface';
import { UserRepository } from '../repositories/user.repository';
import { normalizePhone } from '../../utils/phone.util';
import { RestRepository } from 'src/modules/restaurants/repositories/rest.repository';
import { normalizePhone } from '../../../utils/phone.util';
import { RestRepository } from ../../..shops/repositories/rest.repository';
import { WalletTransactionRepository } from '../repositories/wallet-transaction.repository';
import { WalletService } from './wallet.service';
import { WalletTransactionReason, WalletTransactionType } from '../interface/wallet';
@@ -83,18 +83,18 @@ export class UserService {
birthDate: undefined,
marriageDate: undefined,
};
// get registerscore from restaurant
const restaurant = await this.restaurantRepository.findOne({ id: restId });
if (!restaurant) {
throw new NotFoundException(`Restaurant not found.`);
// get registerscore from shop
const shop = await this.restaurantRepository.findOne({ id: restId });
if (!shop) {
throw new NotFoundException(`Shop not found.`);
}
const points = Number(restaurant.score?.registerScore || 0);
const points = Number(shop.score?.registerScore || 0);
const createData = _raw as unknown as RequiredEntityData<User>;
const user = this.userRepository.create(createData);
const newWalletTransaction = this.walletTransactionRepository.create({
user: user,
restaurant: restaurant,
shop: shop,
balance: 0,
amount: points,
type: WalletTransactionType.CREDIT,
@@ -134,7 +134,7 @@ export class UserService {
// 2. Build the 'where' filter query
const where: FilterQuery<User> = {
orders: {
restaurant: {
shop: {
id: restId,
},
},
@@ -312,18 +312,18 @@ export class UserService {
if (!user) {
throw new NotFoundException(`User with ID ${userId} not found.`);
}
const restaurant = await em.findOne(Restaurant, { id: restId });
if (!restaurant) {
throw new NotFoundException(`Restaurant with ID ${restId} not found.`);
const shop = await em.findOne(Shop, { id: restId });
if (!shop) {
throw new NotFoundException(`Shop with ID ${restId} not found.`);
}
let walletTransaction = await em.findOne(WalletTransaction, { user: { id: userId }, restaurant: { id: restId } },
let walletTransaction = await em.findOne(WalletTransaction, { user: { id: userId }, shop: { id: restId } },
{ orderBy: { createdAt: 'DESC' } });
if (!walletTransaction) {
walletTransaction = em.create(WalletTransaction,
{
user: user,
restaurant,
shop,
balance: 0,
amount: 0,
type: WalletTransactionType.CREDIT,
@@ -339,22 +339,22 @@ export class UserService {
throw new BadRequestException('Points to convert must be greater than 0.');
}
if (!restaurant.score) {
throw new BadRequestException('Restaurant score not found.');
if (!shop.score) {
throw new BadRequestException('Shop score not found.');
}
if (!restaurant.score.purchaseScore) {
throw new BadRequestException('Restaurant purchase score not found.');
if (!shop.score.purchaseScore) {
throw new BadRequestException('Shop purchase score not found.');
}
if (!restaurant.score.purchaseAmount) {
throw new BadRequestException('Restaurant purchase amount not found.');
if (!shop.score.purchaseAmount) {
throw new BadRequestException('Shop purchase amount not found.');
}
const walletIncreaseAmount =
(Number(pointsToConvert) * Number(restaurant.score.purchaseAmount)) / Number(restaurant.score.purchaseScore);
(Number(pointsToConvert) * Number(shop.score.purchaseAmount)) / Number(shop.score.purchaseScore);
// Convert points to wallet (1:1 ratio - can be made configurable)
const newWalletTransaction = em.create(WalletTransaction, {
user: user,
restaurant: restaurant,
shop: shop,
amount: walletIncreaseAmount,
type: WalletTransactionType.CREDIT,
reason: WalletTransactionReason.CONVERT_SCORE_TO_WALLET,
@@ -371,7 +371,7 @@ export class UserService {
}
getUserWallet(userId: string, restId: string): Promise<WalletTransaction | null> {
return this.walletTransactionRepository.findOne({ user: { id: userId }, restaurant: { id: restId } },
return this.walletTransactionRepository.findOne({ user: { id: userId }, shop: { id: restId } },
{ orderBy: { createdAt: 'DESC' } });
}