ผูกสิดข้อมูลหลัก
This commit is contained in:
parent
f9fce4ba25
commit
92b2291c4b
15 changed files with 702 additions and 514 deletions
|
|
@ -69,7 +69,7 @@ export class kpiCapacityController extends Controller {
|
||||||
},
|
},
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionCreate(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionCreate(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiCapacity = Object.assign(new KpiCapacity(), {
|
const kpiCapacity = Object.assign(new KpiCapacity(), {
|
||||||
type: requestBody.type,
|
type: requestBody.type,
|
||||||
name: requestBody.name,
|
name: requestBody.name,
|
||||||
|
|
@ -134,7 +134,7 @@ export class kpiCapacityController extends Controller {
|
||||||
},
|
},
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionUpdate(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -285,7 +285,8 @@ export class kpiCapacityController extends Controller {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
async GetKpiCapacityById(@Path() id: string) {
|
async GetKpiCapacityById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
select: ["type", "name", "description"],
|
select: ["type", "name", "description"],
|
||||||
|
|
@ -315,11 +316,13 @@ export class kpiCapacityController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listKpiCapacity(
|
async listKpiCapacity(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("type") type?: string,
|
@Query("type") type?: string,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
|
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
|
||||||
.createQueryBuilder("kpiCapacity")
|
.createQueryBuilder("kpiCapacity")
|
||||||
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")
|
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")
|
||||||
|
|
@ -360,7 +363,7 @@ export class kpiCapacityController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiCapacity(@Path() id: string, @Request() request: RequestWithUser) {
|
async deleteKpiCapacity(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
const kpiCapacity = await this.kpiCapacityRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,12 @@
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
Post,
|
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
|
|
@ -18,7 +14,7 @@ import {
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Like, Not } from "typeorm";
|
import { Like } from "typeorm";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiEvaluation, updateKpiEvaluation } from "../entities/kpiEvaluation";
|
import { KpiEvaluation, updateKpiEvaluation } from "../entities/kpiEvaluation";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
|
@ -43,7 +39,7 @@ export class kpiEvaluationController extends Controller {
|
||||||
@Body() requestBody: updateKpiEvaluation[],
|
@Body() requestBody: updateKpiEvaluation[],
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionUpdate(request, "SYS_EVA_COMPETENCY");
|
||||||
const updatedIds: string[] = [];
|
const updatedIds: string[] = [];
|
||||||
|
|
||||||
for (const item of requestBody) {
|
for (const item of requestBody) {
|
||||||
|
|
@ -70,10 +66,12 @@ export class kpiEvaluationController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listKpiEvaluation(
|
async listKpiEvaluation(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
let whereClause: any = {};
|
let whereClause: any = {};
|
||||||
|
|
||||||
if (keyword !== undefined && keyword !== "") {
|
if (keyword !== undefined && keyword !== "") {
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,8 @@ export class kpiGroupController extends Controller {
|
||||||
@Example({
|
@Example({
|
||||||
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
||||||
})
|
})
|
||||||
async createKpiGroup(
|
async createKpiGroup(@Body() requestBody: createKpiGroup, @Request() request: RequestWithUser) {
|
||||||
@Body() requestBody: createKpiGroup,
|
await new permission().PermissionCreate(request, "SYS_EVA_COMPETENCY");
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionCreate(request,"SYS_EVA_COMPETENCY");
|
|
||||||
const kpiGroup = Object.assign(new KpiGroup(), requestBody);
|
const kpiGroup = Object.assign(new KpiGroup(), requestBody);
|
||||||
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
|
@ -75,7 +72,7 @@ export class kpiGroupController extends Controller {
|
||||||
@Body() requestBody: updateKpiGroup,
|
@Body() requestBody: updateKpiGroup,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionUpdate(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiGroup = await this.kpiGroupRepository.findOne({
|
const kpiGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -86,7 +83,7 @@ export class kpiGroupController extends Controller {
|
||||||
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
const chkkpinameGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
nameGroupKPI: requestBody.nameGroupKPI,
|
nameGroupKPI: requestBody.nameGroupKPI,
|
||||||
id: Not(id)
|
id: Not(id),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (chkkpinameGroup) {
|
if (chkkpinameGroup) {
|
||||||
|
|
@ -107,7 +104,8 @@ export class kpiGroupController extends Controller {
|
||||||
@Example({
|
@Example({
|
||||||
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
||||||
})
|
})
|
||||||
async KpiGroupById(@Path() id: string) {
|
async KpiGroupById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiGroup = await this.kpiGroupRepository.findOne({
|
const kpiGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
select: ["nameGroupKPI"],
|
select: ["nameGroupKPI"],
|
||||||
|
|
@ -124,7 +122,7 @@ export class kpiGroupController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiGroup(@Path() id: string, @Request() request: RequestWithUser) {
|
async deleteKpiGroup(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request,"SYS_EVA_COMPETENCY");
|
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiGroup = await this.kpiGroupRepository.findOne({
|
const kpiGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -143,10 +141,12 @@ export class kpiGroupController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listKpiGroup(
|
async listKpiGroup(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
let whereClause: any = {};
|
let whereClause: any = {};
|
||||||
|
|
||||||
if (keyword !== undefined && keyword !== "") {
|
if (keyword !== undefined && keyword !== "") {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
|
|
@ -18,9 +17,9 @@ import {
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { Like, Not, In, Brackets } from "typeorm";
|
import { In, Brackets } from "typeorm";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiLink, createKpiLink, updateKpiLink } from "../entities/kpiLink";
|
import { KpiLink, createKpiLink } from "../entities/kpiLink";
|
||||||
import { KpiGroup } from "../entities/kpiGroup";
|
import { KpiGroup } from "../entities/kpiGroup";
|
||||||
import { KpiCapacity } from "../entities/kpiCapacity";
|
import { KpiCapacity } from "../entities/kpiCapacity";
|
||||||
import { Position } from "../entities/position";
|
import { Position } from "../entities/position";
|
||||||
|
|
@ -165,7 +164,8 @@ export class kpiLinkController extends Controller {
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async KpiLinkById(@Path() id: string) {
|
async KpiLinkById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
const kpiLink = await this.kpiLinkRepository.findOne({
|
const kpiLink = await this.kpiLinkRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: ["positions", "kpiCapacitys", "kpiGroup"],
|
relations: ["positions", "kpiCapacitys", "kpiGroup"],
|
||||||
|
|
@ -224,10 +224,12 @@ export class kpiLinkController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listKpiLink(
|
async listKpiLink(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||||
const [_kpiLink, _total] = await AppDataSource.getRepository(KpiLink)
|
const [_kpiLink, _total] = await AppDataSource.getRepository(KpiLink)
|
||||||
.createQueryBuilder("kpiLink")
|
.createQueryBuilder("kpiLink")
|
||||||
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
|
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,8 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -22,7 +20,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
import { KpiPlan, createKpiPlan, updateKpiPlan } from "../entities/kpiPlan";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
import { KpiPeriod } from "../entities/kpiPeriod";
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
||||||
import { Brackets, IsNull, Not } from "typeorm";
|
import { Brackets, IsNull } from "typeorm";
|
||||||
import { KpiPlanHistory } from "../entities/kpiPlanHistory";
|
import { KpiPlanHistory } from "../entities/kpiPlanHistory";
|
||||||
import { KpiSpecial } from "../entities/kpiSpecial";
|
import { KpiSpecial } from "../entities/kpiSpecial";
|
||||||
import { KpiRole } from "../entities/kpiRole";
|
import { KpiRole } from "../entities/kpiRole";
|
||||||
|
|
@ -48,11 +46,8 @@ export class kpiPlanController extends Controller {
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
async createKpiPlan(
|
async createKpiPlan(@Body() requestBody: createKpiPlan, @Request() request: RequestWithUser) {
|
||||||
@Body() requestBody: createKpiPlan,
|
await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR");
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionCreate(request,"SYS_EVA_INDICATOR");
|
|
||||||
const kpiPlan = Object.assign(new KpiPlan(), requestBody);
|
const kpiPlan = Object.assign(new KpiPlan(), requestBody);
|
||||||
if (requestBody.year != null && requestBody.period != null) {
|
if (requestBody.year != null && requestBody.period != null) {
|
||||||
const kpiPeriod = await this.kpiPeriodRepository
|
const kpiPeriod = await this.kpiPeriodRepository
|
||||||
|
|
@ -212,7 +207,7 @@ export class kpiPlanController extends Controller {
|
||||||
@Body() requestBody: updateKpiPlan,
|
@Body() requestBody: updateKpiPlan,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionUpdate(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -294,7 +289,8 @@ export class kpiPlanController extends Controller {
|
||||||
* @param id Guid, *Id ตัวชี้วัดตามแผนฯ
|
* @param id Guid, *Id ตัวชี้วัดตามแผนฯ
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetKpiPlanById(@Path() id: string) {
|
async GetKpiPlanById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: { kpiPeriod: true },
|
relations: { kpiPeriod: true },
|
||||||
|
|
@ -398,6 +394,7 @@ export class kpiPlanController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("search")
|
@Post("search")
|
||||||
async listKpiPlan(
|
async listKpiPlan(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: {
|
requestBody: {
|
||||||
page: number;
|
page: number;
|
||||||
|
|
@ -411,6 +408,7 @@ export class kpiPlanController extends Controller {
|
||||||
// isNull?: boolean | false;
|
// isNull?: boolean | false;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
let condition = "";
|
let condition = "";
|
||||||
let parameters: any = {};
|
let parameters: any = {};
|
||||||
if (requestBody.isAll === false) {
|
if (requestBody.isAll === false) {
|
||||||
|
|
@ -506,7 +504,7 @@ export class kpiPlanController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiPlan(@Path() id: string, @Request() request: RequestWithUser) {
|
async deleteKpiPlan(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionDelete(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiPlan = await this.kpiPlanRepository.findOne({
|
const kpiPlan = await this.kpiPlanRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -592,7 +590,8 @@ export class kpiPlanController extends Controller {
|
||||||
* @param id Guid, *Id ประวัดิตัวชี้วัดตามแผน
|
* @param id Guid, *Id ประวัดิตัวชี้วัดตามแผน
|
||||||
*/
|
*/
|
||||||
@Get("history/{id}")
|
@Get("history/{id}")
|
||||||
async GetHistory(@Path() id: string) {
|
async GetHistory(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiPlanHistory = await this.kpiPlanHistoryRepository.find({
|
const kpiPlanHistory = await this.kpiPlanHistoryRepository.find({
|
||||||
where: { kpiPlanId: id },
|
where: { kpiPlanId: id },
|
||||||
order: {
|
order: {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import {
|
||||||
updateKpiUserReasonEvaluation,
|
updateKpiUserReasonEvaluation,
|
||||||
} from "../entities/kpiUserEvaluationReasonCapacity";
|
} from "../entities/kpiUserEvaluationReasonCapacity";
|
||||||
import { KpiUserEvaluationReasonDevelopment } from "../entities/kpiUserEvaluationReasonDevelopment";
|
import { KpiUserEvaluationReasonDevelopment } from "../entities/kpiUserEvaluationReasonDevelopment";
|
||||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
|
||||||
import { KpiUserRole } from "../entities/kpiUserRole";
|
import { KpiUserRole } from "../entities/kpiUserRole";
|
||||||
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
|
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
|
||||||
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
|
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,8 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -44,11 +42,8 @@ export class kpiRoleController extends Controller {
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
async createKpiRole(
|
async createKpiRole(@Body() requestBody: createKpiRole, @Request() request: RequestWithUser) {
|
||||||
@Body() requestBody: createKpiRole,
|
await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR");
|
||||||
@Request() request: RequestWithUser,
|
|
||||||
) {
|
|
||||||
await new permission().PermissionCreate(request,"SYS_EVA_INDICATOR");
|
|
||||||
const kpiRole = Object.assign(new KpiRole(), requestBody);
|
const kpiRole = Object.assign(new KpiRole(), requestBody);
|
||||||
if (requestBody.year != null && requestBody.period != null) {
|
if (requestBody.year != null && requestBody.period != null) {
|
||||||
const kpiPeriod = await this.kpiPeriodRepository
|
const kpiPeriod = await this.kpiPeriodRepository
|
||||||
|
|
@ -205,7 +200,7 @@ export class kpiRoleController extends Controller {
|
||||||
@Body() requestBody: updateKpiRole,
|
@Body() requestBody: updateKpiRole,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionUpdate(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -269,7 +264,8 @@ export class kpiRoleController extends Controller {
|
||||||
* @param id Guid, *Id ตัวชี้วัดตามตำแหน่ง
|
* @param id Guid, *Id ตัวชี้วัดตามตำแหน่ง
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetKpiRoleById(@Path() id: string) {
|
async GetKpiRoleById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: { kpiPeriod: true },
|
relations: { kpiPeriod: true },
|
||||||
|
|
@ -343,6 +339,7 @@ export class kpiRoleController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("search")
|
@Post("search")
|
||||||
async listKpiRole(
|
async listKpiRole(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: {
|
requestBody: {
|
||||||
page: number;
|
page: number;
|
||||||
|
|
@ -357,6 +354,7 @@ export class kpiRoleController extends Controller {
|
||||||
// isNull?: boolean | false;
|
// isNull?: boolean | false;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
let condition = "";
|
let condition = "";
|
||||||
let parameters: any = {};
|
let parameters: any = {};
|
||||||
if (requestBody.isAll === false) {
|
if (requestBody.isAll === false) {
|
||||||
|
|
@ -468,8 +466,8 @@ export class kpiRoleController extends Controller {
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiRole(@Path() id: string,@Request() request: RequestWithUser) {
|
async deleteKpiRole(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionDelete(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiRole = await this.kpiRoleRepository.findOne({
|
const kpiRole = await this.kpiRoleRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -559,7 +557,8 @@ export class kpiRoleController extends Controller {
|
||||||
* @param id Guid, *Id ประวัดิตัวชี้วัดตามตำแหน่ง
|
* @param id Guid, *Id ประวัดิตัวชี้วัดตามตำแหน่ง
|
||||||
*/
|
*/
|
||||||
@Get("history/{id}")
|
@Get("history/{id}")
|
||||||
async GetHistory(@Path() id: string) {
|
async GetHistory(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiRoleHistory = await this.kpiRoleHistoryRepository.find({
|
const kpiRoleHistory = await this.kpiRoleHistoryRepository.find({
|
||||||
where: { kpiRoleId: id },
|
where: { kpiRoleId: id },
|
||||||
order: {
|
order: {
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,15 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiSpecial, CreateKpiSpecial, UpdateKpiSpecial } from "../entities/kpiSpecial";
|
import { KpiSpecial, CreateKpiSpecial, UpdateKpiSpecial } from "../entities/kpiSpecial";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import { Brackets, Not } from "typeorm";
|
||||||
import { Brackets, IsNull, Like, Not } from "typeorm";
|
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
@Route("api/v1/kpi/special")
|
@Route("api/v1/kpi/special")
|
||||||
|
|
@ -45,7 +42,7 @@ export class kpiSpecialController extends Controller {
|
||||||
@Body() requestBody: CreateKpiSpecial,
|
@Body() requestBody: CreateKpiSpecial,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionCreate(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR");
|
||||||
const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({
|
const chk_kpiSpecial = await this.kpiSpecialRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
including: String(requestBody.including),
|
including: String(requestBody.including),
|
||||||
|
|
@ -82,7 +79,7 @@ export class kpiSpecialController extends Controller {
|
||||||
@Body() requestBody: UpdateKpiSpecial,
|
@Body() requestBody: UpdateKpiSpecial,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionUpdate(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiSpecial = await this.kpiSpecialRepository.findOne({
|
const kpiSpecial = await this.kpiSpecialRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -115,7 +112,8 @@ export class kpiSpecialController extends Controller {
|
||||||
* @param id Guid, *Id ตัวชี้วัด Special
|
* @param id Guid, *Id ตัวชี้วัด Special
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async GetKpiSpecialById(@Path() id: string) {
|
async GetKpiSpecialById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
const KpiSpecial = await this.kpiSpecialRepository.findOne({
|
const KpiSpecial = await this.kpiSpecialRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
@ -156,6 +154,7 @@ export class kpiSpecialController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("search")
|
@Post("search")
|
||||||
async listKpiSpecial(
|
async listKpiSpecial(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
@Body()
|
@Body()
|
||||||
requestBody: {
|
requestBody: {
|
||||||
page: number;
|
page: number;
|
||||||
|
|
@ -165,6 +164,7 @@ export class kpiSpecialController extends Controller {
|
||||||
keyword?: string | null;
|
keyword?: string | null;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
let _data = await new permission().PermissionList(request, "SYS_EVA_INDICATOR");
|
||||||
// let condition: any = {};
|
// let condition: any = {};
|
||||||
// if (requestBody.keyword !== undefined && requestBody.keyword !== "") {
|
// if (requestBody.keyword !== undefined && requestBody.keyword !== "") {
|
||||||
// condition = {
|
// condition = {
|
||||||
|
|
@ -216,8 +216,8 @@ export class kpiSpecialController extends Controller {
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiSpecial(@Path() id: string, @Request() request: RequestWithUser,) {
|
async deleteKpiSpecial(@Path() id: string, @Request() request: RequestWithUser) {
|
||||||
await new permission().PermissionDelete(request,"SYS_EVA_INDICATOR");
|
await new permission().PermissionDelete(request, "SYS_EVA_INDICATOR");
|
||||||
const kpiSpecial = await this.kpiSpecialRepository.findOne({
|
const kpiSpecial = await this.kpiSpecialRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,9 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
ArrayValidator,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -23,11 +21,9 @@ import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiCapacity } from "../entities/kpiCapacity";
|
import { KpiCapacity } from "../entities/kpiCapacity";
|
||||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
import { KpiUserCapacity, KpiUserCapacityDataPoint } from "../entities/kpiUserCapacity";
|
import { KpiUserCapacity, KpiUserCapacityDataPoint } from "../entities/kpiUserCapacity";
|
||||||
import { Like, In, Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
import { Double } from "typeorm/browser";
|
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { request } from "axios";
|
|
||||||
|
|
||||||
@Route("api/v1/kpi/user/capacity")
|
@Route("api/v1/kpi/user/capacity")
|
||||||
@Tags("kpiUserCapacity")
|
@Tags("kpiUserCapacity")
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import {
|
||||||
} from "../entities/kpiUserDevelopment";
|
} from "../entities/kpiUserDevelopment";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
import { Not, Like, Brackets } from "typeorm";
|
import { Not, Brackets } from "typeorm";
|
||||||
import { DevelopmentProject } from "../entities/developmentProject";
|
import { DevelopmentProject } from "../entities/developmentProject";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,9 @@ import {
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
ArrayValidator,
|
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -31,7 +29,7 @@ import {
|
||||||
updateKpiUserReqEditEvaluation,
|
updateKpiUserReqEditEvaluation,
|
||||||
updateKpiUserResultEvaluation,
|
updateKpiUserResultEvaluation,
|
||||||
} from "../entities/kpiUserEvaluation";
|
} from "../entities/kpiUserEvaluation";
|
||||||
import { Like, In, Brackets, IsNull, Not } from "typeorm";
|
import { In, Brackets, IsNull, Not } from "typeorm";
|
||||||
import CallAPI from "../interfaces/call-api";
|
import CallAPI from "../interfaces/call-api";
|
||||||
import { KpiCapacity } from "../entities/kpiCapacity";
|
import { KpiCapacity } from "../entities/kpiCapacity";
|
||||||
import { Position } from "../entities/position";
|
import { Position } from "../entities/position";
|
||||||
|
|
@ -249,27 +247,27 @@ export class KpiUserEvaluationController extends Controller {
|
||||||
qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", {
|
qb.orWhere("kpiUserEvaluation.prefix LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.firstName LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.firstName LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.lastName LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.lastName LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.org LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.org LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.position LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.position LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.posTypeName LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.posTypeName LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere("kpiUserEvaluation.posLevelName LIKE :keyword", {
|
.orWhere("kpiUserEvaluation.posLevelName LIKE :keyword", {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
})
|
||||||
.orWhere(conditionFullName, {
|
.orWhere(conditionFullName, {
|
||||||
keyword: `%${requestBody.keyword}%`,
|
keyword: `%${requestBody.keyword}%`,
|
||||||
})
|
});
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,12 @@ import {
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,12 @@ import {
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
|
||||||
Route,
|
Route,
|
||||||
Security,
|
Security,
|
||||||
Tags,
|
Tags,
|
||||||
Body,
|
Body,
|
||||||
Path,
|
Path,
|
||||||
Request,
|
Request,
|
||||||
Example,
|
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,16 +1,3 @@
|
||||||
import {
|
|
||||||
Controller,
|
|
||||||
Request,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Delete,
|
|
||||||
Patch,
|
|
||||||
Route,
|
|
||||||
Security,
|
|
||||||
Tags,
|
|
||||||
Path,
|
|
||||||
} from "tsoa";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import CallAPI from "./call-api";
|
import CallAPI from "./call-api";
|
||||||
|
|
@ -26,23 +13,166 @@ class CheckAuth {
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
await new CallAPI()
|
return await new CallAPI()
|
||||||
.GetData(req, "/org/permission")
|
.GetData(req, "/org/permission")
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
let permission = false;
|
let permission = false;
|
||||||
let role = x.roles.find((x: any) => x.authSysId == system);
|
let role = x.roles.find((x: any) => x.authSysId == system);
|
||||||
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
||||||
|
if (role.attrOwnership == "OWNER") return "OWNER";
|
||||||
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
||||||
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
||||||
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
||||||
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
||||||
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
||||||
if (role.attrOwnership == "OWNER") permission = true;
|
|
||||||
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
||||||
return role.attrPrivilege;
|
return role.attrPrivilege;
|
||||||
})
|
})
|
||||||
.catch((x) => {
|
.catch((x) => {
|
||||||
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
if (x.status != undefined) {
|
||||||
|
throw new HttpError(x.status, x.message);
|
||||||
|
} else {
|
||||||
|
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public async PermissionOrg(req: RequestWithUser, system: string, action: string) {
|
||||||
|
if (
|
||||||
|
req.headers.hasOwnProperty("api_key") &&
|
||||||
|
req.headers["api_key"] &&
|
||||||
|
req.headers["api_key"] == process.env.API_KEY
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return await new CallAPI()
|
||||||
|
.GetData(req, "/org/permission/org")
|
||||||
|
.then(async (x) => {
|
||||||
|
let privilege = null;
|
||||||
|
if (action.trim().toLocaleUpperCase() == "CREATE")
|
||||||
|
privilege = await this.PermissionCreate(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "DELETE")
|
||||||
|
privilege = await this.PermissionDelete(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "GET")
|
||||||
|
privilege = await this.PermissionGet(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "LIST")
|
||||||
|
privilege = await this.PermissionList(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "UPDATE")
|
||||||
|
privilege = await this.PermissionUpdate(req, system);
|
||||||
|
|
||||||
|
let data: any = {
|
||||||
|
root: [null],
|
||||||
|
child1: [null],
|
||||||
|
child2: [null],
|
||||||
|
child3: [null],
|
||||||
|
child4: [null],
|
||||||
|
};
|
||||||
|
let node = 4;
|
||||||
|
if (x.orgChild1Id == null) {
|
||||||
|
node = 0;
|
||||||
|
} else if (x.orgChild2Id == null) {
|
||||||
|
node = 1;
|
||||||
|
} else if (x.orgChild3Id == null) {
|
||||||
|
node = 2;
|
||||||
|
} else if (x.orgChild4Id == null) {
|
||||||
|
node = 3;
|
||||||
|
}
|
||||||
|
if (privilege == "ROOT") {
|
||||||
|
data = {
|
||||||
|
root: [x.orgRootId],
|
||||||
|
child1: null,
|
||||||
|
child2: null,
|
||||||
|
child3: null,
|
||||||
|
child4: null,
|
||||||
|
};
|
||||||
|
} else if (privilege == "CHILD") {
|
||||||
|
data = {
|
||||||
|
root: node >= 0 ? [x.orgRootId] : null,
|
||||||
|
child1: node >= 1 ? [x.orgChild1Id] : null,
|
||||||
|
child2: node >= 2 ? [x.orgChild2Id] : null,
|
||||||
|
child3: node >= 3 ? [x.orgChild3Id] : null,
|
||||||
|
child4: node >= 4 ? [x.orgChild4Id] : null,
|
||||||
|
};
|
||||||
|
} else if (privilege == "NORMAL") {
|
||||||
|
data = {
|
||||||
|
root: [x.orgRootId],
|
||||||
|
child1: [x.orgChild1Id],
|
||||||
|
child2: [x.orgChild2Id],
|
||||||
|
child3: [x.orgChild3Id],
|
||||||
|
child4: [x.orgChild4Id],
|
||||||
|
};
|
||||||
|
} else if (privilege == "SPECIFIC") {
|
||||||
|
} else if (privilege == "OWNER") {
|
||||||
|
data = {
|
||||||
|
root: null,
|
||||||
|
child1: null,
|
||||||
|
child2: null,
|
||||||
|
child3: null,
|
||||||
|
child4: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.catch((x) => {
|
||||||
|
if (x.status != undefined) {
|
||||||
|
throw new HttpError(x.status, x.message);
|
||||||
|
} else {
|
||||||
|
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public async PermissionOrgByUser(
|
||||||
|
req: RequestWithUser,
|
||||||
|
system: string,
|
||||||
|
action: string,
|
||||||
|
profileId: string,
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
req.headers.hasOwnProperty("api_key") &&
|
||||||
|
req.headers["api_key"] &&
|
||||||
|
req.headers["api_key"] == process.env.API_KEY
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return await new CallAPI()
|
||||||
|
.GetData(req, `/org/permission/user/${profileId}`)
|
||||||
|
.then(async (x) => {
|
||||||
|
let org = {
|
||||||
|
root: [null],
|
||||||
|
child1: [null],
|
||||||
|
child2: [null],
|
||||||
|
child3: [null],
|
||||||
|
child4: [null],
|
||||||
|
};
|
||||||
|
if (action.trim().toLocaleUpperCase() == "CREATE")
|
||||||
|
org = await this.PermissionOrgCreate(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "DELETE")
|
||||||
|
org = await this.PermissionOrgDelete(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "GET")
|
||||||
|
org = await this.PermissionOrgGet(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "LIST")
|
||||||
|
org = await this.PermissionOrgList(req, system);
|
||||||
|
if (action.trim().toLocaleUpperCase() == "UPDATE")
|
||||||
|
org = await this.PermissionOrgUpdate(req, system);
|
||||||
|
|
||||||
|
if (org.root != null) if (x.orgRootId != org.root[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||||
|
if (org.child1 != null)
|
||||||
|
if (x.orgChild1Id != org.child1[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||||
|
if (org.child2 != null)
|
||||||
|
if (x.orgChild2Id != org.child2[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||||
|
if (org.child3 != null)
|
||||||
|
if (x.orgChild3Id != org.child3[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||||
|
if (org.child4 != null)
|
||||||
|
if (x.orgChild4Id != org.child4[0]) throw "ไม่มีสิทธิ์เข้าถึงข้อมูล";
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.catch((x) => {
|
||||||
|
if (x.status != undefined) {
|
||||||
|
throw new HttpError(x.status, x.message);
|
||||||
|
} else {
|
||||||
|
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||||
|
|
@ -60,6 +190,38 @@ class CheckAuth {
|
||||||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||||
return await this.Permission(req, system, "UPDATE");
|
return await this.Permission(req, system, "UPDATE");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async PermissionOrgCreate(req: RequestWithUser, system: string) {
|
||||||
|
return await this.PermissionOrg(req, system, "CREATE");
|
||||||
|
}
|
||||||
|
public async PermissionOrgDelete(req: RequestWithUser, system: string) {
|
||||||
|
return await this.PermissionOrg(req, system, "DELETE");
|
||||||
|
}
|
||||||
|
public async PermissionOrgGet(req: RequestWithUser, system: string) {
|
||||||
|
return await this.PermissionOrg(req, system, "GET");
|
||||||
|
}
|
||||||
|
public async PermissionOrgList(req: RequestWithUser, system: string) {
|
||||||
|
return await this.PermissionOrg(req, system, "LIST");
|
||||||
|
}
|
||||||
|
public async PermissionOrgUpdate(req: RequestWithUser, system: string) {
|
||||||
|
return await this.PermissionOrg(req, system, "UPDATE");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async PermissionOrgUserCreate(req: RequestWithUser, system: string, profileId: string) {
|
||||||
|
return await this.PermissionOrgByUser(req, system, "CREATE", profileId);
|
||||||
|
}
|
||||||
|
public async PermissionOrgUserDelete(req: RequestWithUser, system: string, profileId: string) {
|
||||||
|
return await this.PermissionOrgByUser(req, system, "DELETE", profileId);
|
||||||
|
}
|
||||||
|
public async PermissionOrgUserGet(req: RequestWithUser, system: string, profileId: string) {
|
||||||
|
return await this.PermissionOrgByUser(req, system, "GET", profileId);
|
||||||
|
}
|
||||||
|
public async PermissionOrgUserList(req: RequestWithUser, system: string, profileId: string) {
|
||||||
|
return await this.PermissionOrgByUser(req, system, "LIST", profileId);
|
||||||
|
}
|
||||||
|
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) {
|
||||||
|
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CheckAuth;
|
export default CheckAuth;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue