service call service
This commit is contained in:
parent
5a92e60e0e
commit
666a7f8021
5 changed files with 63 additions and 60 deletions
|
|
@ -24,6 +24,7 @@ class CallAPI {
|
|||
headers: {
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
|
|
@ -38,16 +39,16 @@ class CallAPI {
|
|||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -60,6 +61,7 @@ class CallAPI {
|
|||
headers: {
|
||||
Authorization: `${token}`,
|
||||
"Content-Type": "application/json",
|
||||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
|
|
@ -75,17 +77,17 @@ class CallAPI {
|
|||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,13 @@ import HttpStatus from "./http-status";
|
|||
|
||||
class CheckAuth {
|
||||
public async Permission(req: RequestWithUser, system: string, action: string) {
|
||||
if (
|
||||
req.headers.hasOwnProperty("api_key") &&
|
||||
req.headers["api_key"] &&
|
||||
req.headers["api_key"] == process.env.API_KEY
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
await new CallAPI()
|
||||
.GetData(req, "/org/permission")
|
||||
.then((x) => {
|
||||
|
|
@ -39,19 +46,19 @@ class CheckAuth {
|
|||
});
|
||||
}
|
||||
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "CREATE");
|
||||
return await this.Permission(req, system, "CREATE");
|
||||
}
|
||||
public async PermissionDelete(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "DELETE");
|
||||
return await this.Permission(req, system, "DELETE");
|
||||
}
|
||||
public async PermissionGet(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "GET");
|
||||
return await this.Permission(req, system, "GET");
|
||||
}
|
||||
public async PermissionList(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "LIST");
|
||||
return await this.Permission(req, system, "LIST");
|
||||
}
|
||||
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||
this.Permission(req, system, "UPDATE");
|
||||
return await this.Permission(req, system, "UPDATE");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue