แก้ sort report2

This commit is contained in:
Kittapath 2024-04-11 16:33:06 +07:00
parent 313ef6ec51
commit 5c9e50ce36
2 changed files with 165 additions and 23 deletions

View file

@ -26,6 +26,8 @@ import { OrgRoot } from "../entities/OrgRoot";
import { PosMaster } from "../entities/PosMaster";
import { calculateRetireDate } from "../interfaces/utils";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee";
@Route("api/v1/org/unauthorize")
@Tags("OrganizationUnauthorize")
@ -37,6 +39,8 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
export class OrganizationUnauthorizeController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private profileRepository = AppDataSource.getRepository(Profile);
private profileEmployeeRepository = AppDataSource.getRepository(ProfileEmployee);
/**
* API (unauthorize)
@ -197,7 +201,9 @@ export class OrganizationUnauthorizeController extends Controller {
datePeriodStart.getMonth() - 6,
),
);
const specialPosition = item.positions.find(position => position.positionIsSelected === true);
const specialPosition = item.positions.find(
(position) => position.positionIsSelected === true,
);
const isSpecial = specialPosition ? specialPosition.isSpecial : null;
return {
id: item.id,
@ -248,7 +254,7 @@ export class OrganizationUnauthorizeController extends Controller {
calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year
? false
: true,
isSpecial: isSpecial
isSpecial: isSpecial,
};
});
return new HttpSuccess({ data: formattedData, total: total });
@ -402,7 +408,7 @@ export class OrganizationUnauthorizeController extends Controller {
datePeriodStart.getMonth() - 6,
),
);
return {
salaryLevel: item.current_holder.salaryLevel,
group: item.current_holder.group,
@ -505,4 +511,98 @@ export class OrganizationUnauthorizeController extends Controller {
}
return new HttpSuccess(findRevision.id);
}
/**
* API user profile officer
*
* @summary user profile officer
*
*/
@Get("officer/{id}")
async GetProfileById(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findProfile = await AppDataSource.getRepository(Profile)
.createQueryBuilder("current_holder")
.leftJoinAndSelect("current_holder.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where({ id: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const posExecutive =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions ==
null ||
findProfile.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions
.length == 0 ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
return new HttpSuccess({
type: "OFFICER",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posExecutive: posExecutive,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
/**
* API user profile employee
*
* @summary user profile employee
*
*/
@Get("employee/{id}")
async GetProfileEmployeeById(@Path() id: string) {
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
.createQueryBuilder("current_holder")
.leftJoinAndSelect("current_holder.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where({ id: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
return new HttpSuccess({
type: "OFFICER",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
}

View file

@ -955,7 +955,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -968,7 +970,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -1275,7 +1279,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -1288,7 +1294,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -1597,7 +1605,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -1610,7 +1620,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -1928,7 +1940,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -1941,7 +1955,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -2259,7 +2275,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -2272,7 +2290,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -2739,7 +2759,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -2752,7 +2774,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -2909,7 +2933,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -2922,7 +2948,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -3081,7 +3109,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -3094,7 +3124,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -3253,7 +3285,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
(b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -3266,7 +3300,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];
@ -3426,7 +3462,11 @@ export class ReportController extends Controller {
posMaster.next_holder.profileEducations.length > 0
) {
let _education: any = posMaster.next_holder.profileEducations.sort(
(a, b) => b.finishDate.getTime() - a.finishDate.getTime(),
(a, b) =>
b.finishDate == null
? 0
: (b.finishDate == null ? 0 : b.finishDate.getTime()) -
(a.finishDate == null ? 0 : a.finishDate.getTime()),
);
if (_education.length > 0) {
education = _education[0];
@ -3439,7 +3479,9 @@ export class ReportController extends Controller {
posMaster.next_holder.profileSalary.length > 0
) {
let _salary: any = posMaster.next_holder.profileSalary.sort(
(a, b) => b.date.getTime() - a.date.getTime(),
(a, b) =>
(b.date == null ? 0 : b.date.getTime()) -
(a.date == null ? 0 : a.date.getTime()),
);
if (_salary.length > 0) {
salary = _salary[0];