fix: profile
This commit is contained in:
parent
de7f9c059b
commit
412874a057
|
@ -1,4 +1,10 @@
|
||||||
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 { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
import { Connection, EntityNotFoundError, Not, Repository } from 'typeorm';
|
||||||
|
@ -58,24 +64,29 @@ export class UsersService {
|
||||||
userData.username = createUserDto.username;
|
userData.username = createUserDto.username;
|
||||||
userData.password = await hashPassword(createUserDto.password, salt);
|
userData.password = await hashPassword(createUserDto.password, salt);
|
||||||
userData.salt = salt;
|
userData.salt = salt;
|
||||||
|
|
||||||
if (createUserDto.superior) {
|
if (createUserDto.superior) {
|
||||||
userData.superior = superior;
|
userData.superior = superior;
|
||||||
} else {
|
} else {
|
||||||
userData.superior = null;
|
userData.superior = null;
|
||||||
userData.partner = createUserDto.partner;
|
userData.partner = createUserDto.partner;
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.roles = roles;
|
userData.roles = roles;
|
||||||
|
|
||||||
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();
|
const userDetailData = new UserDetail();
|
||||||
|
|
||||||
userDetailData.name = createUserDto.name;
|
userDetailData.name = createUserDto.name;
|
||||||
userDetailData.phone_number = createUserDto.phone_number;
|
userDetailData.phone_number = createUserDto.phone_number;
|
||||||
userDetailData.user = userData;
|
userDetailData.user = userData;
|
||||||
|
|
||||||
const user_detail = await manager.insert(UserDetail, userDetailData);
|
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;
|
||||||
dataCoaWallet.type = coaType.WALLET;
|
dataCoaWallet.type = coaType.WALLET;
|
||||||
|
@ -83,6 +94,7 @@ export class UsersService {
|
||||||
await this.coaService.create(dataCoaWallet);
|
await this.coaService.create(dataCoaWallet);
|
||||||
|
|
||||||
const dataCoaAR = new InputCoaDto();
|
const dataCoaAR = new InputCoaDto();
|
||||||
|
|
||||||
dataCoaAR.user = userData;
|
dataCoaAR.user = userData;
|
||||||
dataCoaAR.balanceType = balanceType.DEBIT;
|
dataCoaAR.balanceType = balanceType.DEBIT;
|
||||||
dataCoaAR.relatedUserId = superior.id;
|
dataCoaAR.relatedUserId = superior.id;
|
||||||
|
@ -92,6 +104,7 @@ export class UsersService {
|
||||||
|
|
||||||
if (roles.name == 'Supervisor' || roles.name == 'Sales') {
|
if (roles.name == 'Supervisor' || roles.name == 'Sales') {
|
||||||
const dataCOAProfit = new InputCoaDto();
|
const dataCOAProfit = new InputCoaDto();
|
||||||
|
|
||||||
dataCOAProfit.user = userData;
|
dataCOAProfit.user = userData;
|
||||||
dataCOAProfit.balanceType = balanceType.CREDIT;
|
dataCOAProfit.balanceType = balanceType.CREDIT;
|
||||||
dataCOAProfit.type = coaType.PROFIT;
|
dataCOAProfit.type = coaType.PROFIT;
|
||||||
|
@ -101,6 +114,7 @@ export class UsersService {
|
||||||
|
|
||||||
if (createUserDto.superior) {
|
if (createUserDto.superior) {
|
||||||
const dataCoaAP = new InputCoaDto();
|
const dataCoaAP = new InputCoaDto();
|
||||||
|
|
||||||
dataCoaAP.user = userData;
|
dataCoaAP.user = userData;
|
||||||
dataCoaAP.balanceType = balanceType.CREDIT;
|
dataCoaAP.balanceType = balanceType.CREDIT;
|
||||||
dataCoaAP.relatedUserId = superior.id;
|
dataCoaAP.relatedUserId = superior.id;
|
||||||
|
@ -180,28 +194,37 @@ export class UsersService {
|
||||||
superior: id,
|
superior: id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const listId = baseQuery.map((x) => x.id);
|
const listId = baseQuery.map((x) => {
|
||||||
|
return x.id;
|
||||||
|
});
|
||||||
|
|
||||||
listUser = listUser.concat(listId);
|
listUser = listUser.concat(listId);
|
||||||
listToFind = listId;
|
listToFind = listId;
|
||||||
|
|
||||||
if (role == 1) {
|
if (role == 1) {
|
||||||
return listUser;
|
return listUser;
|
||||||
} else {
|
}
|
||||||
for (let it = 2; it <= role; it++) {
|
|
||||||
let newListToFind = [];
|
for (let it = 2; it <= role; it++) {
|
||||||
await mapSeries(listToFind, async (ltf) => {
|
let newListToFind = [];
|
||||||
const getListUser = await this.usersRepository.find({
|
|
||||||
where: {
|
await mapSeries(listToFind, async (ltf) => {
|
||||||
superior: ltf,
|
const getListUser = await this.usersRepository.find({
|
||||||
},
|
where: {
|
||||||
});
|
superior: ltf,
|
||||||
if (getListUser.length > 0) {
|
},
|
||||||
const listId = getListUser.map((x) => x.id);
|
|
||||||
newListToFind = newListToFind.concat(listId);
|
|
||||||
listUser = listUser.concat(listId);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
listToFind = newListToFind;
|
|
||||||
}
|
if (getListUser.length > 0) {
|
||||||
|
const listId = getListUser.map((x) => {
|
||||||
|
return x.id;
|
||||||
|
});
|
||||||
|
|
||||||
|
newListToFind = newListToFind.concat(listId);
|
||||||
|
listUser = listUser.concat(listId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
listToFind = newListToFind;
|
||||||
}
|
}
|
||||||
|
|
||||||
return listUser;
|
return listUser;
|
||||||
|
@ -335,10 +358,13 @@ export class UsersService {
|
||||||
.getOne();
|
.getOne();
|
||||||
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
const coa = await this.coaService.findByUser(id, coaType.WALLET);
|
||||||
let coaProfit;
|
let coaProfit;
|
||||||
if(userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209'){
|
|
||||||
coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
userData.roles.id != 'e4dfb6a3-2338-464a-8fb8-5cbc089d4209' &&
|
||||||
|
userData.roles.id != '21dceea2-416e-4b55-b74c-12605e1f8d1b'
|
||||||
|
) {
|
||||||
|
coaProfit = await this.coaService.findByUser(id, coaType.PROFIT);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...userData,
|
...userData,
|
||||||
|
@ -416,11 +442,14 @@ export class UsersService {
|
||||||
async updatePassword(id: string, updateUserDto: UpdateUserDto) {
|
async updatePassword(id: string, updateUserDto: UpdateUserDto) {
|
||||||
try {
|
try {
|
||||||
const dataUser = await this.usersRepository.findOneOrFail(id);
|
const dataUser = await this.usersRepository.findOneOrFail(id);
|
||||||
|
|
||||||
dataUser.password = await hashPassword(
|
dataUser.password = await hashPassword(
|
||||||
updateUserDto.password,
|
updateUserDto.password,
|
||||||
dataUser.salt,
|
dataUser.salt,
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.usersRepository.save(dataUser);
|
const result = await this.usersRepository.save(dataUser);
|
||||||
|
|
||||||
return dataUser;
|
return dataUser;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
@ -444,11 +473,14 @@ export class UsersService {
|
||||||
partner: id,
|
partner: id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
dataUser.password = await hashPassword(
|
dataUser.password = await hashPassword(
|
||||||
updateUserDto.password,
|
updateUserDto.password,
|
||||||
dataUser.salt,
|
dataUser.salt,
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await this.usersRepository.save(dataUser);
|
const result = await this.usersRepository.save(dataUser);
|
||||||
|
|
||||||
return dataUser;
|
return dataUser;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof EntityNotFoundError) {
|
if (e instanceof EntityNotFoundError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user