185 lines
4.2 KiB
TypeScript
185 lines
4.2 KiB
TypeScript
import { Body, Controller, Get, HttpStatus, Param, ParseUUIDPipe, Post, Put, Query, Request } from '@nestjs/common';
|
|
import { TransactionService } from './transaction.service';
|
|
import { DistributeTransactionDto } from './dto/distribute-transaction.dto';
|
|
import { OrderTransactionDto } from './dto/order-transaction.dto';
|
|
import { AddSaldoSupplier } from './dto/add-saldo-supplier.dto';
|
|
import { DepositReturnDto } from './dto/deposit_return.dto';
|
|
|
|
@Controller({
|
|
path: 'transaction',
|
|
version: '1',
|
|
})
|
|
export class TransactionController {
|
|
constructor(private readonly transactionService: TransactionService) {}
|
|
|
|
@Post('distribute')
|
|
async create(
|
|
@Body() createTransactionDto: DistributeTransactionDto,
|
|
@Request() req,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.distributeDeposit(
|
|
createTransactionDto,
|
|
req.user,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Post('distribute-admin')
|
|
async distributeAdmin(
|
|
@Body() createTransactionDto: DistributeTransactionDto,
|
|
@Request() req,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.distributeFromAdmin(
|
|
createTransactionDto,
|
|
req.user,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Post('add-saldo-supplier')
|
|
async addSaldoSupplier(
|
|
@Body() addSaldoSupplier: AddSaldoSupplier,
|
|
@Request() req,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.addPartnerSaldo(
|
|
addSaldoSupplier,
|
|
req.user,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Post('order')
|
|
async orderTransaction(
|
|
@Body() orderTransactionDto: OrderTransactionDto,
|
|
@Request() req,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.orderTransaction(
|
|
orderTransactionDto,
|
|
req.user,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Post('deposit-return')
|
|
async depositReturn(
|
|
@Body() depositReturnDto: DepositReturnDto,
|
|
@Request() req,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.createDepositReturn(
|
|
req.user,
|
|
depositReturnDto,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('history')
|
|
async findByCategories(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
@Request() req,
|
|
) {
|
|
const data = await this.transactionService.transactionHistoryByUser(
|
|
page,
|
|
req.user.userId,
|
|
pageSize,
|
|
);
|
|
|
|
return {
|
|
...data,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('deposit-return')
|
|
async findDepositReturn(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
@Request() req,
|
|
) {
|
|
const [data, count] =
|
|
await this.transactionService.getAllDepositReturnFromUser(
|
|
req.user.userId,
|
|
page,
|
|
pageSize,
|
|
);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get('deposit-return/confirmation')
|
|
async findDepositReturnConfirmation(
|
|
@Query('page') page: number,
|
|
@Query('pageSize') pageSize: number,
|
|
@Request() req,
|
|
) {
|
|
const [data, count] =
|
|
await this.transactionService.getAllDepositReturnToUser(
|
|
req.user.userId,
|
|
page,
|
|
pageSize,
|
|
);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Put('deposit-return/confirmation/:id')
|
|
async confirmDepositReturn(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Request() req,
|
|
@Body() status: string,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.confirmationDepositReturn(
|
|
id,
|
|
req.user,
|
|
status,
|
|
),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Put('deposit-return/confirmation-admin/:id')
|
|
async confirmDepositReturnAdmin(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Request() req,
|
|
@Body() status: string,
|
|
) {
|
|
return {
|
|
data: await this.transactionService.confirmationAdminDepositReturn(
|
|
id,
|
|
req.user,
|
|
status,
|
|
),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
}
|