journaling
This commit is contained in:
@@ -1,15 +1,34 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { COA } from './entities/coa.entity';
|
||||
import { coaType } from '../helper/enum-list';
|
||||
import { InputCoaDto } from './dto/input-coa.dto';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
|
||||
export class CoaService {
|
||||
constructor(
|
||||
@InjectRepository(COA)
|
||||
private coaRepository: Repository<COA>,
|
||||
@Inject(forwardRef(() => UsersService))
|
||||
private userService: UsersService,
|
||||
) {}
|
||||
|
||||
async create(inputCoaDto: InputCoaDto) {
|
||||
const user = await this.userService.findExist(inputCoaDto.userId)
|
||||
|
||||
const result = await this.coaRepository.insert({
|
||||
user:user.id,
|
||||
name: inputCoaDto.balanceType + '-' + user.username,
|
||||
balanceType:inputCoaDto.balanceType,
|
||||
type:inputCoaDto.type
|
||||
});
|
||||
|
||||
return this.coaRepository.findOneOrFail(
|
||||
result.identifiers[0].id,
|
||||
);
|
||||
}
|
||||
|
||||
async findByUser(id: string, typeOfCoa: coaType) {
|
||||
try {
|
||||
return await this.coaRepository.findOneOrFail({ user: id, type: typeOfCoa });
|
||||
|
||||
Reference in New Issue
Block a user