สร้าง user ประจำของ keycloak #759
This commit is contained in:
parent
458fb90187
commit
37fc689ecc
1 changed files with 39 additions and 10 deletions
|
|
@ -1604,24 +1604,26 @@ export class CommandController extends Controller {
|
||||||
commandRecive = Object.assign(new CommandRecive(), item);
|
commandRecive = Object.assign(new CommandRecive(), item);
|
||||||
commandRecive.order = order;
|
commandRecive.order = order;
|
||||||
let salaryData = null_;
|
let salaryData = null_;
|
||||||
if(item.profileId){
|
if (item.profileId) {
|
||||||
salaryData = await this.profileRepository.findOne({
|
salaryData = await this.profileRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: item.profileId
|
id: item.profileId,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
let null_: any = 0;
|
let null_: any = 0;
|
||||||
if (!salaryData) {
|
if (!salaryData) {
|
||||||
salaryData = await this.profileEmployeeRepository.findOne({
|
salaryData = await this.profileEmployeeRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: item.profileId
|
id: item.profileId,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
commandRecive.amount = salaryData ? salaryData.amount : null_;
|
commandRecive.amount = salaryData ? salaryData.amount : null_;
|
||||||
commandRecive.positionSalaryAmount = salaryData ? salaryData.positionSalaryAmount : null_;
|
commandRecive.positionSalaryAmount = salaryData
|
||||||
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
|
? salaryData.positionSalaryAmount
|
||||||
}else{
|
: null_;
|
||||||
|
commandRecive.mouthSalaryAmount = salaryData ? salaryData.mouthSalaryAmount : null_;
|
||||||
|
} else {
|
||||||
commandRecive.amount = null_;
|
commandRecive.amount = null_;
|
||||||
commandRecive.positionSalaryAmount = null_;
|
commandRecive.positionSalaryAmount = null_;
|
||||||
commandRecive.mouthSalaryAmount = null_;
|
commandRecive.mouthSalaryAmount = null_;
|
||||||
|
|
@ -2984,7 +2986,34 @@ export class CommandController extends Controller {
|
||||||
posMasterId: profile.posmasterIdTemp,
|
posMasterId: profile.posmasterIdTemp,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (positionNew != null) {
|
if (positionNew != null) {
|
||||||
|
|
||||||
|
// Create Keycloak
|
||||||
|
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||||
|
firstName: profile.firstName,
|
||||||
|
lastName: profile.lastName,
|
||||||
|
// email: profile.email,
|
||||||
|
});
|
||||||
|
if (typeof userKeycloakId !== "string") {
|
||||||
|
throw new Error(userKeycloakId.errorMessage);
|
||||||
|
}
|
||||||
|
const list = await getRoles();
|
||||||
|
if (!Array.isArray(list))
|
||||||
|
throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
|
const result = await addUserRoles(
|
||||||
|
userKeycloakId,
|
||||||
|
list
|
||||||
|
.filter((v) => v.name === "USER")
|
||||||
|
.map((x) => ({
|
||||||
|
id: x.id,
|
||||||
|
name: x.name,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
if (!result) throw new Error("Failed. Cannot set user's role.");
|
||||||
|
profile.keycloak = userKeycloakId;
|
||||||
|
// End Create Keycloak
|
||||||
|
|
||||||
positionNew.positionIsSelected = true;
|
positionNew.positionIsSelected = true;
|
||||||
profile.posLevelId = positionNew.posLevelId;
|
profile.posLevelId = positionNew.posLevelId;
|
||||||
profile.posTypeId = positionNew.posTypeId;
|
profile.posTypeId = positionNew.posTypeId;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue