feat: implement bank accounts, branches, and banks modules with CRUD operations
- Added BankAccountsController, BankAccountsService, and related DTOs for managing bank accounts. - Implemented BankBranchesController, BankBranchesService, and related DTOs for managing bank branches. - Created BanksController and BanksService for retrieving bank information. - Integrated Prisma for database operations across all modules. - Added response mapping for consistent API responses.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { BankAccountsService } from './bank-accounts.service'
|
||||
import { CreateBankAccountDto } from './dto/create-bank-account.dto'
|
||||
import { UpdateBankAccountDto } from './dto/update-bank-account.dto'
|
||||
|
||||
@Controller('bank-accounts')
|
||||
export class BankAccountsController {
|
||||
constructor(private readonly bankAccountsService: BankAccountsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreateBankAccountDto) {
|
||||
return this.bankAccountsService.create(dto)
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bankAccountsService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.bankAccountsService.findOne(Number(id))
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateBankAccountDto) {
|
||||
return this.bankAccountsService.update(Number(id), dto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.bankAccountsService.remove(Number(id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PrismaModule } from '../../prisma/prisma.module'
|
||||
import { BankAccountsController } from './bank-accounts.controller'
|
||||
import { BankAccountsService } from './bank-accounts.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [BankAccountsController],
|
||||
providers: [BankAccountsService],
|
||||
})
|
||||
export class BankAccountsModule {}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../../common/response/response-mapper'
|
||||
import { PrismaService } from '../../prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class BankAccountsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
async create(data: any) {
|
||||
const item = await this.prisma.bankAccount.create({ data })
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const items = await this.prisma.bankAccount.findMany({
|
||||
include: {
|
||||
branch: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
code: true,
|
||||
bank: {
|
||||
select: { id: true, name: true, shortName: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
omit: {
|
||||
branchId: true,
|
||||
},
|
||||
})
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const item = await this.prisma.bankAccount.findUnique({ where: { id } })
|
||||
if (!item) return null
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
async update(id: number, data: any) {
|
||||
const item = await this.prisma.bankAccount.update({ where: { id }, data })
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const item = await this.prisma.bankAccount.delete({ where: { id } })
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { IsInt, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreateBankAccountDto {
|
||||
@IsString()
|
||||
accountNumber: string
|
||||
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
iban: string
|
||||
|
||||
@IsInt()
|
||||
branchId: number
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
createdAt?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
updatedAt?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
deletedAt?: string
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/swagger'
|
||||
import { CreateBankAccountDto } from './create-bank-account.dto'
|
||||
|
||||
export class UpdateBankAccountDto extends PartialType(CreateBankAccountDto) {}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { BankBranchesService } from './bank-branches.service'
|
||||
import { CreateBankBranchDto } from './dto/create-bank-branches.dto'
|
||||
import { UpdateBankBranchDto } from './dto/update-bank-branches.dto'
|
||||
|
||||
@Controller('bank-branches')
|
||||
export class BankBranchesController {
|
||||
constructor(private readonly bankBranchesService: BankBranchesService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreateBankBranchDto) {
|
||||
return this.bankBranchesService.create(dto)
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.bankBranchesService.findAll()
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.bankBranchesService.findOne(Number(id))
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateBankBranchDto) {
|
||||
return this.bankBranchesService.update(Number(id), dto)
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.bankBranchesService.remove(Number(id))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PrismaModule } from '../../prisma/prisma.module'
|
||||
import { BankBranchesController } from './bank-branches.controller'
|
||||
import { BankBranchesService } from './bank-branches.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [BankBranchesController],
|
||||
providers: [BankBranchesService],
|
||||
})
|
||||
export class BankBranchesModule {}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../../common/response/response-mapper'
|
||||
import { PrismaService } from '../../prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class BankBranchesService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
async create(data: any) {
|
||||
const item = await this.prisma.bankBranch.create({ data })
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
const items = await this.prisma.bankBranch.findMany({
|
||||
include: {
|
||||
bank: {
|
||||
select: { id: true, name: true, shortName: true },
|
||||
},
|
||||
},
|
||||
})
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
const item = await this.prisma.bankBranch.findUnique({ where: { id } })
|
||||
if (!item) return null
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
async update(id: number, data: any) {
|
||||
const item = await this.prisma.bankBranch.update({ where: { id }, data })
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const item = await this.prisma.bankBranch.delete({ where: { id } })
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { IsInt, IsString } from 'class-validator'
|
||||
|
||||
export class CreateBankBranchDto {
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsString()
|
||||
code: string
|
||||
|
||||
@IsInt()
|
||||
bankId: number
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class UpdateBankBranchDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
imageUrl?: string
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common'
|
||||
import { BanksService } from './banks.service'
|
||||
|
||||
@Controller('banks')
|
||||
export class BanksController {
|
||||
constructor(private readonly banksService: BanksService) {}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.banksService.findAll()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { PrismaModule } from '../../prisma/prisma.module'
|
||||
import { BanksController } from './banks.controller'
|
||||
import { BanksService } from './banks.service'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule],
|
||||
controllers: [BanksController],
|
||||
providers: [BanksService],
|
||||
})
|
||||
export class BanksModule {}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from '../../common/response/response-mapper'
|
||||
import { PrismaService } from '../../prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class BanksService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
const items = await this.prisma.bank.findMany({
|
||||
select: { id: true, name: true, shortName: true },
|
||||
})
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import dayjs from 'dayjs'
|
||||
import { ResponseMapper } from '../../common/response/response-mapper'
|
||||
import { Prisma } from '../../generated/prisma/client'
|
||||
import { PrismaService } from '../../prisma/prisma.service'
|
||||
import { ReadCardexDto } from './dto/read-pos.dto'
|
||||
import { ReadCardexDto } from './dto/read-cardex.dto'
|
||||
|
||||
@Injectable()
|
||||
export class CardexService {
|
||||
|
||||
@@ -29,47 +29,4 @@ export class PosController {
|
||||
|
||||
return this.posService.createOrder(dto, inventoryId!)
|
||||
}
|
||||
|
||||
// @Post()
|
||||
// create(@Body() dto: CreateInventoryDto) {
|
||||
// return this.inventoriesService.create(dto)
|
||||
// }
|
||||
|
||||
// @Get()
|
||||
// @ApiQuery({ name: 'isPointOfSale', required: false, type: Boolean })
|
||||
// findAll(@Query('isPointOfSale') isPointOfSale?: boolean) {
|
||||
// return this.inventoriesService.findAll(isPointOfSale)
|
||||
// }
|
||||
|
||||
// @Get(':id')
|
||||
// findOne(@Param('id') id: string) {
|
||||
// return this.inventoriesService.findOne(Number(id))
|
||||
// }
|
||||
|
||||
// @Patch(':id')
|
||||
// update(@Param('id') id: string, @Body() dto: UpdateInventoryDto) {
|
||||
// return this.inventoriesService.update(Number(id), dto)
|
||||
// }
|
||||
|
||||
// @Delete(':id')
|
||||
// remove(@Param('id') id: string) {
|
||||
// return this.inventoriesService.remove(Number(id))
|
||||
// }
|
||||
|
||||
// @Get(':id/movements')
|
||||
// @ApiQuery({ name: 'type', required: false, enum: MovementType })
|
||||
// findInventoryMovements(@Param('id') id: string, @Query('type') type?: MovementType) {
|
||||
// return this.inventoriesService.findInventoryMovements(Number(id), type ?? undefined)
|
||||
// }
|
||||
|
||||
// @Get(':id/stock')
|
||||
// @ApiQuery({ name: 'isAvailable', required: false, type: Boolean })
|
||||
// getStock(@Param('id') id: string, @Query('isAvailable') isAvailable?: boolean) {
|
||||
// return this.inventoriesService.getStock(Number(id), isAvailable ?? undefined)
|
||||
// }
|
||||
|
||||
// @Get(':id/products/:productId/cardex')
|
||||
// getProductCardex(@Param('id') id: string, @Param('productId') productId: string) {
|
||||
// return this.inventoriesService.getProductCardex(Number(id), Number(productId))
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user