From b93fb6c1e5c1aa1c699648bf45444e7e2821ab86 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 28 Feb 2024 11:27:52 +0700 Subject: [PATCH] no message --- src/controllers/SalaryPeriodController.ts | 7 ++-- src/interfaces/call-api.ts | 49 ++++++++++++++--------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index ff4597b..83035d0 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -27,6 +27,7 @@ import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; +import CallAPI from "../interfaces/call-api"; @Route("api/v1/salary/period") @Tags("Salary") @@ -774,9 +775,9 @@ export class SalaryPeriodController extends Controller { await this.salaryOrgRepository.remove(salaryOrg); await this.salaryProfileRepository.remove(salaryProfile); - let orgs: any; - let orgProfiles: any; - let revisionId: any; + let orgs = await new CallAPI().GetData(request, "org/active/root/id"); + let orgProfiles = await new CallAPI().GetData(request, "org/profile/salary/gen"); + let revisionId = await new CallAPI().GetData(request, "org/revision/latest"); salaryPeriod.revisionId = revisionId; await this.salaryPeriodRepository.save(salaryPeriod); diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 49473f0..ddf535e 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -1,24 +1,35 @@ -import { Controller, Request, Get, Post, Put, Delete, Patch, Route, Security, Tags, Path } from "tsoa"; -import axios from 'axios'; +import { + Controller, + Request, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Path, +} from "tsoa"; +import axios from "axios"; class CallAPI { - //Get - public async GetData(request: any, @Path() path: any) { - const token = request.headers.authorization; - const url = process.env.ORG_API+path; - try { - const response = await axios.get(url, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }); - return response.data; - } catch (error) { - throw error; - } + //Get + public async GetData(request: any, @Path() path: any) { + const token = request.headers.authorization; + const url = process.env.ORG_API + path; + try { + const response = await axios.get(url, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "application/json", + }, + }); + return response.data.result; + } catch (error) { + throw error; } - + } } -export default CallAPI; \ No newline at end of file +export default CallAPI;