Merge branch 'develop' into adiDev
This commit is contained in:
commit
abd8327d17
2 changed files with 19 additions and 9 deletions
|
|
@ -88,7 +88,8 @@ export class KeycloakController extends Controller {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof userId !== "string") {
|
if (typeof userId !== "string") {
|
||||||
throw new Error("ไม่สามารถติดต่อกับระบบจัดการผู้ใช้งานได้");
|
// throw new Error("ไม่สามารถติดต่อกับระบบจัดการผู้ใช้งานได้");
|
||||||
|
throw new Error(userId.errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|
@ -140,9 +141,15 @@ export class KeycloakController extends Controller {
|
||||||
firstName?: string;
|
firstName?: string;
|
||||||
lastName?: string;
|
lastName?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
|
attributes?: object
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
return await editUser(userId, body);
|
// return await editUser(userId, body);
|
||||||
|
const chkUpdate = await editUser(userId, body);
|
||||||
|
if (typeof chkUpdate !== "boolean") {
|
||||||
|
throw new Error(chkUpdate.errorMessage);
|
||||||
|
}
|
||||||
|
return chkUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete("user/{userId}")
|
@Delete("user/{userId}")
|
||||||
|
|
@ -191,8 +198,8 @@ export class KeycloakController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("user")
|
@Get("user")
|
||||||
async getUserList(@Query() search = "") {
|
async getUserList(@Query() first = "", @Query() max = "" ,@Query() search = "") {
|
||||||
const result = await getUserList(search);
|
const result = await getUserList(first, max, search);
|
||||||
|
|
||||||
if (Array.isArray(result)) {
|
if (Array.isArray(result)) {
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,8 @@ export async function createUser(username: string, password: string, opts?: Reco
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
// return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = res.headers.get("Location");
|
const path = res.headers.get("Location");
|
||||||
|
|
@ -122,9 +123,10 @@ export async function getUser(userId: string) {
|
||||||
*
|
*
|
||||||
* @returns user list if success, false otherwise.
|
* @returns user list if success, false otherwise.
|
||||||
*/
|
*/
|
||||||
export async function getUserList(search = "") {
|
export async function getUserList(first = "", max = "", search = "") {
|
||||||
const res = await fetch(
|
const res = await fetch(
|
||||||
`${KC_URL}/admin/realms/${KC_REALM}/users`.concat(!!search ? `?search=${search}` : ""),
|
// `${KC_URL}/admin/realms/${KC_REALM}/users`.concat(!!search ? `?search=${search}` : ""),
|
||||||
|
`${KC_URL}/admin/realms/${KC_REALM}/users?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}`,
|
||||||
{
|
{
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -139,7 +141,7 @@ export async function getUserList(search = "") {
|
||||||
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((await res.json()) as any[]).map((v: Record<string, string>) => ({
|
return ((await res.json()) as any[]).slice(0, 5000).map((v: Record<string, string>) => ({
|
||||||
id: v.id,
|
id: v.id,
|
||||||
username: v.username,
|
username: v.username,
|
||||||
firstName: v.firstName,
|
firstName: v.firstName,
|
||||||
|
|
@ -174,7 +176,8 @@ export async function editUser(userId: string, opts: Record<string, any>) {
|
||||||
|
|
||||||
if (!res) return false;
|
if (!res) return false;
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
// return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||||
|
return await res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = res.headers.get("Location");
|
const path = res.headers.get("Location");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue