parent
4ee47eba4b
commit
c96ff31be7
13 changed files with 200 additions and 4 deletions
@ -0,0 +1,5 @@ |
||||
export class CreateWalletsTransactionDto { |
||||
userId: number; |
||||
operation: number; |
||||
byAmount: number; |
||||
} |
@ -0,0 +1,14 @@ |
||||
import { Table, Column, Model, DataType, HasOne } from 'sequelize-typescript'; |
||||
import { WalletsTransactions } from './wallets-transaction.entity'; |
||||
|
||||
@Table({ tableName: 'transaction_operations', timestamps: false }) |
||||
export class TransactionOperations extends Model<TransactionOperations> { |
||||
@Column({ |
||||
type: DataType.STRING, |
||||
allowNull: false, |
||||
}) |
||||
name: string; |
||||
|
||||
@HasOne(() => WalletsTransactions) |
||||
order: WalletsTransactions; |
||||
} |
@ -0,0 +1,34 @@ |
||||
import { |
||||
Table, |
||||
Column, |
||||
Model, |
||||
DataType, |
||||
ForeignKey, |
||||
BelongsTo, |
||||
} from 'sequelize-typescript'; |
||||
import { User } from 'src/modules/users/entities/user.entity'; |
||||
import { TransactionOperations } from './transaction-operation.entity'; |
||||
|
||||
@Table({ tableName: 'wallets_transactions', updatedAt: false }) |
||||
export class WalletsTransactions extends Model<WalletsTransactions> { |
||||
@Column({ |
||||
type: DataType.FLOAT, |
||||
allowNull: false, |
||||
defaultValue: 0, |
||||
}) |
||||
byAmount: number; |
||||
|
||||
@ForeignKey(() => User) |
||||
@Column |
||||
userId: number; |
||||
|
||||
@BelongsTo(() => User) |
||||
user: User; |
||||
|
||||
@ForeignKey(() => TransactionOperations) |
||||
@Column |
||||
operation: number; |
||||
|
||||
@BelongsTo(() => TransactionOperations) |
||||
transactionOperations: TransactionOperations; |
||||
} |
@ -0,0 +1,33 @@ |
||||
import { |
||||
Controller, |
||||
Get, |
||||
Post, |
||||
Body, |
||||
Patch, |
||||
Param, |
||||
Delete, |
||||
} from '@nestjs/common'; |
||||
import { WalletsTransactionsService } from './wallets-transactions.service'; |
||||
import { CreateWalletsTransactionDto } from './dto/create-wallets-transaction.dto'; |
||||
|
||||
@Controller('wallets-transactions') |
||||
export class WalletsTransactionsController { |
||||
constructor( |
||||
private readonly walletsTransactionsService: WalletsTransactionsService, |
||||
) {} |
||||
|
||||
@Get() |
||||
findAll() { |
||||
return this.walletsTransactionsService.findAll(); |
||||
} |
||||
|
||||
@Get(':id') |
||||
findOne(@Param('id') id: number) { |
||||
return this.walletsTransactionsService.findOne(id); |
||||
} |
||||
|
||||
@Get('users/:id') |
||||
findByUser(@Param('id') id: number) { |
||||
return this.walletsTransactionsService.findByUser(id); |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
import { Module } from '@nestjs/common'; |
||||
import { WalletsTransactionsService } from './wallets-transactions.service'; |
||||
import { WalletsTransactionsController } from './wallets-transactions.controller'; |
||||
import { walletsTransactionsProviders } from './wallets-transactions.providers'; |
||||
|
||||
@Module({ |
||||
controllers: [WalletsTransactionsController], |
||||
providers: [WalletsTransactionsService, ...walletsTransactionsProviders], |
||||
exports: [WalletsTransactionsService], |
||||
}) |
||||
export class WalletsTransactionsModule {} |
@ -0,0 +1,9 @@ |
||||
import { WalletsTransactions } from './entities/wallets-transaction.entity'; |
||||
import { WALLET_TRANSACTIONS_REPOSITORY } from '../../core/constants'; |
||||
|
||||
export const walletsTransactionsProviders = [ |
||||
{ |
||||
provide: WALLET_TRANSACTIONS_REPOSITORY, |
||||
useValue: WalletsTransactions, |
||||
}, |
||||
]; |
@ -0,0 +1,31 @@ |
||||
import { Inject, Injectable } from '@nestjs/common'; |
||||
import { CreateWalletsTransactionDto } from './dto/create-wallets-transaction.dto'; |
||||
import { WALLET_TRANSACTIONS_REPOSITORY } from 'src/core/constants'; |
||||
import { WalletsTransactions } from './entities/wallets-transaction.entity'; |
||||
|
||||
@Injectable() |
||||
export class WalletsTransactionsService { |
||||
constructor( |
||||
@Inject(WALLET_TRANSACTIONS_REPOSITORY) |
||||
private readonly walletsTransactionsRepository: typeof WalletsTransactions, |
||||
) {} |
||||
async create(createWalletsTransactionDto: CreateWalletsTransactionDto) { |
||||
return await this.walletsTransactionsRepository.create( |
||||
createWalletsTransactionDto, |
||||
); |
||||
} |
||||
|
||||
async findAll() { |
||||
return await this.walletsTransactionsRepository.findAll(); |
||||
} |
||||
|
||||
async findOne(id: number) { |
||||
return await this.walletsTransactionsRepository.findAll({ where: { id } }); |
||||
} |
||||
|
||||
async findByUser(id: number) { |
||||
return await this.walletsTransactionsRepository.findAll({ |
||||
where: { userId: id }, |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue