no message

This commit is contained in:
kittapath 2024-11-27 11:06:05 +07:00
parent b4b49b7378
commit d7c10e4d64

View file

@ -107,39 +107,6 @@ export class KeycloakController extends Controller {
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
userId,
list.filter((v) => body.roles.includes(v.id)),
);
const now = new Date().toISOString();
const folderData: any = {
pathname: stripLeadingSlash(`${body.username.trim()}/`),
path: "",
name: body.username.trim(),
hidden: false,
permissionGroup: [],
permissionUser: [],
permissionOther: {
create: false,
read: false,
update: false,
delete: false,
perm: false,
},
favourite: false,
color: "default",
type: "folder",
owner: body.username,
ownerId: userId,
createdAt: now,
createdBy: request.user.preferred_username,
createdByUserId: request.user.sub,
updatedAt: now,
updatedBy: request.user.preferred_username,
updatedByUserId: request.user.sub,
};
const profile = await this.profileRepo.findOne({
where: {
id: body.profileId,
@ -172,6 +139,64 @@ export class KeycloakController extends Controller {
return userId;
}
@Post("user-emp")
@Security("bearerAuth", ["system", "admin"])
async createUserEmployee(
@Request() request: { user: { sub: string; preferred_username: string } },
@Body()
body: {
username: string;
password: string;
firstName?: string;
lastName?: string;
email?: string;
roles: string[];
profileId?: string;
},
) {
const userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const profile = await this.profileEmpRepo.findOne({
where: {
id: body.profileId,
},
});
if (profile) {
let _null: any = null;
if (typeof userId === "string") {
profile.keycloak = userId;
}
profile.email = body.email == null ? _null : body.email;
await this.profileEmpRepo.save(profile);
if (body.roles != null && body.roles.length > 0) {
const roleKeycloak = await this.roleKeycloakRepo.find({
where: { id: In(body.roles) },
});
const _profile = await this.profileEmpRepo.findOne({
where: { keycloak: userId },
relations: ["roleKeycloaks"],
});
if (_profile) {
_profile.roleKeycloaks = Array.from(
new Set([..._profile.roleKeycloaks, ...roleKeycloak]),
);
this.profileEmpRepo.save(_profile);
}
}
}
return userId;
}
@Put("user/{userId}")
async editUser(
@Path() userId: string,