Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 48s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 48s
This commit is contained in:
commit
c4faf65050
3 changed files with 10 additions and 75 deletions
|
|
@ -12,7 +12,7 @@ import {
|
||||||
Path,
|
Path,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { addLogSequence, safeStringify } from "./utils";
|
import { addLogSequence } from "./utils";
|
||||||
|
|
||||||
class CallAPI {
|
class CallAPI {
|
||||||
//Get
|
//Get
|
||||||
|
|
@ -34,7 +34,7 @@ class CallAPI {
|
||||||
request: {
|
request: {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: url,
|
url: url,
|
||||||
response: safeStringify(response.data.result),
|
response: JSON.stringify(response.data.result),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return response.data.result;
|
return response.data.result;
|
||||||
|
|
@ -46,7 +46,7 @@ class CallAPI {
|
||||||
request: {
|
request: {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: url,
|
url: url,
|
||||||
response: safeStringify(error),
|
response: JSON.stringify(error),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
|
|
@ -71,8 +71,8 @@ class CallAPI {
|
||||||
request: {
|
request: {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: url,
|
url: url,
|
||||||
payload: safeStringify(sendData),
|
payload: JSON.stringify(sendData),
|
||||||
response: safeStringify(response.data.result),
|
response: JSON.stringify(response.data.result),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return response.data.result;
|
return response.data.result;
|
||||||
|
|
@ -84,8 +84,8 @@ class CallAPI {
|
||||||
request: {
|
request: {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: url,
|
url: url,
|
||||||
payload: safeStringify(sendData),
|
payload: JSON.stringify(sendData),
|
||||||
response: safeStringify(error),
|
response: JSON.stringify(error),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
|
|
@ -183,42 +183,7 @@ class CheckAuth {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// public async checkOrg(token: any, keycloakId: string) {
|
public async checkOrg(token: any, keycloakId: string) {
|
||||||
// const redisClient = await this.redis.createClient({
|
|
||||||
// host: process.env.REDIS_HOST,
|
|
||||||
// port: process.env.REDIS_PORT,
|
|
||||||
// })
|
|
||||||
// const getAsync = promisify(redisClient.get).bind(redisClient)
|
|
||||||
// try {
|
|
||||||
// let reply = await getAsync("org_" + keycloakId)
|
|
||||||
// if (reply != null) {
|
|
||||||
// reply = JSON.parse(reply)
|
|
||||||
// } else {
|
|
||||||
// if (!keycloakId) throw new Error("No KeycloakId provided")
|
|
||||||
// const x = await new CallAPI().GetData(
|
|
||||||
// {
|
|
||||||
// headers: { authorization: token },
|
|
||||||
// },
|
|
||||||
// `/org/permission/checkOrg/${keycloakId}`,
|
|
||||||
// false
|
|
||||||
// )
|
|
||||||
|
|
||||||
// const data = {
|
|
||||||
// orgRootId: x.orgRootId,
|
|
||||||
// orgChild1Id: x.orgChild1Id,
|
|
||||||
// orgChild2Id: x.orgChild2Id,
|
|
||||||
// orgChild3Id: x.orgChild3Id,
|
|
||||||
// orgChild4Id: x.orgChild4Id,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return data
|
|
||||||
// }
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error("Error calling API:", error)
|
|
||||||
// throw error
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
public async checkOrg(token: any, keycloakId: string) {
|
|
||||||
try {
|
try {
|
||||||
// Validate required environment variables
|
// Validate required environment variables
|
||||||
const REDIS_HOST = process.env.REDIS_HOST;
|
const REDIS_HOST = process.env.REDIS_HOST;
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
||||||
typeof data.after === "object"
|
typeof data.after === "object"
|
||||||
) {
|
) {
|
||||||
req.app.locals.logData.dataDiff = {
|
req.app.locals.logData.dataDiff = {
|
||||||
before: safeStringify(data.before),
|
before: JSON.stringify(data.before),
|
||||||
after: safeStringify(data.after),
|
after: JSON.stringify(data.after),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
console.error("Invalid data provided: both before and after must be valid objects.");
|
console.error("Invalid data provided: both before and after must be valid objects.");
|
||||||
|
|
@ -45,33 +45,3 @@ export function addLogSequence(req: RequestWithUser, data: LogSequence) {
|
||||||
export function editLogSequence(req: RequestWithUser, index: number, data: LogSequence) {
|
export function editLogSequence(req: RequestWithUser, index: number, data: LogSequence) {
|
||||||
req.app.locals.logData.sequence[index] = data;
|
req.app.locals.logData.sequence[index] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ปลอดภัยกว่า JSON.stringify()
|
|
||||||
* - กัน circular reference
|
|
||||||
* - จำกัดความลึก
|
|
||||||
* - return string แน่นอนเสมอ
|
|
||||||
*/
|
|
||||||
export function safeStringify(obj: any, space?: number): string {
|
|
||||||
const cache = new WeakSet();
|
|
||||||
|
|
||||||
try {
|
|
||||||
return JSON.stringify(
|
|
||||||
obj,
|
|
||||||
(key, value) => {
|
|
||||||
// ป้องกัน circular reference
|
|
||||||
if (typeof value === "object" && value !== null) {
|
|
||||||
if (cache.has(value)) {
|
|
||||||
return "[Circular]";
|
|
||||||
}
|
|
||||||
cache.add(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
space,
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("⚠️ safeStringify error:", err);
|
|
||||||
return "[Unserializable object]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue