add: paging in user and relation when get in user
This commit is contained in:
parent
96d5089dc8
commit
a418e74db5
|
@ -1,7 +1,8 @@
|
|||
import { Roles } from 'src/configurable/entities/roles.entity';
|
||||
import {
|
||||
Entity,
|
||||
Column,
|
||||
PrimaryGeneratedColumn, BeforeInsert,
|
||||
PrimaryGeneratedColumn, BeforeInsert, ManyToOne,
|
||||
} from 'typeorm';
|
||||
import { BaseModel } from '../../config/basemodel.entity';
|
||||
import { hashPassword } from '../../helper/hash_password';
|
||||
|
@ -22,4 +23,24 @@ export class User extends BaseModel {
|
|||
|
||||
@Column({ default: true })
|
||||
isActive: boolean;
|
||||
|
||||
@ManyToOne(
|
||||
() => {
|
||||
return User;
|
||||
},
|
||||
(user) => {
|
||||
return user.id;
|
||||
},
|
||||
)
|
||||
superior: User;
|
||||
|
||||
@ManyToOne(
|
||||
() => {
|
||||
return Roles;
|
||||
},
|
||||
(roles) => {
|
||||
return roles.id;
|
||||
},
|
||||
)
|
||||
roles: Roles;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
Delete,
|
||||
ParseUUIDPipe,
|
||||
HttpStatus,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { UsersService } from './users.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
|
@ -30,8 +31,8 @@ export class UsersController {
|
|||
}
|
||||
|
||||
@Get()
|
||||
async findAll() {
|
||||
const [data, count] = await this.usersService.findAll();
|
||||
async findAll(@Query('page') page: number) {
|
||||
const [data, count] = await this.usersService.findAll(page);
|
||||
|
||||
return {
|
||||
data,
|
||||
|
|
|
@ -28,14 +28,25 @@ export class UsersService {
|
|||
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.usersRepository.findAndCount();
|
||||
findAll(page:number) {
|
||||
return this.usersRepository.findAndCount({
|
||||
skip: page * 10,
|
||||
take: 10,
|
||||
order: {
|
||||
version: 'DESC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
const coa = await this.coaService.findByUser(id,coaType.WALLET);
|
||||
try {
|
||||
const userData = await this.usersRepository.findOneOrFail(id);
|
||||
const userData = await this.usersRepository.findOneOrFail({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
relations:["roles","superior"]
|
||||
});
|
||||
return {
|
||||
...userData,
|
||||
wallet:coa.amount,
|
||||
|
|
Loading…
Reference in New Issue
Block a user