Merge branch 'develop' into develop-Bright
# Conflicts: # src/controllers/ImportDataController.ts
This commit is contained in:
commit
022cc04e7b
13 changed files with 300 additions and 133 deletions
|
|
@ -22,14 +22,17 @@ import { AuthRoleAttr } from "../entities/AuthRoleAttr";
|
|||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
|
||||
const REDIS_HOST = process.env.REDIS_HOST;
|
||||
const REDIS_PORT = process.env.REDIS_PORT;
|
||||
@Route("api/v1/org/auth/authRole")
|
||||
@Tags("AuthRole")
|
||||
@Security("bearerAuth")
|
||||
export class AuthRoleController extends Controller {
|
||||
private authRoleRepo = AppDataSource.getRepository(AuthRole);
|
||||
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
|
||||
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
|
||||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster)
|
||||
private employeePosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||
private redis = require("redis");
|
||||
|
||||
@Get("list")
|
||||
public async listAuthRole() {
|
||||
|
|
@ -77,50 +80,51 @@ export class AuthRoleController extends Controller {
|
|||
}
|
||||
|
||||
@Post("govoment")
|
||||
public async AddAuthRoleGovoment(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) {
|
||||
public async AddAuthRoleGovoment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateAddAuthRole,
|
||||
) {
|
||||
let NULL_: any = null;
|
||||
let getDetail;
|
||||
|
||||
let NULL_ : any = null;
|
||||
let getDetail
|
||||
|
||||
if(body.authRoleId == "") {
|
||||
body.authRoleId = NULL_
|
||||
}
|
||||
else {
|
||||
if (body.authRoleId == "") {
|
||||
body.authRoleId = NULL_;
|
||||
} else {
|
||||
getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId });
|
||||
if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
const posMaster = await this.posMasterRepository.findOneBy({ id : body.posMasterId })
|
||||
|
||||
const posMaster = await this.posMasterRepository.findOneBy({ id: body.posMasterId });
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
||||
|
||||
posMaster.lastUpdateUserId = req.user.sub;
|
||||
posMaster.lastUpdateFullName = req.user.name;
|
||||
posMaster.authRoleId = body.authRoleId
|
||||
posMaster.authRoleId = body.authRoleId;
|
||||
await this.posMasterRepository.save(posMaster);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
@Post("employee")
|
||||
public async AddAuthRoleEmployee(@Request() req: RequestWithUser, @Body() body: CreateAddAuthRole) {
|
||||
public async AddAuthRoleEmployee(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateAddAuthRole,
|
||||
) {
|
||||
let NULL_: any = null;
|
||||
let getDetail;
|
||||
|
||||
let NULL_ : any = null;
|
||||
let getDetail
|
||||
|
||||
if(body.authRoleId == "") {
|
||||
body.authRoleId = NULL_
|
||||
}
|
||||
else {
|
||||
if (body.authRoleId == "") {
|
||||
body.authRoleId = NULL_;
|
||||
} else {
|
||||
getDetail = await this.authRoleRepo.findOneBy({ id: body.authRoleId });
|
||||
if (!getDetail) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
|
||||
const posMaster = await this.employeePosMasterRepository.findOneBy({ id : body.posMasterId })
|
||||
|
||||
const posMaster = await this.employeePosMasterRepository.findOneBy({ id: body.posMasterId });
|
||||
if (!posMaster) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
||||
|
||||
posMaster.lastUpdateUserId = req.user.sub;
|
||||
posMaster.lastUpdateFullName = req.user.name;
|
||||
posMaster.authRoleId = body.authRoleId
|
||||
posMaster.authRoleId = body.authRoleId;
|
||||
await this.employeePosMasterRepository.save(posMaster);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,33 +434,33 @@ export class ImportDataController extends Controller {
|
|||
return new HttpSuccess(result);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @summary Import Education Code
|
||||
// */
|
||||
// @Post("uploadEducation-Code")
|
||||
// @UseInterceptors(FileInterceptor("file"))
|
||||
// async UploadFileSQLEducationCode(
|
||||
// @UploadedFile() file: Express.Multer.File,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
// ) {
|
||||
// const workbook = xlsx.read(file.buffer, { type: "buffer" });
|
||||
// const sheetName = workbook.SheetNames[0]
|
||||
// const sheet = workbook.Sheets[sheetName];
|
||||
// const getExcel = xlsx.utils.sheet_to_json(sheet);
|
||||
// let educationMis_: any = [];
|
||||
/**
|
||||
* @summary Import Education Code
|
||||
*/
|
||||
@Post("uploadEducation-Code")
|
||||
@UseInterceptors(FileInterceptor("file"))
|
||||
async UploadFileSQLEducationCode(
|
||||
@UploadedFile() file: Express.Multer.File,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const workbook = xlsx.read(file.buffer, { type: "buffer" });
|
||||
const sheetName = workbook.SheetNames[0]
|
||||
const sheet = workbook.Sheets[sheetName];
|
||||
const getExcel = xlsx.utils.sheet_to_json(sheet);
|
||||
let educationMis_: any = [];
|
||||
|
||||
await Promise.all(
|
||||
getExcel.map(async (item: any) => {
|
||||
const educationMis = new EducationMis();
|
||||
educationMis.EDUCATION_CODE = item.EDUCATION_CODE;
|
||||
educationMis.EDUCATION_CODE = item.EDUCATION_CODE;
|
||||
educationMis_.push(educationMis);
|
||||
|
||||
// await Promise.all(
|
||||
// getExcel.map(async (item: any) => {
|
||||
// const educationMis = new EducationMis();
|
||||
// educationMis.EDUCATION_CODE = item.EDUCATION_CODE;
|
||||
// educationMis.EDUCATION_CODE = item.EDUCATION_CODE;
|
||||
// educationMis_.push(educationMis);
|
||||
|
||||
// }),
|
||||
// );
|
||||
// await this.educationMisRepo.save(educationMis_);
|
||||
// return new HttpSuccess(educationMis_);
|
||||
// }
|
||||
}),
|
||||
);
|
||||
await this.educationMisRepo.save(educationMis_);
|
||||
return new HttpSuccess(educationMis_);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * API upload EDU
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ import { AuthRole } from "../entities/AuthRole";
|
|||
import { AuthRoleAttr } from "../entities/AuthRoleAttr";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import { AuthSys } from "../entities/AuthSys";
|
||||
import { promisify } from "util";
|
||||
import { In } from "typeorm";
|
||||
const REDIS_HOST = process.env.REDIS_HOST;
|
||||
const REDIS_PORT = process.env.REDIS_PORT;
|
||||
|
||||
@Route("api/v1/org/permission")
|
||||
@Tags("Permission")
|
||||
|
|
@ -18,53 +23,137 @@ export class PermissionController extends Controller {
|
|||
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
||||
private authRoleRepo = AppDataSource.getRepository(AuthRole);
|
||||
private authRoleAttrRepo = AppDataSource.getRepository(AuthRoleAttr);
|
||||
private authSysRepo = AppDataSource.getRepository(AuthSys);
|
||||
private redis = require("redis");
|
||||
|
||||
@Get("")
|
||||
public async getPermission(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
select: ["id"],
|
||||
where: { keycloak: request.user.sub },
|
||||
const redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
const getAsync = promisify(redisClient.get).bind(redisClient);
|
||||
|
||||
let reply = await getAsync("role_" + request.user.sub);
|
||||
if (reply != null) {
|
||||
reply = JSON.parse(reply);
|
||||
} else {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
select: ["id"],
|
||||
where: { keycloak: request.user.sub },
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
select: ["authRoleId"],
|
||||
where: { current_holderId: profile.id },
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
const getDetail = await this.authRoleRepo.findOne({
|
||||
select: ["id", "roleName", "roleDescription"],
|
||||
where: { id: posMaster.authRoleId },
|
||||
});
|
||||
if (!getDetail) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const roleAttrData = await this.authRoleAttrRepo.find({
|
||||
select: [
|
||||
"authSysId",
|
||||
"parentNode",
|
||||
"attrOwnership",
|
||||
"attrIsCreate",
|
||||
"attrIsList",
|
||||
"attrIsGet",
|
||||
"attrIsUpdate",
|
||||
"attrIsDelete",
|
||||
"attrPrivilege",
|
||||
],
|
||||
where: { authRoleId: getDetail.id },
|
||||
});
|
||||
|
||||
reply = {
|
||||
...getDetail,
|
||||
roles: roleAttrData,
|
||||
};
|
||||
redisClient.set("role_" + request.user.sub, JSON.stringify(reply));
|
||||
}
|
||||
return new HttpSuccess(reply);
|
||||
}
|
||||
|
||||
@Get("menu")
|
||||
public async listAuthSys(@Request() request: { user: Record<string, any> }) {
|
||||
const redisClient = await this.redis.createClient({
|
||||
host: REDIS_HOST,
|
||||
port: REDIS_PORT,
|
||||
});
|
||||
const getAsync = promisify(redisClient.get).bind(redisClient);
|
||||
|
||||
let reply = await getAsync("menu_" + request.user.sub);
|
||||
if (reply != null) {
|
||||
reply = JSON.parse(reply);
|
||||
} else {
|
||||
console.log(request.user.sub);
|
||||
const profile = await this.profileRepo.findOne({
|
||||
select: ["id"],
|
||||
where: { keycloak: request.user.sub },
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
// select: ["authRoleId"],
|
||||
where: {
|
||||
current_holderId: profile.id,
|
||||
orgRevision: {
|
||||
orgRevisionIsDraft: false,
|
||||
orgRevisionIsCurrent: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งในโครงสร้าง");
|
||||
}
|
||||
|
||||
const authRole = await this.authRoleRepo.findOne({
|
||||
select: ["id"],
|
||||
where: { id: posMaster.authRoleId },
|
||||
});
|
||||
if (!authRole) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
const roleAttrData = await this.authRoleAttrRepo.find({
|
||||
select: ["authSysId"],
|
||||
where: { authRoleId: authRole.id },
|
||||
});
|
||||
|
||||
const getList = await this.authSysRepo.find({
|
||||
select: ["id", "parentId", "sysName", "sysDescription", "icon", "path", "order"],
|
||||
where: {
|
||||
id: In(roleAttrData.map((x) => x.authSysId)),
|
||||
},
|
||||
});
|
||||
|
||||
const reply = getList
|
||||
.filter((x) => x.parentId == null)
|
||||
.map((item) => {
|
||||
return {
|
||||
...item,
|
||||
children: getList
|
||||
.filter((x) => x.parentId == item.id)
|
||||
.sort((a, b) => a.order - b.order),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.order - b.order);
|
||||
console.log(JSON.stringify(reply));
|
||||
redisClient.set("menu_" + request.user.sub, 30, JSON.stringify(reply));
|
||||
}
|
||||
|
||||
const posMaster = await this.posMasterRepository.findOne({
|
||||
select: ["authRoleId"],
|
||||
where: { current_holderId: profile.id },
|
||||
});
|
||||
if (!posMaster) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลสิทธิ์");
|
||||
}
|
||||
|
||||
const getDetail = await this.authRoleRepo.findOne({
|
||||
select: ["roleName", "roleDescription"],
|
||||
where: { id: posMaster.authRoleId },
|
||||
});
|
||||
if (!getDetail) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
const roleAttrData = await this.authRoleAttrRepo.find({
|
||||
select: [
|
||||
"authSysId",
|
||||
"parentNode",
|
||||
"attrOwnership",
|
||||
"attrIsCreate",
|
||||
"attrIsList",
|
||||
"attrIsGet",
|
||||
"attrIsUpdate",
|
||||
"attrIsDelete",
|
||||
"attrPrivilege",
|
||||
],
|
||||
where: { authRoleId: getDetail.id },
|
||||
});
|
||||
|
||||
const formattedData = {
|
||||
...getDetail,
|
||||
roleAttributes: roleAttrData,
|
||||
};
|
||||
|
||||
return new HttpSuccess(formattedData);
|
||||
return new HttpSuccess(reply);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,26 +52,20 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
if (status != "" && status != null) {
|
||||
qb.andWhere("ProfileEdit.status = :status", { status: status });
|
||||
}
|
||||
qb.andWhere("ProfileEdit.profileEmployeeId = :profileEmployeeId", { profileEmployeeId: profile.id });
|
||||
qb.andWhere("ProfileEdit.profileEmployeeId = :profileEmployeeId", {
|
||||
profileEmployeeId: profile.id,
|
||||
});
|
||||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.topic LIKE :keyword"
|
||||
: "1=1",
|
||||
qb.where(keyword != "" && keyword != null ? "ProfileEdit.topic LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(
|
||||
keyword != "" && keyword != null ? "ProfileEdit.detail LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.detail LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||
|
|
@ -118,22 +112,14 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
})
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.where(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.topic LIKE :keyword"
|
||||
: "1=1",
|
||||
qb.where(keyword != "" && keyword != null ? "ProfileEdit.topic LIKE :keyword" : "1=1", {
|
||||
keyword: `%${keyword}%`,
|
||||
}).orWhere(
|
||||
keyword != "" && keyword != null ? "ProfileEdit.detail LIKE :keyword" : "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
.orWhere(
|
||||
keyword != "" && keyword != null
|
||||
? "ProfileEdit.detail LIKE :keyword"
|
||||
: "1=1",
|
||||
{
|
||||
keyword: `%${keyword}%`,
|
||||
},
|
||||
)
|
||||
);
|
||||
}),
|
||||
)
|
||||
.orderBy("ProfileEdit.createdAt", "ASC")
|
||||
|
|
@ -162,7 +148,7 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Get("{Id}")
|
||||
public async detailProfileByIdEdit(@Path() Id: string) {
|
||||
public async detailProfileEmployeeByIdEdit(@Path() Id: string) {
|
||||
const getProfileEdit = await this.profileEditRepository.findOne({
|
||||
where: { id: Id },
|
||||
});
|
||||
|
|
@ -233,7 +219,7 @@ export class ProfileEditEmployeeController extends Controller {
|
|||
) {
|
||||
// const record = await this.profileEditRepository.findOneBy({ id: editId });
|
||||
const record = await this.profileEditRepository.findOne({
|
||||
where: { id: editId }
|
||||
where: { id: editId },
|
||||
});
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
|
|
|||
BIN
src/controllers/backup-employee-temp-bmaStatic40k.xlsx
Normal file
BIN
src/controllers/backup-employee-temp-bmaStatic40k.xlsx
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue