api apikeyhistory
This commit is contained in:
parent
f7653aa4cf
commit
62f803f3e3
5 changed files with 87 additions and 2 deletions
|
|
@ -128,4 +128,56 @@ export class ApiKeyController extends Controller {
|
|||
});
|
||||
return new HttpSuccess(apiName);
|
||||
}
|
||||
|
||||
/**
|
||||
* API สร้าง Api Key
|
||||
*
|
||||
* @summary สร้าง Api Key (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post("history")
|
||||
async getHistory(
|
||||
@Body()
|
||||
requestBody: {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
apiNameId: string | null;
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
if (requestBody.apiNameId) {
|
||||
const apiName = await this.apiNameRepository.findOne({
|
||||
where: { id: requestBody.apiNameId },
|
||||
});
|
||||
if (apiName)
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไท้พบรายการ Web Service นี้ในระบบ");
|
||||
}
|
||||
const apiHistory = await AppDataSource.getRepository(ApiHistory)
|
||||
.createQueryBuilder("apiHistory")
|
||||
.leftJoinAndSelect("apiHistory.apiKey", "apiKey")
|
||||
.leftJoinAndSelect("apiHistory.apiName", "apiName")
|
||||
.andWhere(requestBody.apiNameId ? `apiHistory.apiNameId = :apiNameId` : "1=1", {
|
||||
apiNameId: requestBody.apiNameId,
|
||||
})
|
||||
.andWhere(
|
||||
`apiHistory.createdAt >= DATE(:startDate) AND apiHistory.createdAt <= DATE(:endDate)`,
|
||||
{
|
||||
startDate: new Date(requestBody.startDate),
|
||||
endDate: new Date(
|
||||
requestBody.endDate.setDate(new Date(requestBody.endDate).getDate() + 1),
|
||||
),
|
||||
},
|
||||
)
|
||||
.orderBy("apiHistory.createdAt", "DESC")
|
||||
.getMany();
|
||||
const result = apiHistory.map((x) => ({
|
||||
id: x.id,
|
||||
apiName: x.apiName.name,
|
||||
apiKey: x.apiKey.name,
|
||||
createdAt: x.createdAt,
|
||||
ipApi: x.ipApi,
|
||||
}));
|
||||
|
||||
return new HttpSuccess(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue