crud development

This commit is contained in:
Bright 2024-04-02 17:53:45 +07:00
parent 454cda29e5
commit 9da7f47cf6
7 changed files with 393 additions and 0 deletions

View file

@ -0,0 +1,51 @@
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.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;
}
}
//Post
public async PostData(request: any, @Path() path: any, sendData: any) {
const token = request.headers.authorization;
const url = process.env.API + path;
try {
const response = await axios.post(url, sendData, {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
return response.data.result;
} catch (error) {
throw error;
}
}
}
export default CallAPI;