|
|
@ -1,15 +1,18 @@ |
|
|
|
import { Injectable, Inject } from '@nestjs/common'; |
|
|
|
import { Injectable, Inject } from '@nestjs/common'; |
|
|
|
import { User } from './entities/user.entity'; |
|
|
|
import { User } from './entities/user.entity'; |
|
|
|
import { CreateUserDto, UpdateUserDto } from './dto'; |
|
|
|
import { CreateUserDto, UpdateUserDto } from './dto'; |
|
|
|
import { USER_REPOSITORY } from '../../core/constants'; |
|
|
|
import { USER_REPOSITORY, WALLET_REPOSITORY } from '../../core/constants'; |
|
|
|
import * as argon from 'argon2'; |
|
|
|
import * as argon from 'argon2'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import * as _ from 'lodash'; |
|
|
|
import { UUID } from 'crypto'; |
|
|
|
import { UUID } from 'crypto'; |
|
|
|
|
|
|
|
import { Wallet } from '../wallets/entities/wallet.entity'; |
|
|
|
|
|
|
|
import { CreateWalletDto } from '../wallets/dto'; |
|
|
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
|
@Injectable() |
|
|
|
export class UsersService { |
|
|
|
export class UsersService { |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
@Inject(USER_REPOSITORY) private readonly userRepository: typeof User, |
|
|
|
@Inject(USER_REPOSITORY) private readonly userRepository: typeof User, |
|
|
|
|
|
|
|
@Inject(WALLET_REPOSITORY) private readonly walletRepository: typeof Wallet, |
|
|
|
) {} |
|
|
|
) {} |
|
|
|
|
|
|
|
|
|
|
|
async findAll() { |
|
|
|
async findAll() { |
|
|
@ -26,6 +29,8 @@ export class UsersService { |
|
|
|
|
|
|
|
|
|
|
|
const newUser = await this.userRepository.create(createUserDto); |
|
|
|
const newUser = await this.userRepository.create(createUserDto); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.createWallet({ userId: newUser.id, amount: 0 }); |
|
|
|
|
|
|
|
|
|
|
|
return _.pick(newUser, [ |
|
|
|
return _.pick(newUser, [ |
|
|
|
'firstName', |
|
|
|
'firstName', |
|
|
|
'lastName', |
|
|
|
'lastName', |
|
|
@ -56,4 +61,8 @@ export class UsersService { |
|
|
|
async findOneByEmail(email: string): Promise<User> { |
|
|
|
async findOneByEmail(email: string): Promise<User> { |
|
|
|
return await this.userRepository.findOne<User>({ where: { email } }); |
|
|
|
return await this.userRepository.findOne<User>({ where: { email } }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async createWallet(createWalletDto: CreateWalletDto) { |
|
|
|
|
|
|
|
await this.walletRepository.create(createWalletDto); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|