diff --git a/src/modules/users/users.controller.ts b/src/modules/users/users.controller.ts index adc6144..dac5d08 100644 --- a/src/modules/users/users.controller.ts +++ b/src/modules/users/users.controller.ts @@ -27,7 +27,7 @@ export class UsersController { return this.usersService.findOne(id); } - @UseGuards(AuthGuard('jwt')) + // @UseGuards(AuthGuard('jwt')) @Post() create(@Body() createUserDto: CreateUserDto) { return this.usersService.create(createUserDto); diff --git a/src/modules/users/users.module.ts b/src/modules/users/users.module.ts index 7ddf719..49540d5 100644 --- a/src/modules/users/users.module.ts +++ b/src/modules/users/users.module.ts @@ -2,9 +2,10 @@ import { Module } from '@nestjs/common'; import { UsersService } from './users.service'; import { usersProviders } from './users.providers'; import { UsersController } from './users.controller'; +import { walletsProviders } from '../wallets/wallets.providers'; @Module({ - providers: [UsersService, ...usersProviders], + providers: [UsersService, ...usersProviders, ...walletsProviders], exports: [UsersService], controllers: [UsersController], }) diff --git a/src/modules/users/users.service.ts b/src/modules/users/users.service.ts index 23ca00f..7377b73 100644 --- a/src/modules/users/users.service.ts +++ b/src/modules/users/users.service.ts @@ -1,15 +1,18 @@ import { Injectable, Inject } from '@nestjs/common'; import { User } from './entities/user.entity'; 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 _ from 'lodash'; import { UUID } from 'crypto'; +import { Wallet } from '../wallets/entities/wallet.entity'; +import { CreateWalletDto } from '../wallets/dto'; @Injectable() export class UsersService { constructor( @Inject(USER_REPOSITORY) private readonly userRepository: typeof User, + @Inject(WALLET_REPOSITORY) private readonly walletRepository: typeof Wallet, ) {} async findAll() { @@ -26,6 +29,8 @@ export class UsersService { const newUser = await this.userRepository.create(createUserDto); + await this.createWallet({ userId: newUser.id, amount: 0 }); + return _.pick(newUser, [ 'firstName', 'lastName', @@ -56,4 +61,8 @@ export class UsersService { async findOneByEmail(email: string): Promise { return await this.userRepository.findOne({ where: { email } }); } + + private async createWallet(createWalletDto: CreateWalletDto) { + await this.walletRepository.create(createWalletDto); + } } diff --git a/src/modules/wallets/dto/create-wallet.dto.ts b/src/modules/wallets/dto/create-wallet.dto.ts new file mode 100644 index 0000000..c965f6c --- /dev/null +++ b/src/modules/wallets/dto/create-wallet.dto.ts @@ -0,0 +1,4 @@ +export class CreateWalletDto { + userId: number; + amount: number; +} diff --git a/src/modules/wallets/dto/index.ts b/src/modules/wallets/dto/index.ts new file mode 100644 index 0000000..5b78187 --- /dev/null +++ b/src/modules/wallets/dto/index.ts @@ -0,0 +1,2 @@ +export * from './create-wallet.dto'; +export * from './update-wallet.dto'; diff --git a/src/modules/wallets/dto/update-wallet.dto.ts b/src/modules/wallets/dto/update-wallet.dto.ts index c6e94ba..7825603 100644 --- a/src/modules/wallets/dto/update-wallet.dto.ts +++ b/src/modules/wallets/dto/update-wallet.dto.ts @@ -1,3 +1,4 @@ -export class UpdateWalletDto { - amount: number; -} +import { PartialType } from '@nestjs/mapped-types'; +import { CreateWalletDto } from './create-wallet.dto'; + +export class UpdateWalletDto extends PartialType(CreateWalletDto) {}