no message

This commit is contained in:
kittapath 2024-11-25 16:57:36 +07:00
parent ade79873ed
commit 0b4e597a81
3 changed files with 61 additions and 36 deletions

View file

@ -24,6 +24,7 @@ import { Profile } from "../entities/Profile";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { setLogDataDiff } from "../interfaces/utils"; import { setLogDataDiff } from "../interfaces/utils";
import { Brackets } from "typeorm";
@Route("api/v1/org/permission-org") @Route("api/v1/org/permission-org")
@Tags("PermissionOrg") @Tags("PermissionOrg")
@ -77,6 +78,10 @@ export class PermissionOrgController extends Controller {
}) })
.orderBy("orgRoot.orgRootOrder", "ASC") .orderBy("orgRoot.orgRootOrder", "ASC")
.getMany(); .getMany();
data.map((x) => ({
...x,
labelName: `${x.orgRootName} ${x.orgRootCode} ${x.orgRootShortName}`,
}));
return new HttpSuccess(data); return new HttpSuccess(data);
} }
@ -118,6 +123,14 @@ export class PermissionOrgController extends Controller {
IFNULL(current_holders.posMasterNo , '') IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`; ) LIKE :keyword`;
} }
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
// console.log(findRevision.id);
const [record, total] = await this.profileRepository const [record, total] = await this.profileRepository
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -131,24 +144,24 @@ export class PermissionOrgController extends Controller {
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3") .leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4") .leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.andWhere( .andWhere(
new Brackets((qb) => {
qb.andWhere(`current_holders.orgRevisionId = :orgRevisionId`, {
orgRevisionId: findRevision.id,
}).andWhere(
searchKeyword != undefined && searchKeyword != null && searchKeyword != "" searchKeyword != undefined && searchKeyword != null && searchKeyword != ""
? queryLike ? queryLike
: "1=1", : "1=1",
{ {
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}, },
);
}),
) )
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =
@ -299,6 +312,12 @@ export class PermissionOrgController extends Controller {
IFNULL(current_holders.posMasterNo , '') IFNULL(current_holders.posMasterNo , '')
) LIKE :keyword`; ) LIKE :keyword`;
} }
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const [record, total] = await this.permissionOrgRepository const [record, total] = await this.permissionOrgRepository
.createQueryBuilder("permissionOrg") .createQueryBuilder("permissionOrg")
.leftJoinAndSelect("permissionOrg.orgRootTree", "orgRootTree") .leftJoinAndSelect("permissionOrg.orgRootTree", "orgRootTree")
@ -325,17 +344,14 @@ export class PermissionOrgController extends Controller {
keyword: `%${requestBody.searchKeyword}%`, keyword: `%${requestBody.searchKeyword}%`,
}, },
) )
.andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
orgRevisionId: findRevision.id,
})
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((requestBody.page - 1) * requestBody.pageSize) .skip((requestBody.page - 1) * requestBody.pageSize)
.take(requestBody.pageSize) .take(requestBody.pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =

View file

@ -3760,6 +3760,12 @@ export class ProfileController extends Controller {
nodeCondition = "current_holders.orgChild4Id = :nodeId"; nodeCondition = "current_holders.orgChild4Id = :nodeId";
} }
nodeCondition = nodeCondition + nodeAll; nodeCondition = nodeCondition + nodeAll;
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const [record, total] = await this.profileRepo const [record, total] = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -3811,17 +3817,14 @@ export class ProfileController extends Controller {
.andWhere(nodeCondition, { .andWhere(nodeCondition, {
nodeId: nodeId, nodeId: nodeId,
}) })
.andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
orgRevisionId: findRevision.id,
})
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const posExecutive = const posExecutive =
@ -4114,6 +4117,12 @@ export class ProfileController extends Controller {
nodeCondition = "current_holders.orgChild4Id = :nodeId"; nodeCondition = "current_holders.orgChild4Id = :nodeId";
} }
nodeCondition = nodeCondition + nodeAll; nodeCondition = nodeCondition + nodeAll;
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const [record, total] = await this.profileRepo const [record, total] = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")
.leftJoinAndSelect("profile.posLevel", "posLevel") .leftJoinAndSelect("profile.posLevel", "posLevel")
@ -4215,17 +4224,14 @@ export class ProfileController extends Controller {
.andWhere(nodeCondition, { .andWhere(nodeCondition, {
nodeId: nodeId, nodeId: nodeId,
}) })
.andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
orgRevisionId: findRevision.id,
})
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const posExecutive = const posExecutive =

View file

@ -1420,6 +1420,12 @@ export class ProfileEmployeeController extends Controller {
nodeCondition = "current_holders.orgChild4Id = :nodeId"; nodeCondition = "current_holders.orgChild4Id = :nodeId";
} }
nodeCondition = nodeCondition + nodeAll; nodeCondition = nodeCondition + nodeAll;
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const [record, total] = await this.profileRepo const [record, total] = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -1524,16 +1530,13 @@ export class ProfileEmployeeController extends Controller {
.andWhere(nodeCondition, { .andWhere(nodeCondition, {
nodeId: nodeId, nodeId: nodeId,
}) })
.andWhere(`current_holders.orgRevisionId LIKE :orgRevisionId`, {
orgRevisionId: findRevision.id,
})
.orderBy("current_holders.posMasterNo", "ASC") .orderBy("current_holders.posMasterNo", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount(); .getManyAndCount();
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
}
const data = await Promise.all( const data = await Promise.all(
record.map((_data) => { record.map((_data) => {
const shortName = const shortName =