Spaces:
Sleeping
Sleeping
see list of user
Browse files
backend/src/entities/user.entity.ts
CHANGED
@@ -56,4 +56,11 @@ export class UserEntity extends BaseEntity {
|
|
56 |
|
57 |
@OneToMany(() => ReceiptEntity, (receipt) => receipt.receiver)
|
58 |
out_receipts: Relation<ReceiptEntity>[];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
|
|
56 |
|
57 |
@OneToMany(() => ReceiptEntity, (receipt) => receipt.receiver)
|
58 |
out_receipts: Relation<ReceiptEntity>[];
|
59 |
+
|
60 |
+
@ManyToOne(() => BranchEntity, { nullable: true })
|
61 |
+
@JoinColumn({ name: 'branch_id' }) // Tùy chỉnh tên cột là branch_id
|
62 |
+
branch: Relation<BranchEntity>;
|
63 |
+
|
64 |
+
@Column({ nullable: true })
|
65 |
+
branch_id: string;
|
66 |
}
|
backend/src/migrations/1731146081011-create-branch-id.ts
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
+
|
3 |
+
export class CreateBranchId1731146081011 implements MigrationInterface {
|
4 |
+
name = 'CreateBranchId1731146081011'
|
5 |
+
|
6 |
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
+
await queryRunner.query(`ALTER TABLE "users" ADD "branch_id" character varying`);
|
8 |
+
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "FK_5a58f726a41264c8b3e86d4a1de" FOREIGN KEY ("branch_id") REFERENCES "branches"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
9 |
+
}
|
10 |
+
|
11 |
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
12 |
+
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "FK_5a58f726a41264c8b3e86d4a1de"`);
|
13 |
+
await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "branch_id"`);
|
14 |
+
}
|
15 |
+
|
16 |
+
}
|
backend/src/modules/user/user.controller.ts
CHANGED
@@ -10,21 +10,6 @@ import { UpdateUsersDto } from './dto/update-users.dto.js';
|
|
10 |
export class UsersController {
|
11 |
constructor(private readonly usersService: UserService) {}
|
12 |
|
13 |
-
@Get('id')
|
14 |
-
@Roles(Role.ADMIN, Role.AREA_MANAGER, Role.BRANCH_MANAGER)
|
15 |
-
async getUserById(
|
16 |
-
@Query('id') id: string
|
17 |
-
): Promise<UserEntity | undefined> {
|
18 |
-
return this.usersService.findOneByField("id", id)
|
19 |
-
}
|
20 |
-
|
21 |
-
@Get('fullname')
|
22 |
-
@Roles(Role.ADMIN, Role.AREA_MANAGER, Role.BRANCH_MANAGER)
|
23 |
-
async getUserByFullname( @Query('full_name') fullName: string, @Paginate() query: PaginateQuery, ) {
|
24 |
-
console.log(fullName)
|
25 |
-
return this.usersService.findAllByName(fullName, query);
|
26 |
-
}
|
27 |
-
|
28 |
@Post('updateUser')
|
29 |
async updateUser(@Request() req){
|
30 |
const userId = req.user.sub;
|
@@ -40,22 +25,9 @@ export class UsersController {
|
|
40 |
return this.usersService.updateUsers(updateUsersDto);
|
41 |
}
|
42 |
|
43 |
-
@Get('
|
44 |
@Roles(Role.ADMIN, Role.AREA_MANAGER, Role.BRANCH_MANAGER)
|
45 |
-
async
|
46 |
-
return this.usersService.
|
47 |
-
}
|
48 |
-
|
49 |
-
@Get('role')
|
50 |
-
@Roles(Role.ADMIN, Role.AREA_MANAGER, Role.BRANCH_MANAGER)
|
51 |
-
async getUserByRole( @Query('role') role: string, @Paginate() query: PaginateQuery, ) {
|
52 |
-
console.log(role)
|
53 |
-
return this.usersService.findAllByRole(role, query);
|
54 |
-
}
|
55 |
-
|
56 |
-
@Get('role')
|
57 |
-
@Roles(Role.ADMIN, Role.AREA_MANAGER)
|
58 |
-
async getUsersByBranch(@Query('branchId') branchId: string, @Paginate() query: PaginateQuery){
|
59 |
-
|
60 |
}
|
61 |
}
|
|
|
10 |
export class UsersController {
|
11 |
constructor(private readonly usersService: UserService) {}
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
@Post('updateUser')
|
14 |
async updateUser(@Request() req){
|
15 |
const userId = req.user.sub;
|
|
|
25 |
return this.usersService.updateUsers(updateUsersDto);
|
26 |
}
|
27 |
|
28 |
+
@Get('getUsers')
|
29 |
@Roles(Role.ADMIN, Role.AREA_MANAGER, Role.BRANCH_MANAGER)
|
30 |
+
async getUsers( @Paginate() query: PaginateQuery, ) {
|
31 |
+
return this.usersService.getUsers(query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
}
|
backend/src/modules/user/user.service.ts
CHANGED
@@ -103,22 +103,25 @@ export class UserService {
|
|
103 |
return paginate(query, queryBuilder, paginateConfig);
|
104 |
}
|
105 |
|
106 |
-
async
|
107 |
const queryBuilder = UserEntity.createQueryBuilder('users')
|
108 |
-
.where('users.role = :role', { role });
|
109 |
const paginateConfig: PaginateConfig<UserEntity> = {
|
110 |
sortableColumns: ['id', 'full_name', 'phone_number', 'email'],
|
111 |
nullSort: 'last',
|
112 |
defaultSortBy: [['id', 'DESC']],
|
113 |
-
searchableColumns: ['full_name'],
|
114 |
filterableColumns: {
|
|
|
115 |
full_name: [
|
116 |
FilterOperator.LT,
|
117 |
FilterOperator.LTE,
|
118 |
FilterOperator.GT,
|
119 |
FilterOperator.GTE,
|
120 |
],
|
121 |
-
|
|
|
|
|
|
|
122 |
},
|
123 |
};
|
124 |
return paginate(query, queryBuilder, paginateConfig);
|
|
|
103 |
return paginate(query, queryBuilder, paginateConfig);
|
104 |
}
|
105 |
|
106 |
+
async getUsers(query: PaginateQuery) {
|
107 |
const queryBuilder = UserEntity.createQueryBuilder('users')
|
|
|
108 |
const paginateConfig: PaginateConfig<UserEntity> = {
|
109 |
sortableColumns: ['id', 'full_name', 'phone_number', 'email'],
|
110 |
nullSort: 'last',
|
111 |
defaultSortBy: [['id', 'DESC']],
|
112 |
+
searchableColumns: ['full_name', 'phone_number'],
|
113 |
filterableColumns: {
|
114 |
+
id: [FilterOperator.EQ],
|
115 |
full_name: [
|
116 |
FilterOperator.LT,
|
117 |
FilterOperator.LTE,
|
118 |
FilterOperator.GT,
|
119 |
FilterOperator.GTE,
|
120 |
],
|
121 |
+
phone_number: [FilterOperator.EQ],
|
122 |
+
email: [FilterOperator.EQ],
|
123 |
+
branch_id:[FilterOperator.EQ],
|
124 |
+
role: [FilterOperator.EQ]
|
125 |
},
|
126 |
};
|
127 |
return paginate(query, queryBuilder, paginateConfig);
|