fix: add user detail on create member
This commit is contained in:
parent
8c5e944cc8
commit
dcad18339b
|
@ -1,10 +1,17 @@
|
||||||
import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator';
|
import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator';
|
||||||
import { Partner } from '../entities/partner.entity';
|
import { Partner } from '../entities/partner.entity';
|
||||||
|
import { Column } from 'typeorm';
|
||||||
|
|
||||||
export class CreateUserDto {
|
export class CreateUserDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
phone_number: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
import { Roles } from 'src/configurable/entities/roles.entity';
|
import { Roles } from 'src/configurable/entities/roles.entity';
|
||||||
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
ManyToOne,
|
||||||
|
OneToOne,
|
||||||
|
} from 'typeorm';
|
||||||
import { BaseModel } from '../../config/basemodel.entity';
|
import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { hashPassword } from '../../helper/hash_password';
|
import { hashPassword } from '../../helper/hash_password';
|
||||||
import { Partner } from './partner.entity';
|
import { Partner } from './partner.entity';
|
||||||
|
import { UserDetail } from './user_detail.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User extends BaseModel {
|
export class User extends BaseModel {
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
import {
|
||||||
|
Entity,
|
||||||
|
Column,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
OneToOne,
|
||||||
|
ManyToOne,
|
||||||
|
JoinColumn,
|
||||||
|
} from 'typeorm';
|
||||||
import { accountType } from '../../helper/enum-list';
|
import { accountType } from '../../helper/enum-list';
|
||||||
|
import { User } from './user.entity';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class UserDetail {
|
export class UserDetail {
|
||||||
|
@ -9,14 +17,10 @@ export class UserDetail {
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column()
|
|
||||||
first_name: string;
|
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
|
|
||||||
@Column({
|
@OneToOne(() => User)
|
||||||
nullable: true,
|
@JoinColumn()
|
||||||
})
|
user: User;
|
||||||
type: accountType;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,11 @@ import { SupplierService } from './supplier/supplier.service';
|
||||||
import { Supplier } from './entities/supplier.entity';
|
import { Supplier } from './entities/supplier.entity';
|
||||||
import { Partner } from './entities/partner.entity';
|
import { Partner } from './entities/partner.entity';
|
||||||
import { PartnerService } from './partner/partner.service';
|
import { PartnerService } from './partner/partner.service';
|
||||||
|
import { UserDetail } from './entities/user_detail.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([User, Supplier, Partner]),
|
TypeOrmModule.forFeature([User, Supplier, Partner, UserDetail]),
|
||||||
forwardRef(() => TransactionModule),
|
forwardRef(() => TransactionModule),
|
||||||
ConfigurableModule,
|
ConfigurableModule,
|
||||||
],
|
],
|
||||||
|
|
|
@ -23,6 +23,7 @@ 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';
|
import * as uuid from 'uuid';
|
||||||
|
import { UserDetail } from './entities/user_detail.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
|
@ -76,6 +77,12 @@ export class UsersService {
|
||||||
await this.connection.transaction(async (manager) => {
|
await this.connection.transaction(async (manager) => {
|
||||||
const result = await manager.insert(User, userData);
|
const result = await manager.insert(User, userData);
|
||||||
|
|
||||||
|
const userDetailData = new UserDetail();
|
||||||
|
userDetailData.name = createUserDto.name;
|
||||||
|
userDetailData.phone_number = createUserDto.phone_number;
|
||||||
|
userDetailData.user = userData;
|
||||||
|
const user_detail = await manager.insert(UserDetail, userDetailData);
|
||||||
|
|
||||||
const dataCoaWallet = new InputCoaDto();
|
const dataCoaWallet = new InputCoaDto();
|
||||||
dataCoaWallet.user = userData;
|
dataCoaWallet.user = userData;
|
||||||
dataCoaWallet.balanceType = balanceType.CREDIT;
|
dataCoaWallet.balanceType = balanceType.CREDIT;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user