api จัดการผู้ใช้งาน
This commit is contained in:
parent
6320f4d7db
commit
855639bd7f
6 changed files with 335 additions and 46 deletions
|
|
@ -7874,47 +7874,4 @@ export class ProfileController extends Controller {
|
|||
]);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขอีเมล
|
||||
*
|
||||
* @summary แก้ไขอีเมล (USER)
|
||||
*
|
||||
*/
|
||||
@Get("keycloak/user")
|
||||
async listUserKeycloak(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query() keyword: string = "",
|
||||
) {
|
||||
// sort by org
|
||||
const [profiles, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.roleKeycloaks", "roleKeycloaks")
|
||||
.where("profile.citizenId LIKE :citizenId", {
|
||||
citizenId: `%${keyword}%`,
|
||||
})
|
||||
.andWhere(keyword != null && keyword != "" ? `profile.citizenId like '%${keyword}%'` : "1=1")
|
||||
.andWhere(
|
||||
keyword != null && keyword != ""
|
||||
? `CONCAT(profile.prefix, profile.firstName," ",profile.lastName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
const _profiles = profiles.map((_data) => ({
|
||||
id: _data.id,
|
||||
firstname: _data.firstName,
|
||||
lastname: _data.lastName,
|
||||
email: _data.email,
|
||||
username: _data.citizenId,
|
||||
citizenId: _data.citizenId,
|
||||
roles: _data.roleKeycloaks,
|
||||
enabled: _data.isActive,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({ data: _profiles, total });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ import { AppDataSource } from "../database/data-source";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { Brackets } from "typeorm";
|
||||
// import * as io from "../lib/websocket";
|
||||
// import elasticsearch from "../elasticsearch";
|
||||
// import { StorageFolder } from "../interfaces/storage-fs";
|
||||
|
|
@ -237,7 +239,7 @@ export class KeycloakController extends Controller {
|
|||
if (!result) throw new Error("Failed. Cannot remove user's role.");
|
||||
}
|
||||
|
||||
@Get("user")
|
||||
/*@Get("user")
|
||||
async getUserList(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() first = "",
|
||||
|
|
@ -348,6 +350,82 @@ export class KeycloakController extends Controller {
|
|||
return _mapData;
|
||||
}
|
||||
throw new Error("Failed. Cannot get user list.");
|
||||
}*/
|
||||
|
||||
@Get("user")
|
||||
async listUserKeycloak(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query() keyword: string = "",
|
||||
@Query() type: string = "",
|
||||
) {
|
||||
// sort by org
|
||||
let profiles: any;
|
||||
let total: any;
|
||||
if (type == "OFFICER") {
|
||||
[profiles, total] = await this.profileRepo
|
||||
.createQueryBuilder("profile")
|
||||
.leftJoinAndSelect("profile.roleKeycloaks", "roleKeycloaks")
|
||||
.where("profile.keycloak IS NOT NULL AND profile.keycloak != ''")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(keyword != null && keyword != "" ? `profile.citizenId like '%${keyword}%'` : "1=1")
|
||||
.orWhere(keyword != null && keyword != "" ? `profile.email like '%${keyword}%'` : "1=1")
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? `CONCAT(profile.prefix, profile.firstName," ",profile.lastName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
)
|
||||
}),
|
||||
)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
}
|
||||
else if (type == "EMPLOYEE") {
|
||||
[profiles, total] = await this.profileEmpRepo
|
||||
.createQueryBuilder("profileEmployee")
|
||||
.leftJoinAndSelect("profileEmployee.roleKeycloaks", "roleKeycloaks")
|
||||
.where("profileEmployee.keycloak IS NOT NULL AND profileEmployee.keycloak != ''")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere(keyword != null && keyword != "" ? `profileEmployee.citizenId like '%${keyword}%'` : "1=1")
|
||||
.orWhere(keyword != null && keyword != "" ? `profileEmployee.email like '%${keyword}%'` : "1=1")
|
||||
.orWhere(
|
||||
keyword != null && keyword != ""
|
||||
? `CONCAT(profileEmployee.prefix, profileEmployee.firstName," ",profileEmployee.lastName) like '%${keyword}%'`
|
||||
: "1=1",
|
||||
)
|
||||
}),
|
||||
)
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.getManyAndCount();
|
||||
}
|
||||
else {
|
||||
return new HttpSuccess({ data: [], total: 0 });
|
||||
}
|
||||
|
||||
const _profiles = profiles.map((_data:any) => ({
|
||||
id: _data.id,
|
||||
firstname: _data.firstName,
|
||||
lastname: _data.lastName,
|
||||
email: _data.email,
|
||||
username: _data.citizenId,
|
||||
citizenId: _data.citizenId,
|
||||
roles: _data.roleKeycloaks.length > 0
|
||||
? _data.roleKeycloaks.map((x:any) => ({
|
||||
id: x.id,
|
||||
name: x.name,
|
||||
description: x.description,
|
||||
composite: x.composite,
|
||||
clientRole: x.clientRole,
|
||||
containerId: x.containerId,
|
||||
}))
|
||||
: [],
|
||||
enabled: _data.isActive,
|
||||
}));
|
||||
return new HttpSuccess({ data: _profiles, total });
|
||||
}
|
||||
|
||||
@Get("group")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue