From ed537aa72f35ec8f70d083604f17c4750e29592c Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 30 Sep 2024 09:44:43 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20call=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 4 +- src/controllers/ProfileEmployeeController.ts | 4 +- src/interfaces/call-api.ts | 45 +------------------- 3 files changed, 6 insertions(+), 47 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 8427b28f..ba3719d5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -136,7 +136,7 @@ export class ProfileController extends Controller { let ImgUrl: any; if (profile?.avatar != null && profile?.avatarName != null) { await new CallAPI() - .GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) + .GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) .then(async (x) => { ImgUrl = x.downloadUrl; }) @@ -287,7 +287,7 @@ export class ProfileController extends Controller { let ImgUrl: any; if (profiles?.avatar != null && profiles?.avatarName != null) { await new CallAPI() - .GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) + .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) .then(async (x) => { ImgUrl = x.downloadUrl; }) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ee34a68f..cc534965 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -142,7 +142,7 @@ export class ProfileEmployeeController extends Controller { let ImgUrl: any; if (profile?.avatar != null && profile?.avatarName != null) { await new CallAPI() - .GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) + .GetData(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) .then(async (x) => { ImgUrl = x.downloadUrl; }) @@ -297,7 +297,7 @@ export class ProfileEmployeeController extends Controller { let ImgUrl: any; if (profiles?.avatar != null && profiles?.avatarName != null) { await new CallAPI() - .GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) + .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) .then(async (x) => { ImgUrl = x.downloadUrl; }) diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 277a26c1..1989aeed 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -1,31 +1,7 @@ -import { - Controller, - Request, - Get, - Post, - Put, - Delete, - Patch, - Route, - Security, - Tags, - Path, -} from "tsoa"; +import { Path } from "tsoa"; import axios from "axios"; -import HttpError from "./http-error"; -import { CreateProfileSalary, ProfileSalary } from "../entities/ProfileSalary"; -import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; -import { RequestWithUser } from "../middlewares/user"; -import HttpStatus from "./http-status"; -import HttpSuccess from "./http-success"; -import permission from "./permission"; -import { AppDataSource } from "../database/data-source"; -import { Profile } from "../entities/Profile"; class CallAPI { - private profileRepo = AppDataSource.getRepository(Profile); - private salaryRepo = AppDataSource.getRepository(ProfileSalary); - private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); //Get public async GetData(request: any, @Path() path: any) { const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); @@ -33,7 +9,7 @@ class CallAPI { try { const response = await axios.get(url, { headers: { - Authorization: `${token}`.includes("Bearer "), + Authorization: `${token}`, "Content-Type": "application/json", api_key: process.env.API_KEY, }, @@ -43,23 +19,6 @@ class CallAPI { throw error; } } - //Get (response.data) - public async GetData2(request: any, @Path() path: any) { - const token = "Bearer " + request.headers.authorization.replace("Bearer ", ""); - const url = process.env.API_URL + path; - try { - const response = await axios.get(url, { - headers: { - Authorization: `${token}`.includes("Bearer "), - "Content-Type": "application/json", - api_key: process.env.API_KEY, - }, - }); - return response.data; - } catch (error) { - throw error; - } - } //Post public async PostData(request: any, @Path() path: any, sendData: any) { const token = "Bearer " + request.headers.authorization.replace("Bearer ", "");