Merge branch 'develop' of github.com:Frappet/hrms-api-org into develop
This commit is contained in:
commit
88805b6040
4 changed files with 148 additions and 119 deletions
|
|
@ -18,7 +18,7 @@ import { format } from "path";
|
||||||
import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
|
import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
|
||||||
import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation";
|
import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmployeeEvaluation";
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
|
import { resetPassword } from "../keycloak";
|
||||||
@Route("api/v1/org/unauthorize")
|
@Route("api/v1/org/unauthorize")
|
||||||
@Tags("OrganizationUnauthorize")
|
@Tags("OrganizationUnauthorize")
|
||||||
@Response(
|
@Response(
|
||||||
|
|
@ -36,6 +36,20 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
viewProfileEmployeeEvaluation,
|
viewProfileEmployeeEvaluation,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Post("user/reset-password")
|
||||||
|
async forgetPassword(
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
username: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const result = await resetPassword(body.username);
|
||||||
|
if (!result) {
|
||||||
|
throw new Error("Failed. Cannot change password.");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize)
|
* API รายชื่อราชการที่เลื่อนเงินเดือน (unauthorize)
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -174,13 +174,13 @@ export class ReportController extends Controller {
|
||||||
async registryOfficer(
|
async registryOfficer(
|
||||||
@Query() node?: number,
|
@Query() node?: number,
|
||||||
@Query() nodeId?: string,
|
@Query() nodeId?: string,
|
||||||
@Query() posTypeName?: string,
|
@Query() posType?: string,
|
||||||
@Query() posLevelName?: string,
|
@Query() posLevel?: string,
|
||||||
@Query() position?: string,
|
@Query() position?: string,
|
||||||
@Query() posExecutiveName?: string,
|
@Query() posExecutiveName?: string,
|
||||||
@Query() gender?: string,
|
@Query() gender?: string,
|
||||||
@Query() relationship?: string,
|
@Query() status?: string,
|
||||||
@Query() degree?: string,
|
@Query() education?: string,
|
||||||
@Query() startDateAppoint?: Date,
|
@Query() startDateAppoint?: Date,
|
||||||
@Query() endDateAppoint?: Date,
|
@Query() endDateAppoint?: Date,
|
||||||
@Query() ageMin?: number,
|
@Query() ageMin?: number,
|
||||||
|
|
@ -251,58 +251,60 @@ export class ReportController extends Controller {
|
||||||
})
|
})
|
||||||
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets((qb) => {
|
posType != null && posType != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.posTypeName LIKE :posTypeName"
|
||||||
posTypeName != null && posTypeName != ""
|
: "1=1",
|
||||||
? "registryOfficer.posTypeName LIKE :posTypeName"
|
{
|
||||||
: "1=1",
|
posTypeName: `%${posType}%`,
|
||||||
{
|
}
|
||||||
posTypeName: `%${posTypeName}%`,
|
)
|
||||||
},
|
.andWhere(
|
||||||
);
|
posLevel != null && posLevel != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.posLevelName LIKE :posLevelName"
|
||||||
posLevelName != null && posLevelName != ""
|
: "1=1",
|
||||||
? "registryOfficer.posLevelName LIKE :posLevelName"
|
{
|
||||||
: "1=1",
|
posLevelName: `%${posLevel}%`,
|
||||||
{
|
}
|
||||||
posLevelName: `%${posLevelName}%`,
|
)
|
||||||
},
|
.andWhere(
|
||||||
);
|
position != null && position != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.position LIKE :position"
|
||||||
position != null && position != "" ? "registryOfficer.position LIKE :position" : "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
position: `%${position}%`,
|
position: `%${position}%`,
|
||||||
},
|
}
|
||||||
);
|
)
|
||||||
qb.orWhere(
|
.andWhere(
|
||||||
posExecutiveName != null && posExecutiveName != ""
|
posExecutiveName != null && posExecutiveName != ""
|
||||||
? "registryOfficer.posExecutiveName LIKE :posExecutiveName"
|
? "registryOfficer.posExecutiveName LIKE :posExecutiveName"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
posExecutiveName: `%${posExecutiveName}%`,
|
posExecutiveName: `%${posExecutiveName}%`,
|
||||||
},
|
}
|
||||||
);
|
)
|
||||||
qb.orWhere(
|
.andWhere(
|
||||||
gender != null && gender != "" ? "registryOfficer.gender LIKE :gender" : "1=1",
|
gender != null && gender != ""
|
||||||
{
|
? "registryOfficer.gender LIKE :gender"
|
||||||
gender: `%${gender}%`,
|
: "1=1",
|
||||||
},
|
{
|
||||||
);
|
gender: `%${gender}%`,
|
||||||
qb.orWhere(
|
}
|
||||||
relationship != null && relationship != ""
|
)
|
||||||
? "registryOfficer.relationship LIKE :relationship"
|
.andWhere(
|
||||||
: "1=1",
|
status != null && status != ""
|
||||||
{
|
? "registryOfficer.relationship LIKE :relationship"
|
||||||
relationship: `%${relationship}%`,
|
: "1=1",
|
||||||
},
|
{
|
||||||
);
|
relationship: `%${status}%`,
|
||||||
qb.orWhere(
|
}
|
||||||
degree != null && degree != "" ? "registryOfficer.degree LIKE :degree" : "1=1",
|
)
|
||||||
{
|
.andWhere(
|
||||||
degree: `%${degree}%`,
|
education != null && education != ""
|
||||||
},
|
? "registryOfficer.degree LIKE :degree"
|
||||||
);
|
: "1=1",
|
||||||
}),
|
{
|
||||||
|
degree: `%${education}%`,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.orderBy(`registryOfficer.${sortBy}`, sort)
|
.orderBy(`registryOfficer.${sortBy}`, sort)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
@ -469,12 +471,12 @@ export class ReportController extends Controller {
|
||||||
async registryEmployee(
|
async registryEmployee(
|
||||||
@Query() node?: number,
|
@Query() node?: number,
|
||||||
@Query() nodeId?: string,
|
@Query() nodeId?: string,
|
||||||
@Query() posTypeName?: string,
|
@Query() posType?: string,
|
||||||
@Query() posLevelName?: string,
|
@Query() posLevel?: string,
|
||||||
@Query() position?: string,
|
@Query() position?: string,
|
||||||
@Query() gender?: string,
|
@Query() gender?: string,
|
||||||
@Query() relationship?: string,
|
@Query() status?: string,
|
||||||
@Query() degree?: string,
|
@Query() education?: string,
|
||||||
@Query() startDateAppoint?: Date,
|
@Query() startDateAppoint?: Date,
|
||||||
@Query() endDateAppoint?: Date,
|
@Query() endDateAppoint?: Date,
|
||||||
@Query() isProbation?: boolean,
|
@Query() isProbation?: boolean,
|
||||||
|
|
@ -545,50 +547,52 @@ export class ReportController extends Controller {
|
||||||
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
||||||
.andWhere("registryEmployee.employeeClass = 'PERM'")
|
.andWhere("registryEmployee.employeeClass = 'PERM'")
|
||||||
.andWhere(
|
.andWhere(
|
||||||
new Brackets((qb) => {
|
posType != null && posType != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.posTypeName LIKE :posTypeName"
|
||||||
posTypeName != null && posTypeName != ""
|
: "1=1",
|
||||||
? "registryEmployee.posTypeName LIKE :posTypeName"
|
{
|
||||||
: "1=1",
|
posTypeName: `%${posType}%`,
|
||||||
{
|
}
|
||||||
posTypeName: `%${posTypeName}%`,
|
)
|
||||||
},
|
.andWhere(
|
||||||
);
|
posLevel != null && posLevel != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.posLevelName LIKE :posLevelName"
|
||||||
posLevelName != null && posLevelName != ""
|
: "1=1",
|
||||||
? "registryEmployee.posLevelName LIKE :posLevelName"
|
{
|
||||||
: "1=1",
|
posLevelName: `%${posLevel}%`,
|
||||||
{
|
}
|
||||||
posLevelName: `%${posLevelName}%`,
|
)
|
||||||
},
|
.andWhere(
|
||||||
);
|
position != null && position != ""
|
||||||
qb.orWhere(
|
? "registryOfficer.position LIKE :position"
|
||||||
position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
position: `%${position}%`,
|
position: `%${position}%`,
|
||||||
},
|
}
|
||||||
);
|
)
|
||||||
qb.orWhere(
|
.andWhere(
|
||||||
gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1",
|
gender != null && gender != ""
|
||||||
{
|
? "registryOfficer.gender LIKE :gender"
|
||||||
gender: `%${gender}%`,
|
: "1=1",
|
||||||
},
|
{
|
||||||
);
|
gender: `%${gender}%`,
|
||||||
qb.orWhere(
|
}
|
||||||
relationship != null && relationship != ""
|
)
|
||||||
? "registryEmployee.relationship LIKE :relationship"
|
.andWhere(
|
||||||
: "1=1",
|
status != null && status != ""
|
||||||
{
|
? "registryOfficer.relationship LIKE :relationship"
|
||||||
relationship: `%${relationship}%`,
|
: "1=1",
|
||||||
},
|
{
|
||||||
);
|
relationship: `%${status}%`,
|
||||||
qb.orWhere(
|
}
|
||||||
degree != null && degree != "" ? "registryEmployee.degree LIKE :degree" : "1=1",
|
)
|
||||||
{
|
.andWhere(
|
||||||
degree: `%${degree}%`,
|
education != null && education != ""
|
||||||
},
|
? "registryOfficer.degree LIKE :degree"
|
||||||
);
|
: "1=1",
|
||||||
}),
|
{
|
||||||
|
degree: `%${education}%`,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.orderBy(`registryEmployee.${sortBy}`, sort)
|
.orderBy(`registryEmployee.${sortBy}`, sort)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
|
||||||
|
|
@ -830,18 +830,4 @@ export class KeycloakController extends Controller {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("user/reset-password")
|
|
||||||
async forgetPassword(
|
|
||||||
@Request() request: { user: { sub: string; preferred_username: string } },
|
|
||||||
@Body()
|
|
||||||
body: {
|
|
||||||
username: string;
|
|
||||||
},
|
|
||||||
) {
|
|
||||||
const result = await resetPassword(body.username);
|
|
||||||
if (!result) {
|
|
||||||
throw new Error("Failed. Cannot change password.");
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ const KC_URL = process.env.KC_URL;
|
||||||
const KC_REALMS = process.env.KC_REALMS;
|
const KC_REALMS = process.env.KC_REALMS;
|
||||||
const KC_CLIENT_ID = process.env.KC_SERVICE_ACCOUNT_CLIENT_ID;
|
const KC_CLIENT_ID = process.env.KC_SERVICE_ACCOUNT_CLIENT_ID;
|
||||||
const KC_SECRET = process.env.KC_SERVICE_ACCOUNT_SECRET;
|
const KC_SECRET = process.env.KC_SERVICE_ACCOUNT_SECRET;
|
||||||
|
const AUTH_ACCOUNT_SECRET = process.env.AUTH_ACCOUNT_SECRET
|
||||||
|
const API_KEY = process.env.API_KEY
|
||||||
|
|
||||||
let token: string | null = null;
|
let token: string | null = null;
|
||||||
let decoded: DecodedJwt | null = null;
|
let decoded: DecodedJwt | null = null;
|
||||||
|
|
@ -765,9 +767,31 @@ export async function changeUserPassword(userId: string, newPassword: string) {
|
||||||
// Function to reset password
|
// Function to reset password
|
||||||
export async function resetPassword(username: string) {
|
export async function resetPassword(username: string) {
|
||||||
try {
|
try {
|
||||||
|
// if (!API_KEY || !AUTH_ACCOUNT_SECRET) {
|
||||||
|
// throw new Error("KC_CLIENT_ID and KC_SECRET are required to used this feature.");
|
||||||
|
// }
|
||||||
|
// const body = new URLSearchParams();
|
||||||
|
// body.append("client_id", "gettoken");
|
||||||
|
// body.append("client_secret", AUTH_ACCOUNT_SECRET?.toString());
|
||||||
|
// body.append("grant_type", "client_credentials");
|
||||||
|
// const tokenResponse = await fetch(`${process.env.KC_URL}/realms/${process.env.KC_REALMS}/protocol/openid-connect/token`, {
|
||||||
|
// method: "POST",
|
||||||
|
// headers: {
|
||||||
|
// "Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
// api_key: API_KEY,
|
||||||
|
// },
|
||||||
|
// body: body
|
||||||
|
// });
|
||||||
|
// if (!tokenResponse.ok) {
|
||||||
|
// throw new Error("Failed to get admin token");
|
||||||
|
// }
|
||||||
|
// const tokenData = await tokenResponse.json();
|
||||||
|
// const adminToken = tokenData.access_token;
|
||||||
|
|
||||||
const users = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`, {
|
const users = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users?email=${encodeURIComponent(username)}`, {
|
||||||
headers: {
|
headers: {
|
||||||
"authorization": `Bearer ${await getToken()}`,
|
"authorization": `Bearer ${await getToken()}`,
|
||||||
|
// "authorization": `Bearer ${adminToken}`,
|
||||||
"content-type": `application/json`,
|
"content-type": `application/json`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -780,6 +804,7 @@ export async function resetPassword(username: string) {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bearer ${await getToken()}`,
|
"Authorization": `Bearer ${await getToken()}`,
|
||||||
|
// "Authorization": `Bearer ${adminToken}`,
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
},
|
},
|
||||||
body: JSON.stringify(["UPDATE_PASSWORD"])
|
body: JSON.stringify(["UPDATE_PASSWORD"])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue