fix: approve retail
This commit is contained in:
parent
48ec9ec5df
commit
965d285ce2
|
@ -44,3 +44,9 @@ export enum accountType {
|
||||||
PARTNER,
|
PARTNER,
|
||||||
CUSTOMER,
|
CUSTOMER,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum statusApproval {
|
||||||
|
ADMIN,
|
||||||
|
SUPERVISOR,
|
||||||
|
RETAIL,
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { BaseModel } from '../../config/basemodel.entity';
|
||||||
import { Partner } from './partner.entity';
|
import { Partner } from './partner.entity';
|
||||||
import { UserDetail } from './user_detail.entity';
|
import { UserDetail } from './user_detail.entity';
|
||||||
import { COA } from '../../transaction/entities/coa.entity';
|
import { COA } from '../../transaction/entities/coa.entity';
|
||||||
|
import { statusApproval, typeTransaction } from '../../helper/enum-list';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class User extends BaseModel {
|
export class User extends BaseModel {
|
||||||
|
@ -22,6 +23,14 @@ export class User extends BaseModel {
|
||||||
@Column({ default: true })
|
@Column({ default: true })
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
})
|
||||||
|
status_approval: string;
|
||||||
|
|
||||||
|
@Column({ default: false })
|
||||||
|
isRejected: boolean;
|
||||||
|
|
||||||
@ManyToOne(
|
@ManyToOne(
|
||||||
() => {
|
() => {
|
||||||
return User;
|
return User;
|
||||||
|
|
|
@ -187,7 +187,26 @@ export class UsersController {
|
||||||
@Query('page') page: number,
|
@Query('page') page: number,
|
||||||
@Query('pageSize') pageSize: number,
|
@Query('pageSize') pageSize: number,
|
||||||
) {
|
) {
|
||||||
const data = await this.usersService.findBySuperrior(req.user.userId, page, pageSize);
|
const data = await this.usersService.findBySuperrior(
|
||||||
|
req.user.userId,
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('find-by-approval')
|
||||||
|
async findByApproval(
|
||||||
|
@Request() req,
|
||||||
|
@Query('page') page: number,
|
||||||
|
@Query('pageSize') pageSize: number,
|
||||||
|
) {
|
||||||
|
const data = await this.usersService.findApproval(req.user, page, pageSize);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
|
@ -250,6 +269,33 @@ export class UsersController {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('approve-user/:id')
|
||||||
|
async approveUser(@Param('id', ParseUUIDPipe) id: string, @Request() req) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.confirmationUser(id, req.user, 'approved'),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('reject-user/:id')
|
||||||
|
async rejectUser(@Param('id', ParseUUIDPipe) id: string, @Request() req) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.confirmationUser(id, req.user, 'rejected'),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('resend-user/:id')
|
||||||
|
async resendUser(@Param('id', ParseUUIDPipe) id: string, @Request() req) {
|
||||||
|
return {
|
||||||
|
data: await this.usersService.confirmationUser(id, req.user, 'resend'),
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
message: 'success',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Put('change-password/:id')
|
@Put('change-password/:id')
|
||||||
async updatePassword(
|
async updatePassword(
|
||||||
@Param('id', ParseUUIDPipe) id: string,
|
@Param('id', ParseUUIDPipe) id: string,
|
||||||
|
|
|
@ -67,6 +67,7 @@ export class UsersService {
|
||||||
|
|
||||||
if (createUserDto.superior) {
|
if (createUserDto.superior) {
|
||||||
userData.superior = superior;
|
userData.superior = superior;
|
||||||
|
userData.status_approval = superior.roles.name;
|
||||||
} else {
|
} else {
|
||||||
userData.superior = null;
|
userData.superior = null;
|
||||||
userData.partner = createUserDto.partner;
|
userData.partner = createUserDto.partner;
|
||||||
|
@ -130,7 +131,13 @@ export class UsersService {
|
||||||
return userData;
|
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
|
const baseQuery = this.usersRepository
|
||||||
.createQueryBuilder('user')
|
.createQueryBuilder('user')
|
||||||
.where('user.id != :id', {
|
.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) {
|
async findExist(id: string) {
|
||||||
try {
|
try {
|
||||||
return await this.usersRepository.findOneOrFail({
|
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) => {
|
setStatus = async (id: string, type: string) => {
|
||||||
const userData = new User();
|
const userData = new User();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user