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 {
|
import {
|
||||||
Entity,
|
Entity,
|
||||||
Column,
|
Column,
|
||||||
PrimaryGeneratedColumn, BeforeInsert,
|
PrimaryGeneratedColumn, BeforeInsert, ManyToOne,
|
||||||
} from 'typeorm';
|
} 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';
|
||||||
|
@ -22,4 +23,24 @@ export class User extends BaseModel {
|
||||||
|
|
||||||
@Column({ default: true })
|
@Column({ default: true })
|
||||||
isActive: boolean;
|
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,
|
Delete,
|
||||||
ParseUUIDPipe,
|
ParseUUIDPipe,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
|
Query,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UsersService } from './users.service';
|
import { UsersService } from './users.service';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
|
@ -30,8 +31,8 @@ export class UsersController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async findAll() {
|
async findAll(@Query('page') page: number) {
|
||||||
const [data, count] = await this.usersService.findAll();
|
const [data, count] = await this.usersService.findAll(page);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
|
|
|
@ -28,14 +28,25 @@ export class UsersService {
|
||||||
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
return this.usersRepository.findOneOrFail(result.identifiers[0].id);
|
||||||
}
|
}
|
||||||
|
|
||||||
findAll() {
|
findAll(page:number) {
|
||||||
return this.usersRepository.findAndCount();
|
return this.usersRepository.findAndCount({
|
||||||
|
skip: page * 10,
|
||||||
|
take: 10,
|
||||||
|
order: {
|
||||||
|
version: 'DESC',
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
const coa = await this.coaService.findByUser(id,coaType.WALLET);
|
const coa = await this.coaService.findByUser(id,coaType.WALLET);
|
||||||
try {
|
try {
|
||||||
const userData = await this.usersRepository.findOneOrFail(id);
|
const userData = await this.usersRepository.findOneOrFail({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
relations:["roles","superior"]
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
...userData,
|
...userData,
|
||||||
wallet:coa.amount,
|
wallet:coa.amount,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user