fix user input
This commit is contained in:
parent
d030624765
commit
84fda27e2d
|
@ -15,23 +15,19 @@ export class CoaService {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(inputCoaDto: InputCoaDto) {
|
async create(inputCoaDto: InputCoaDto) {
|
||||||
const user = await this.userService.findExist(inputCoaDto.userId)
|
const user = inputCoaDto.user
|
||||||
console.log(coaType[inputCoaDto.type])
|
let coaData = new COA();
|
||||||
console.log(inputCoaDto.type)
|
coaData.user = user.id;
|
||||||
const result = await this.coaRepository.insert({
|
coaData.name = coaType[inputCoaDto.type] + '-' + user.username;
|
||||||
user:user.id,
|
coaData.balanceType = inputCoaDto.balanceType;
|
||||||
name: coaType[inputCoaDto.type] + '-' + user.username,
|
coaData.type = inputCoaDto.type;
|
||||||
balanceType:inputCoaDto.balanceType,
|
coaData.amount = 0;
|
||||||
type:inputCoaDto.type,
|
|
||||||
amount:0
|
const result = await inputCoaDto.coaEntityManager.insert(COA,coaData);
|
||||||
});
|
|
||||||
|
|
||||||
const coaData = await this.coaRepository.findOneOrFail(
|
|
||||||
result.identifiers[0].id,
|
|
||||||
);
|
|
||||||
if(inputCoaDto.type == coaType.ACCOUNT_RECEIVABLE || inputCoaDto.type == coaType.ACCOUNT_PAYABLE){
|
if(inputCoaDto.type == coaType.ACCOUNT_RECEIVABLE || inputCoaDto.type == coaType.ACCOUNT_PAYABLE){
|
||||||
coaData.relatedUser = inputCoaDto.relatedUserId;
|
coaData.relatedUser = inputCoaDto.relatedUserId;
|
||||||
await this.coaRepository.save(coaData)
|
await inputCoaDto.coaEntityManager.save(coaData)
|
||||||
}
|
}
|
||||||
|
|
||||||
return coaData;
|
return coaData;
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||||
import { balanceType, coaType } from 'src/helper/enum-list';
|
import { balanceType, coaType } from 'src/helper/enum-list';
|
||||||
|
import { User } from 'src/users/entities/user.entity';
|
||||||
|
import { EntityManager } from 'typeorm';
|
||||||
|
|
||||||
export class InputCoaDto {
|
export class InputCoaDto {
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
userId: string;
|
user: User;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
type: coaType;
|
type: coaType;
|
||||||
|
@ -13,4 +15,7 @@ export class InputCoaDto {
|
||||||
|
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
relatedUserId: string;
|
relatedUserId: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
coaEntityManager: EntityManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { Connection, EntityNotFoundError, Repository } from 'typeorm';
|
||||||
import { User } from './entities/user.entity';
|
import { User } from './entities/user.entity';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
||||||
|
@ -10,6 +10,7 @@ import { CoaService } from 'src/transaction/coa.service';
|
||||||
import { balanceType, coaType } from 'src/helper/enum-list';
|
import { balanceType, coaType } from 'src/helper/enum-list';
|
||||||
import { RoleService } from 'src/configurable/roles.service';
|
import { RoleService } from 'src/configurable/roles.service';
|
||||||
import { InputCoaDto } from 'src/transaction/dto/input-coa.dto';
|
import { InputCoaDto } from 'src/transaction/dto/input-coa.dto';
|
||||||
|
import * as uuid from "uuid";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
@ -18,47 +19,56 @@ export class UsersService {
|
||||||
private usersRepository: Repository<User>,
|
private usersRepository: Repository<User>,
|
||||||
@Inject(forwardRef(() => CoaService))
|
@Inject(forwardRef(() => CoaService))
|
||||||
private coaService: CoaService,
|
private coaService: CoaService,
|
||||||
private roleService: RoleService
|
private roleService: RoleService,
|
||||||
|
private connection: Connection,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(createUserDto: CreateUserDto, currentUser: any) {
|
async create(createUserDto: CreateUserDto, currentUser: any) {
|
||||||
const roles = await this.roleService.findOne(createUserDto.roleId);
|
const roles = await this.roleService.findOne(createUserDto.roleId);
|
||||||
const superior = await this.findByUsername(currentUser.username);
|
const superior = await this.findByUsername(currentUser.username);
|
||||||
|
|
||||||
const salt = randomStringGenerator();
|
const salt = randomStringGenerator();
|
||||||
const result = await this.usersRepository.insert({
|
|
||||||
username: createUserDto.username,
|
let userData = new User();
|
||||||
password: await hashPassword(createUserDto.password, salt),
|
userData.id = uuid.v4();
|
||||||
salt,
|
userData.username = createUserDto.username,
|
||||||
superior:superior,
|
userData.password = await hashPassword(createUserDto.password, salt),
|
||||||
roles:roles
|
userData.salt = salt,
|
||||||
});
|
userData.superior = superior,
|
||||||
|
userData.roles = roles
|
||||||
|
|
||||||
let dataCoaWallet = new InputCoaDto();
|
await this.connection.transaction(async (manager) => {
|
||||||
dataCoaWallet.userId = result.identifiers[0].id;
|
const result = await manager.insert(User,userData);
|
||||||
dataCoaWallet.balanceType = balanceType.CREDIT;
|
|
||||||
dataCoaWallet.type = coaType.WALLET;
|
let dataCoaWallet = new InputCoaDto();
|
||||||
|
dataCoaWallet.user = userData;
|
||||||
|
dataCoaWallet.balanceType = balanceType.CREDIT;
|
||||||
|
dataCoaWallet.type = coaType.WALLET;
|
||||||
|
dataCoaWallet.coaEntityManager = manager;
|
||||||
|
|
||||||
|
if(createUserDto.superior){
|
||||||
|
let dataCoaAP = new InputCoaDto();
|
||||||
|
dataCoaAP.user = userData;
|
||||||
|
dataCoaAP.balanceType = balanceType.CREDIT;
|
||||||
|
dataCoaAP.relatedUserId = superior.id;
|
||||||
|
dataCoaAP.type = coaType.ACCOUNT_PAYABLE;
|
||||||
|
dataCoaAP.coaEntityManager = manager;
|
||||||
|
|
||||||
|
let dataCoaAR = new InputCoaDto();
|
||||||
|
dataCoaAR.user = userData;
|
||||||
|
dataCoaAR.balanceType = balanceType.DEBIT;
|
||||||
|
dataCoaAR.relatedUserId = superior.id;
|
||||||
|
dataCoaAR.type = coaType.ACCOUNT_RECEIVABLE;
|
||||||
|
dataCoaAR.coaEntityManager = manager;
|
||||||
|
|
||||||
|
await this.coaService.create(dataCoaAP);
|
||||||
|
await this.coaService.create(dataCoaAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.coaService.create(dataCoaWallet);
|
||||||
|
|
||||||
if(createUserDto.superior){
|
})
|
||||||
let dataCoaAP = new InputCoaDto();
|
|
||||||
dataCoaAP.userId = result.identifiers[0].id;
|
|
||||||
dataCoaAP.balanceType = balanceType.CREDIT;
|
|
||||||
dataCoaAP.relatedUserId = superior.id;
|
|
||||||
dataCoaAP.type = coaType.ACCOUNT_PAYABLE;
|
|
||||||
|
|
||||||
let dataCoaAR = new InputCoaDto();
|
return userData;
|
||||||
dataCoaAR.userId = result.identifiers[0].id;
|
|
||||||
dataCoaAR.balanceType = balanceType.DEBIT;
|
|
||||||
dataCoaAR.relatedUserId = superior.id;
|
|
||||||
dataCoaAR.type = coaType.ACCOUNT_RECEIVABLE;
|
|
||||||
|
|
||||||
await this.coaService.create(dataCoaAP);
|
|
||||||
await this.coaService.create(dataCoaAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.coaService.create(dataCoaWallet);
|
|
||||||
|
|
||||||
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll(page:number) {
|
findAll(page:number) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user