From 9ead3c82978ab0aeddffb74f21a380ad11a61aa0 Mon Sep 17 00:00:00 2001 From: MauritsioRK Date: Thu, 7 May 2020 22:28:54 +0200 Subject: [PATCH] Chore: code cleanup, update openapi spec --- lib/application/usecases/log/GetLogUseCase.js | 8 ++++---- lib/database/repositories/LogRepository.js | 4 ++-- lib/public/Model.js | 2 +- lib/public/views/Logs/Logs.js | 6 +++--- spec/openapi.yaml | 5 ++++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/application/usecases/log/GetLogUseCase.js b/lib/application/usecases/log/GetLogUseCase.js index 6612b45a46..f4f560cddd 100644 --- a/lib/application/usecases/log/GetLogUseCase.js +++ b/lib/application/usecases/log/GetLogUseCase.js @@ -22,9 +22,9 @@ const { } = require('../../../database'); /** - * GetLogsUseCase + * GetLogUseCase */ -class GetLogsUseCase extends IUseCase { +class GetLogUseCase extends IUseCase { /** * Executes this use case. * @@ -32,8 +32,8 @@ class GetLogsUseCase extends IUseCase { * @returns {Promise} Promise object represents the result of this use case. */ async execute(id) { - return TransactionHelper.provide(() => LogRepository.find(id)); + return TransactionHelper.provide(() => LogRepository.findOneById(id)); } } -module.exports = GetLogsUseCase; +module.exports = GetLogUseCase; diff --git a/lib/database/repositories/LogRepository.js b/lib/database/repositories/LogRepository.js index 5836a77792..715da6f9b6 100644 --- a/lib/database/repositories/LogRepository.js +++ b/lib/database/repositories/LogRepository.js @@ -43,9 +43,9 @@ class LogRepository extends ILogRepository { * @param {Number} id ID primary key of the entity to find. * @returns {Promise|Null} Promise object representing the full mock data */ - async find(id) { + async findOneById(id) { const result = await Log.findByPk(id); - return result ? [LogAdapter.toEntity(result)] : null; + return result ? LogAdapter.toEntity(result) : null; } /** diff --git a/lib/public/Model.js b/lib/public/Model.js index 554fefc73e..0fdf1f2fc2 100644 --- a/lib/public/Model.js +++ b/lib/public/Model.js @@ -59,7 +59,7 @@ export default class Model extends Observable { this.logs.fetchAllLogs(); break; case 'entry': - this.logs.fetchLog(this.router.params.id); + this.logs.fetchOneLog(this.router.params.id); break; default: this.router.go('?page=home'); diff --git a/lib/public/views/Logs/Logs.js b/lib/public/views/Logs/Logs.js index 4b82d5030b..d7e82bd49f 100644 --- a/lib/public/views/Logs/Logs.js +++ b/lib/public/views/Logs/Logs.js @@ -55,14 +55,14 @@ export default class Overview extends Observable { * @param {Number} id The ID of the log to be found * @returns {undefined} Injects the data object with the response data */ - async fetchLog(id) { + async fetchOneLog(id) { // Do not call this endpoint again if we already have all the logs - if (this.data.length < 1) { + if (this.data && this.data.length < 1) { const response = await fetchClient(`/api/logs/${id}`, { method: 'GET' }); const result = await response.json(); if (result.data) { - this.data = result.data; + this.data = [result.data]; this.error = false; } else { this.error = true; diff --git a/spec/openapi.yaml b/spec/openapi.yaml index 86e5c99464..69540ca51f 100644 --- a/spec/openapi.yaml +++ b/spec/openapi.yaml @@ -69,7 +69,10 @@ components: type: object properties: data: - type: array + type: + oneOf: + - array + - object required: - data DeployInformation: