Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-08-09 10:18:12 +07:00
commit a91410dcdc
55 changed files with 971 additions and 292 deletions

View file

@ -27,6 +27,25 @@ class Extension {
}
return null;
}
public static ConvertToDateTimeV2(value: any) {
if (value != "" && value != null) {
if (value.toString().length > 4) {
const chars = value.split("/");
let year = Number(chars[2]) + 1900;
let month = Extension.MonthToNumber(chars[1]);
return new Date(year, month, chars[0]);
} else {
if (value.toString().length == 4) {
if (value < 1800) {
return null;
} else if (value > 2500) {
return new Date(value - 543, 0, 1);
}
}
}
}
return null;
}
public static CheckRelationship(value: any) {
if (value != "" && value != null) {
@ -76,6 +95,36 @@ class Extension {
return "";
}
}
public static MonthToNumber(value: string) {
switch (value.trim().toUpperCase()) {
case "JAN":
return 0;
case "FEB":
return 1;
case "MAR":
return 2;
case "APR":
return 3;
case "MAY":
return 4;
case "JUN":
return 5;
case "JUL":
return 6;
case "AUG":
return 7;
case "SEP":
return 8;
case "OCT":
return 9;
case "NOV":
return 10;
case "DEC":
return 11;
default:
return 0;
}
}
public static ToThaiShortMonth(value: number) {
switch (value) {

View file

@ -0,0 +1,58 @@
import {
Controller,
Request,
Get,
Post,
Put,
Delete,
Patch,
Route,
Security,
Tags,
Path,
} from "tsoa";
import axios from "axios";
import { RequestWithUser } from "../middlewares/user";
import CallAPI from "./call-api";
import HttpError from "./http-error";
import HttpStatus from "./http-status";
class CheckAuth {
public async Permission(req: RequestWithUser, system: string, action: string) {
await new CallAPI()
.GetData(req, "/org/permission")
.then((x) => {
let permission = false;
let role = x.roles.find((x: any) => x.authSysId == system);
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
if (role.attrOwnership == "OWNER") permission = true;
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
return role.attrPrivilege;
})
.catch((x) => {
throw new HttpError(HttpStatus.FORBIDDEN, x);
});
}
public async PermissionCreate(req: RequestWithUser, system: string) {
this.Permission(req, system, "CREATE");
}
public async PermissionDelete(req: RequestWithUser, system: string) {
this.Permission(req, system, "DELETE");
}
public async PermissionGet(req: RequestWithUser, system: string) {
this.Permission(req, system, "GET");
}
public async PermissionList(req: RequestWithUser, system: string) {
this.Permission(req, system, "LIST");
}
public async PermissionUpdate(req: RequestWithUser, system: string) {
this.Permission(req, system, "UPDATE");
}
}
export default CheckAuth;