up
This commit is contained in:
@@ -84,4 +84,9 @@ export class RestaurantSpecificationDto {
|
||||
|
||||
@ApiPropertyOptional({ example: 0.09, description: 'VAT rate (e.g., 0.09 for 9%)' })
|
||||
vat?: number;
|
||||
|
||||
@ApiPropertyOptional({ example: { registerScore: 100 }, description: 'Score' })
|
||||
score?: {
|
||||
registerScore?: number;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateRestaurantDto } from '../dto/create-restaurant.dto';
|
||||
import { UpdateRestaurantDto } from '../dto/update-restaurant.dto';
|
||||
import { RestaurantSpecificationDto } from '../dto/restaurant-specification.dto';
|
||||
import { Restaurant } from '../entities/restaurant.entity';
|
||||
import { Restaurant } from '../entities/restaurant.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { RestRepository } from '../repositories/rest.repository';
|
||||
import { RestMessage } from 'src/common/enums/message.enum';
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { Entity, Property, ManyToOne, Index } from '@mikro-orm/core';
|
||||
import { Entity, Property, ManyToOne, Index, Unique } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Restaurant } from 'src/modules/restaurants/entities/restaurant.entity';
|
||||
import { User } from './user.entity';
|
||||
|
||||
@Entity({ tableName: 'user_wallets' })
|
||||
@Unique({ properties: ['user', 'restaurant'], name: 'unique_user_restaurant' })
|
||||
@Index({ properties: ['user', 'restaurant'] }) // Composite index for most common query: find wallet by user and restaurant
|
||||
@Index({ properties: ['user'] }) // Index for queries finding all wallets for a user
|
||||
@Index({ properties: ['restaurant'] }) // Index for queries finding all wallets for a restaurant
|
||||
|
||||
@@ -69,20 +69,24 @@ export class UserService {
|
||||
return this.userRepository.findOne({ id });
|
||||
}
|
||||
|
||||
async create(phone: string): Promise<User> {
|
||||
async create(phone: string, restId: string): Promise<User> {
|
||||
const normalizedPhone = normalizePhone(phone);
|
||||
const _raw = {
|
||||
phone: normalizedPhone,
|
||||
firstName: normalizedPhone,
|
||||
birthDate: undefined,
|
||||
marriageDate: undefined,
|
||||
wallet: 0,
|
||||
points: 0,
|
||||
};
|
||||
|
||||
// get registerscore from restaurant
|
||||
const restaurant = await this.restaurantRepository.findOne({ id: restId });
|
||||
if (!restaurant) {
|
||||
throw new NotFoundException(`Restaurant not found.`);
|
||||
}
|
||||
const points = Number(restaurant.score?.registerScore || 0);
|
||||
const createData = _raw as unknown as RequiredEntityData<User>;
|
||||
|
||||
const user = this.userRepository.create(createData);
|
||||
this.userWalletRepository.create({ user: user, restaurant: restaurant, wallet: 0, points: points });
|
||||
await this.em.persistAndFlush(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user