Compare commits

...

7 commits
v1.1.4 ... dev

Author SHA1 Message Date
harid
eb705231b8 Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 58s
2026-03-20 18:05:06 +07:00
harid
f8f928866e no message 2026-03-20 18:04:53 +07:00
harid
8f82ddef4c Merge branch 'develop-Bright' into develop 2026-03-20 18:02:03 +07:00
harid
5e7fa19248 แก้ไข middleware log ให้ใช้จาก token #223 2026-03-20 17:55:10 +07:00
harid
e3ae765da9 Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
2026-03-20 09:59:41 +07:00
harid
4ea611feaf Merge branch 'develop-Bright' into develop 2026-03-20 09:59:28 +07:00
harid
d74a8e14d8 Migrate table portfolio add field position&posLevel 2026-03-20 09:59:18 +07:00
5 changed files with 78 additions and 18 deletions

View file

@ -23,7 +23,7 @@ import { CreatePortfolio, Portfolio } from "../entities/Portfolio";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/development/portfolio")
@Tags("Portfolio")
@Security("bearerAuth")
@ -104,19 +104,21 @@ export class PortfolioController extends Controller {
}
/**
* API ..7/..1
* API .
*
* @summary ..7/..1
* @summary .
*
*/
@Get("kk1/{keycloak}")
async GetPortfolio(@Path() keycloak: string, @Request() request: RequestWithUser) {
const _portfolio = await this.portfolioRepository.find({
where: { createdUserId: keycloak },
select: [
"name",
"createdAt"
],
select: {
name: true,
createdAt: true,
position: true,
posLevel: true
},
order: { createdAt: "DESC" },
});
const result =
@ -124,7 +126,8 @@ export class PortfolioController extends Controller {
name: x.name,
year: x.createdAt.getFullYear() > 2500
? x.createdAt.getFullYear()
: x.createdAt.getFullYear()+543
: x.createdAt.getFullYear()+543,
position: `${x.position ?? ""}${x.posLevel ?? ""}`.trim()
}));
return new HttpSuccess(result);
}
@ -153,7 +156,20 @@ export class PortfolioController extends Controller {
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
let _position:string=""
let _posLevel:string=""
await new CallAPI()
.GetData(request, `/org/dotnet/by-keycloak/${request.user.sub}`)
.then((x) => {
_position = x.position;
_posLevel = x.posLevel;
})
.catch(() => {});
const before = null;
_portfolio.position = _position;
_portfolio.posLevel = _posLevel;
_portfolio.createdUserId = request.user.sub;
_portfolio.createdFullName = request.user.name;
_portfolio.lastUpdateUserId = request.user.sub;

View file

@ -17,6 +17,21 @@ export class Portfolio extends EntityBase {
default: null,
})
detail: string;
@Column({
nullable: true,
comment: "ตำแหน่ง",
default: null,
})
position: string;
@Column({
nullable: true,
comment: "ระดับตำแหน่ง",
default: null,
})
posLevel: string;
}
export class CreatePortfolio {
@Column()

View file

@ -67,6 +67,16 @@ export async function expressAuthentication(
request.app.locals.logData.userName = payload.name;
request.app.locals.logData.user = payload.preferred_username;
// เก็บค่า profileId และ orgRootDnaId จาก token (ใช้ค่าว่างถ้าไม่มี)
request.app.locals.logData.profileId = payload.profileId ?? "";
request.app.locals.logData.orgRootDnaId = payload.orgRootDnaId ?? "";
request.app.locals.logData.orgChild1DnaId = payload.orgChild1DnaId ?? "";
request.app.locals.logData.orgChild2DnaId = payload.orgChild2DnaId ?? "";
request.app.locals.logData.orgChild3DnaId = payload.orgChild3DnaId ?? "";
request.app.locals.logData.orgChild4DnaId = payload.orgChild4DnaId ?? "";
request.app.locals.logData.empType = payload.empType ?? "";
request.app.locals.logData.prefix = payload.prefix ?? "";
return payload;
}

View file

@ -45,21 +45,24 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
if (level === 2 && res.statusCode < 400) return;
if (level === 3 && res.statusCode < 200) return;
const token = req.headers["authorization"];
let rootId = null;
// const token = req.headers["authorization"];
// let rootId = null;
try {
rootId = token
? await new permission().checkRootDna(token, req.app.locals.logData.userId)
: null;
} catch (err) {
console.warn("Error fetching rootId:", err);
}
// try {
// rootId = token
// ? await new permission().checkOrg(token, req.app.locals.logData.userId)
// : null;
// } catch (err) {
// console.warn("Error fetching rootId:", err);
// }
// Get rootId from token
const rootId = req.app.locals.logData?.orgRootDnaId;
const obj = {
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
ip: req.ip,
rootId: rootId?.rootDnaId ?? null,
rootId: rootId ?? null,
systemName: "development",
startTimeStamp: timestamp,
endTimeStamp: new Date().toISOString(),

View file

@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTablePortfolioAddFieldPosition_1773974268282 implements MigrationInterface {
name = 'UpdateTablePortfolioAddFieldPosition_1773974268282'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`portfolio\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`);
await queryRunner.query(`ALTER TABLE \`portfolio\` ADD \`posLevel\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`portfolio\` DROP COLUMN \`posLevel\``);
await queryRunner.query(`ALTER TABLE \`portfolio\` DROP COLUMN \`position\``);
}
}