fix: approve retail
This commit is contained in:
@@ -67,6 +67,7 @@ export class UsersService {
|
||||
|
||||
if (createUserDto.superior) {
|
||||
userData.superior = superior;
|
||||
userData.status_approval = superior.roles.name;
|
||||
} else {
|
||||
userData.superior = null;
|
||||
userData.partner = createUserDto.partner;
|
||||
@@ -130,7 +131,13 @@ export class UsersService {
|
||||
return userData;
|
||||
}
|
||||
|
||||
async findAll(page: number, pageSize: number, id: string, superior: string, type: string) {
|
||||
async findAll(
|
||||
page: number,
|
||||
pageSize: number,
|
||||
id: string,
|
||||
superior: string,
|
||||
type: string,
|
||||
) {
|
||||
const baseQuery = this.usersRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.id != :id', {
|
||||
@@ -289,6 +296,55 @@ export class UsersService {
|
||||
};
|
||||
}
|
||||
|
||||
async findApproval(superrior, page: number, pageSize: number) {
|
||||
const dataUser = await this.findByUsername(superrior.username);
|
||||
|
||||
const baseQuery = this.usersRepository
|
||||
.createQueryBuilder('user')
|
||||
.where(
|
||||
'user.id != :id and user.superior_id = :superior and status_approval = :status and isRejected is false',
|
||||
{
|
||||
id: superrior.userId,
|
||||
superior: superrior.userId,
|
||||
status: dataUser.roles.name,
|
||||
},
|
||||
)
|
||||
.leftJoinAndSelect('user.roles', 'roles', `roles.id = user.roles_id`)
|
||||
.leftJoinAndMapOne(
|
||||
'user.user_detail',
|
||||
UserDetail,
|
||||
'user_detail',
|
||||
`user_detail.user = user.id`,
|
||||
)
|
||||
.leftJoinAndMapOne(
|
||||
'user.coa',
|
||||
COA,
|
||||
'coa',
|
||||
`coa.user = user.id and coa.type = '0'`,
|
||||
)
|
||||
.select([
|
||||
'user.id',
|
||||
'user.username',
|
||||
'user.isActive',
|
||||
'roles.id',
|
||||
'roles.name',
|
||||
'user_detail',
|
||||
'coa.amount',
|
||||
]);
|
||||
|
||||
const data = await baseQuery
|
||||
.skip(page * pageSize)
|
||||
.take(pageSize)
|
||||
.getMany();
|
||||
|
||||
const totalData = await baseQuery.getCount();
|
||||
|
||||
return {
|
||||
data,
|
||||
count: totalData,
|
||||
};
|
||||
}
|
||||
|
||||
async findExist(id: string) {
|
||||
try {
|
||||
return await this.usersRepository.findOneOrFail({
|
||||
@@ -503,6 +559,37 @@ export class UsersService {
|
||||
}
|
||||
}
|
||||
|
||||
async confirmationUser(id: string, user: string, status: string) {
|
||||
try {
|
||||
const dataUser = await this.usersRepository.findOneOrFail(id);
|
||||
const supervisorUser = await this.usersRepository.findOneOrFail(id);
|
||||
|
||||
if (status == 'approved') {
|
||||
dataUser.status_approval = supervisorUser.roles.name;
|
||||
} else if (status == 'resend') {
|
||||
dataUser.isRejected = false;
|
||||
} else {
|
||||
dataUser.isRejected = true;
|
||||
}
|
||||
|
||||
const result = await this.usersRepository.save(dataUser);
|
||||
|
||||
return dataUser;
|
||||
} catch (e) {
|
||||
if (e instanceof EntityNotFoundError) {
|
||||
throw new HttpException(
|
||||
{
|
||||
statusCode: HttpStatus.NOT_FOUND,
|
||||
error: 'User not found',
|
||||
},
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setStatus = async (id: string, type: string) => {
|
||||
const userData = new User();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user