update #802
This commit is contained in:
parent
27f82f3652
commit
9ed7447095
1 changed files with 69 additions and 66 deletions
|
|
@ -99,13 +99,13 @@ export class KeycloakController extends Controller {
|
||||||
const userId = await createUser(body.username, body.password, {
|
const userId = await createUser(body.username, body.password, {
|
||||||
firstName: body.firstName,
|
firstName: body.firstName,
|
||||||
lastName: body.lastName,
|
lastName: body.lastName,
|
||||||
email: body.email,
|
// email: body.email,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof userId !== "string") {
|
if (typeof userId !== "string") {
|
||||||
throw new Error(userId.errorMessage);
|
throw new Error(userId.errorMessage);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
const folderData: any = {
|
const folderData: any = {
|
||||||
pathname: stripLeadingSlash(`${body.username.trim()}/`),
|
pathname: stripLeadingSlash(`${body.username.trim()}/`),
|
||||||
|
|
@ -142,7 +142,9 @@ export class KeycloakController extends Controller {
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
let _null: any = null;
|
let _null: any = null;
|
||||||
|
if (typeof userId === "string") {
|
||||||
profile.keycloak = userId;
|
profile.keycloak = userId;
|
||||||
|
}
|
||||||
profile.email = body.email == null ? _null : body.email;
|
profile.email = body.email == null ? _null : body.email;
|
||||||
await this.profileRepo.save(profile);
|
await this.profileRepo.save(profile);
|
||||||
if (body.roles != null && body.roles.length > 0) {
|
if (body.roles != null && body.roles.length > 0) {
|
||||||
|
|
@ -161,7 +163,6 @@ export class KeycloakController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,7 +250,7 @@ export class KeycloakController extends Controller {
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new Error("Failed. Cannot set user's role.");
|
throw new Error("Failed. Cannot set user's role.");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
const roleKeycloak = await this.roleKeycloakRepo.find({
|
const roleKeycloak = await this.roleKeycloakRepo.find({
|
||||||
where: { id: In(body.role) },
|
where: { id: In(body.role) },
|
||||||
});
|
});
|
||||||
|
|
@ -262,16 +263,18 @@ export class KeycloakController extends Controller {
|
||||||
where: { keycloak: userId },
|
where: { keycloak: userId },
|
||||||
relations: ["roleKeycloaks"],
|
relations: ["roleKeycloaks"],
|
||||||
});
|
});
|
||||||
if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
// if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
if(profileEmp) {
|
||||||
profileEmp.roleKeycloaks = Array.from(
|
profileEmp.roleKeycloaks = Array.from(
|
||||||
new Set([...profileEmp.roleKeycloaks, ...roleKeycloak]),
|
new Set([...profileEmp.roleKeycloaks, ...roleKeycloak]),
|
||||||
);
|
);
|
||||||
this.profileEmpRepo.save(profileEmp);
|
this.profileEmpRepo.save(profileEmp);
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
profile.roleKeycloaks = Array.from(new Set([...profile.roleKeycloaks, ...roleKeycloak]));
|
profile.roleKeycloaks = Array.from(new Set([...profile.roleKeycloaks, ...roleKeycloak]));
|
||||||
this.profileRepo.save(profile);
|
this.profileRepo.save(profile);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue