fix create membership
This commit is contained in:
parent
d65af44a52
commit
d030624765
|
@ -7,6 +7,8 @@ export enum statusTransaction {
|
||||||
export enum typeTransaction {
|
export enum typeTransaction {
|
||||||
DISTRIBUTION,
|
DISTRIBUTION,
|
||||||
ORDER,
|
ORDER,
|
||||||
|
DEPOSIT_IRS,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum productType {
|
export enum productType {
|
||||||
|
|
|
@ -25,7 +25,10 @@ export class ProductHistoryPrice extends BaseModel {
|
||||||
@Column({ type: 'date' })
|
@Column({ type: 'date' })
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
|
|
||||||
@Column({ type: 'date' })
|
@Column({
|
||||||
|
type: 'date',
|
||||||
|
nullable:true
|
||||||
|
})
|
||||||
endDate: Date;
|
endDate: Date;
|
||||||
|
|
||||||
@Column('text')
|
@Column('text')
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nest
|
||||||
import { EntityNotFoundError, Repository } from 'typeorm';
|
import { EntityNotFoundError, Repository } from 'typeorm';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { COA } from './entities/coa.entity';
|
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 { InputCoaDto } from './dto/input-coa.dto';
|
||||||
import { UsersService } from 'src/users/users.service';
|
import { UsersService } from 'src/users/users.service';
|
||||||
|
|
||||||
|
@ -16,17 +16,25 @@ export class CoaService {
|
||||||
|
|
||||||
async create(inputCoaDto: InputCoaDto) {
|
async create(inputCoaDto: InputCoaDto) {
|
||||||
const user = await this.userService.findExist(inputCoaDto.userId)
|
const user = await this.userService.findExist(inputCoaDto.userId)
|
||||||
|
console.log(coaType[inputCoaDto.type])
|
||||||
|
console.log(inputCoaDto.type)
|
||||||
const result = await this.coaRepository.insert({
|
const result = await this.coaRepository.insert({
|
||||||
user:user.id,
|
user:user.id,
|
||||||
name: inputCoaDto.balanceType + '-' + user.username,
|
name: coaType[inputCoaDto.type] + '-' + user.username,
|
||||||
balanceType:inputCoaDto.balanceType,
|
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,
|
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) {
|
async findByUser(id: string, typeOfCoa: coaType) {
|
||||||
|
|
|
@ -10,4 +10,7 @@ export class InputCoaDto {
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
balanceType: balanceType;
|
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()
|
@Column()
|
||||||
user: string;
|
user: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable:true
|
||||||
|
})
|
||||||
|
relatedUser: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { TransactionController } from './transaction.controller';
|
||||||
import { PpobCallbackController } from './ppob_callback.controller';
|
import { PpobCallbackController } from './ppob_callback.controller';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { COA } from './entities/coa.entity';
|
import { COA } from './entities/coa.entity';
|
||||||
import { CoaType } from './entities/coa-type.entity';
|
|
||||||
import { TransactionType } from './entities/transaction-type.entity';
|
import { TransactionType } from './entities/transaction-type.entity';
|
||||||
import { TransactionJournal } from './entities/transaction-journal.entity';
|
import { TransactionJournal } from './entities/transaction-journal.entity';
|
||||||
import { Transactions } from './entities/transactions.entity';
|
import { Transactions } from './entities/transactions.entity';
|
||||||
|
@ -15,7 +14,6 @@ import { UsersModule } from 'src/users/users.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([
|
TypeOrmModule.forFeature([
|
||||||
CoaType,
|
|
||||||
TransactionType,
|
TransactionType,
|
||||||
COA,
|
COA,
|
||||||
TransactionJournal,
|
TransactionJournal,
|
||||||
|
|
|
@ -10,9 +10,12 @@ export class CreateUserDto {
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
roleId: string;
|
roleId: string;
|
||||||
|
|
||||||
@ValidateIf((o) => {
|
@IsNotEmpty()
|
||||||
return !!o.superior;
|
superior: boolean;
|
||||||
})
|
|
||||||
@IsUUID()
|
// @ValidateIf((o) => {
|
||||||
superior: string;
|
// return !!o.superior;
|
||||||
|
// })
|
||||||
|
// @IsUUID()
|
||||||
|
// superior: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
ParseUUIDPipe,
|
ParseUUIDPipe,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Query,
|
Query,
|
||||||
|
Request
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
|
@ -23,11 +24,12 @@ export class UsersController {
|
||||||
constructor(private readonly usersService: UsersService) {}
|
constructor(private readonly usersService: UsersService) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
async create(@Body() createUserDto: CreateUserDto) {
|
async create(
|
||||||
|
@Request() req,
|
||||||
|
@Body() createUserDto: CreateUserDto
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
data: await this.usersService.create(createUserDto),
|
data: await this.usersService.create(createUserDto,req.user),
|
||||||
statusCode: HttpStatus.CREATED,
|
statusCode: HttpStatus.CREATED,
|
||||||
message: 'success',
|
message: 'success',
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,9 +21,9 @@ export class UsersService {
|
||||||
private roleService: RoleService
|
private roleService: RoleService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(createUserDto: CreateUserDto) {
|
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.findExist(createUserDto.superior);
|
const superior = await this.findByUsername(currentUser.username);
|
||||||
|
|
||||||
const salt = randomStringGenerator();
|
const salt = randomStringGenerator();
|
||||||
const result = await this.usersRepository.insert({
|
const result = await this.usersRepository.insert({
|
||||||
|
@ -39,19 +39,24 @@ export class UsersService {
|
||||||
dataCoaWallet.balanceType = balanceType.CREDIT;
|
dataCoaWallet.balanceType = balanceType.CREDIT;
|
||||||
dataCoaWallet.type = coaType.WALLET;
|
dataCoaWallet.type = coaType.WALLET;
|
||||||
|
|
||||||
|
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();
|
let dataCoaAR = new InputCoaDto();
|
||||||
dataCoaAR.userId = result.identifiers[0].id;
|
dataCoaAR.userId = result.identifiers[0].id;
|
||||||
dataCoaAR.balanceType = balanceType.CREDIT;
|
dataCoaAR.balanceType = balanceType.DEBIT;
|
||||||
|
dataCoaAR.relatedUserId = superior.id;
|
||||||
dataCoaAR.type = coaType.ACCOUNT_RECEIVABLE;
|
dataCoaAR.type = coaType.ACCOUNT_RECEIVABLE;
|
||||||
|
|
||||||
let dataCoaPayable = new InputCoaDto();
|
await this.coaService.create(dataCoaAP);
|
||||||
dataCoaPayable.userId = result.identifiers[0].id;
|
await this.coaService.create(dataCoaAR);
|
||||||
dataCoaPayable.balanceType = balanceType.CREDIT;
|
}
|
||||||
dataCoaPayable.type = coaType.ACCOUNT_PAYABLE;
|
|
||||||
|
|
||||||
await this.coaService.create(dataCoaWallet);
|
await this.coaService.create(dataCoaWallet);
|
||||||
await this.coaService.create(dataCoaAR);
|
|
||||||
await this.coaService.create(dataCoaPayable);
|
|
||||||
|
|
||||||
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
||||||
}
|
}
|
||||||
|
@ -97,6 +102,26 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findByUsername(username: string) {
|
||||||
|
try {
|
||||||
|
return await this.usersRepository.findOneOrFail({
|
||||||
|
username:username
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.NOT_FOUND,
|
||||||
|
error: 'Data not found',
|
||||||
|
},
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
const coa = await this.coaService.findByUser(id,coaType.WALLET);
|
const coa = await this.coaService.findByUser(id,coaType.WALLET);
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user