Merge branch 'nice' into develop
# Conflicts: # src/controllers/KpiUserCapacityController.ts # src/controllers/KpiUserEvaluationController.ts
This commit is contained in:
commit
dfd9ebb3c1
21 changed files with 526 additions and 236 deletions
|
|
@ -12,6 +12,7 @@ import {
|
|||
Path,
|
||||
} from "tsoa";
|
||||
import axios from "axios";
|
||||
import { addLogSequence } from "./utils";
|
||||
|
||||
class CallAPI {
|
||||
//Get
|
||||
|
|
@ -26,8 +27,28 @@ class CallAPI {
|
|||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "success",
|
||||
description: "connected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(response.data.result),
|
||||
},
|
||||
});
|
||||
return response.data.result;
|
||||
} catch (error) {
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "error",
|
||||
description: "unconnected",
|
||||
request: {
|
||||
method: "GET",
|
||||
url: url,
|
||||
response: JSON.stringify(error),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,8 +64,30 @@ class CallAPI {
|
|||
api_key: process.env.API_KEY,
|
||||
},
|
||||
});
|
||||
addLogSequence(request, {
|
||||
action: "request",
|
||||
status: "success",
|
||||
description: "connected",
|
||||
request: {
|
||||
method: "POST",
|
||||
url: url,
|
||||
payload: JSON.stringify(sendData),
|
||||
response: JSON.stringify(response.data.result),
|
||||
},
|
||||
});
|
||||
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),
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
37
src/interfaces/utils.ts
Normal file
37
src/interfaces/utils.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
export type DataDiff = {
|
||||
before: any;
|
||||
after: any;
|
||||
};
|
||||
|
||||
export type LogSequence = {
|
||||
action: string;
|
||||
status: "success" | "error";
|
||||
description: string;
|
||||
query?: any;
|
||||
request?: {
|
||||
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
||||
url?: string;
|
||||
payload?: string;
|
||||
response?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
||||
req.app.locals.logData.dataDiff = {
|
||||
before: JSON.stringify(data.before),
|
||||
after: JSON.stringify(data.after),
|
||||
};
|
||||
}
|
||||
|
||||
export function addLogSequence(req: RequestWithUser, data: LogSequence) {
|
||||
if (!req?.app?.locals?.logData?.sequence) {
|
||||
req.app.locals.logData.sequence = [];
|
||||
}
|
||||
req.app.locals.logData.sequence = req.app.locals.logData.sequence.concat(data);
|
||||
}
|
||||
|
||||
export function editLogSequence(req: RequestWithUser, index: number, data: LogSequence) {
|
||||
req.app.locals.logData.sequence[index] = data;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue