org root add responsibility

This commit is contained in:
kittapath 2025-03-14 13:26:37 +07:00
parent 11c79abc31
commit 856315b7bc
8 changed files with 74 additions and 45 deletions

View file

@ -39,7 +39,7 @@ import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee";
import { RequestWithUser } from "../middlewares/user";
import HttpSuccess from "../interfaces/http-success";
import { Brackets, In, IsNull } from "typeorm";
import { Brackets, In, IsNull, Not } from "typeorm";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
import { RoleKeycloak } from "../entities/RoleKeycloak";
@ -830,7 +830,7 @@ export class KeycloakController extends Controller {
return result;
}
@Post("user/asdasdasd")
@Post("user/create")
@Security("bearerAuth", ["system", "admin"])
async createUserImport(
@Request() request: { user: { sub: string; preferred_username: string } },
@ -872,7 +872,7 @@ export class KeycloakController extends Controller {
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
userId,
list.filter((v) => v.id == "8a1a0dc9-304c-4e5b-a90a-65f841048212"),
list.filter((v) => v.id == "f8619dc2-dc0d-4aab-957f-66bdf905e9d0"),
);
if (!result) {
@ -882,13 +882,32 @@ export class KeycloakController extends Controller {
_item.keycloak = userId;
}
const roleKeycloak = await this.roleKeycloakRepo.find({
where: { id: "8a1a0dc9-304c-4e5b-a90a-65f841048212" },
where: { id: "f8619dc2-dc0d-4aab-957f-66bdf905e9d0" },
});
if (_item) {
_item.roleKeycloaks = Array.from(new Set([..._item.roleKeycloaks, ...roleKeycloak]));
this.profileRepo.save(_item);
}
}
return "555+";
return "";
}
@Post("user/change-password-all")
async changeUserPasswordAll(
@Request() request: { user: { sub: string; preferred_username: string } },
) {
const profiles = await this.profileRepo.find({
where: {
keycloak: Not(IsNull()),
},
});
for await (const _item of profiles) {
const result = await changeUserPassword(_item.keycloak, "P@ssw0rd");
if (!result) {
continue;
}
}
return;
}
}