fix create membership
This commit is contained in:
		| @@ -2,7 +2,7 @@ import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nest | ||||
| import { EntityNotFoundError, Repository } from 'typeorm'; | ||||
| import { InjectRepository } from '@nestjs/typeorm'; | ||||
| import { COA } from './entities/coa.entity'; | ||||
| import { coaType } from '../helper/enum-list'; | ||||
| import { balanceType, coaType } from '../helper/enum-list'; | ||||
| import { InputCoaDto } from './dto/input-coa.dto'; | ||||
| import { UsersService } from 'src/users/users.service'; | ||||
|  | ||||
| @@ -16,17 +16,25 @@ export class CoaService { | ||||
|  | ||||
|   async create(inputCoaDto: InputCoaDto) { | ||||
|     const user = await this.userService.findExist(inputCoaDto.userId) | ||||
|  | ||||
|     console.log(coaType[inputCoaDto.type]) | ||||
|     console.log(inputCoaDto.type) | ||||
|     const result = await this.coaRepository.insert({ | ||||
|       user:user.id, | ||||
|       name: inputCoaDto.balanceType + '-' + user.username, | ||||
|       name: coaType[inputCoaDto.type] + '-' + user.username, | ||||
|       balanceType:inputCoaDto.balanceType, | ||||
|       type:inputCoaDto.type | ||||
|       type:inputCoaDto.type, | ||||
|       amount:0 | ||||
|     }); | ||||
|  | ||||
|     return this.coaRepository.findOneOrFail( | ||||
|     const coaData = await this.coaRepository.findOneOrFail( | ||||
|       result.identifiers[0].id, | ||||
|     ); | ||||
|     if(inputCoaDto.type == coaType.ACCOUNT_RECEIVABLE || inputCoaDto.type == coaType.ACCOUNT_PAYABLE){ | ||||
|       coaData.relatedUser = inputCoaDto.relatedUserId; | ||||
|       await this.coaRepository.save(coaData) | ||||
|     } | ||||
|  | ||||
|     return coaData; | ||||
|   } | ||||
|  | ||||
|   async findByUser(id: string, typeOfCoa: coaType) { | ||||
|   | ||||
| @@ -10,4 +10,7 @@ export class InputCoaDto { | ||||
|  | ||||
|   @IsNotEmpty() | ||||
|   balanceType: balanceType; | ||||
|  | ||||
|   @IsUUID() | ||||
|   relatedUserId: string; | ||||
| } | ||||
|   | ||||
| @@ -1,15 +0,0 @@ | ||||
| import { | ||||
|   Entity, | ||||
|   Column, | ||||
| } from 'typeorm'; | ||||
| import { BaseModel } from '../../config/basemodel.entity'; | ||||
| import { balanceType } from '../../helper/enum-list'; | ||||
|  | ||||
| @Entity() | ||||
| export class CoaType extends BaseModel { | ||||
|   @Column() | ||||
|   name: string; | ||||
|  | ||||
|   @Column('text') | ||||
|   normalBalance: balanceType; | ||||
| } | ||||
| @@ -21,4 +21,9 @@ export class COA extends BaseModel { | ||||
|  | ||||
|   @Column() | ||||
|   user: string; | ||||
|  | ||||
|   @Column({ | ||||
|     nullable:true | ||||
|   }) | ||||
|   relatedUser: string; | ||||
| } | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import { TransactionController } from './transaction.controller'; | ||||
| import { PpobCallbackController } from './ppob_callback.controller'; | ||||
| import { TypeOrmModule } from '@nestjs/typeorm'; | ||||
| import { COA } from './entities/coa.entity'; | ||||
| import { CoaType } from './entities/coa-type.entity'; | ||||
| import { TransactionType } from './entities/transaction-type.entity'; | ||||
| import { TransactionJournal } from './entities/transaction-journal.entity'; | ||||
| import { Transactions } from './entities/transactions.entity'; | ||||
| @@ -15,7 +14,6 @@ import { UsersModule } from 'src/users/users.module'; | ||||
| @Module({ | ||||
|   imports: [ | ||||
|     TypeOrmModule.forFeature([ | ||||
|       CoaType, | ||||
|       TransactionType, | ||||
|       COA, | ||||
|       TransactionJournal, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user