Update users module

master
Mahdi 2 weeks ago
parent 8613180c87
commit 4ee47eba4b
  1. 2
      src/modules/users/users.controller.ts
  2. 3
      src/modules/users/users.module.ts
  3. 11
      src/modules/users/users.service.ts
  4. 4
      src/modules/wallets/dto/create-wallet.dto.ts
  5. 2
      src/modules/wallets/dto/index.ts
  6. 7
      src/modules/wallets/dto/update-wallet.dto.ts

@ -27,7 +27,7 @@ export class UsersController {
return this.usersService.findOne(id); return this.usersService.findOne(id);
} }
@UseGuards(AuthGuard('jwt')) // @UseGuards(AuthGuard('jwt'))
@Post() @Post()
create(@Body() createUserDto: CreateUserDto) { create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto); return this.usersService.create(createUserDto);

@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
import { UsersService } from './users.service'; import { UsersService } from './users.service';
import { usersProviders } from './users.providers'; import { usersProviders } from './users.providers';
import { UsersController } from './users.controller'; import { UsersController } from './users.controller';
import { walletsProviders } from '../wallets/wallets.providers';
@Module({ @Module({
providers: [UsersService, ...usersProviders], providers: [UsersService, ...usersProviders, ...walletsProviders],
exports: [UsersService], exports: [UsersService],
controllers: [UsersController], controllers: [UsersController],
}) })

@ -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);
}
} }

@ -0,0 +1,4 @@
export class CreateWalletDto {
userId: number;
amount: number;
}

@ -0,0 +1,2 @@
export * from './create-wallet.dto';
export * from './update-wallet.dto';

@ -1,3 +1,4 @@
export class UpdateWalletDto { import { PartialType } from '@nestjs/mapped-types';
amount: number; import { CreateWalletDto } from './create-wallet.dto';
}
export class UpdateWalletDto extends PartialType(CreateWalletDto) {}

Loading…
Cancel
Save