-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added multiple /tags endpoints
- Loading branch information
Showing
15 changed files
with
765 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const Joi = require('@hapi/joi'); | ||
|
||
const BodyDto = Joi.object({ | ||
text: Joi.string() | ||
.required() | ||
.min(3), | ||
}); | ||
|
||
const CreateTagDto = Joi.object({ | ||
query: Joi.object({}), | ||
body: BodyDto, | ||
params: Joi.object({}), | ||
}); | ||
|
||
module.exports = CreateTagDto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const Joi = require('@hapi/joi'); | ||
|
||
const ParamsDto = Joi.object({ | ||
tagId: Joi.number() | ||
.integer() | ||
.positive(), | ||
}); | ||
|
||
const QueryDto = Joi.object({ | ||
token: Joi.string(), | ||
}); | ||
|
||
const GetLogDto = Joi.object({ | ||
body: Joi.object({}), | ||
params: ParamsDto, | ||
query: QueryDto, | ||
}); | ||
|
||
module.exports = GetLogDto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const { | ||
repositories: { | ||
TagRepository, | ||
}, | ||
utilities: { | ||
QueryBuilder, | ||
TransactionHelper, | ||
}, | ||
} = require('../../database'); | ||
|
||
/** | ||
* CreateTagUseCase | ||
*/ | ||
class CreateTagUseCase { | ||
/** | ||
* Executes this use case. | ||
* | ||
* @param {Object} dto The CreateTagDto containing all data. | ||
* @returns {Promise} Promise object represents the result of this use case. | ||
*/ | ||
async execute(dto) { | ||
const queryBuilder = new QueryBuilder(); | ||
const { body } = dto; | ||
|
||
queryBuilder.where('text', body.text); | ||
|
||
return TransactionHelper.provide(async () => { | ||
const tag = await TagRepository.findOne(queryBuilder); | ||
if (tag) { | ||
return null; | ||
} | ||
|
||
return TagRepository.insert(body); | ||
}); | ||
} | ||
} | ||
|
||
module.exports = CreateTagUseCase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright CERN and copyright holders of ALICE O2. This software is | ||
* distributed under the terms of the GNU General Public License v3 (GPL | ||
* Version 3), copied verbatim in the file "COPYING". | ||
* | ||
* See http://alice-o2.web.cern.ch/license for full licensing information. | ||
* | ||
* In applying this license CERN does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an Intergovernmental Organization | ||
* or submit itself to any jurisdiction. | ||
*/ | ||
|
||
const { | ||
repositories: { | ||
LogRepository, | ||
TagRepository, | ||
}, | ||
utilities: { | ||
QueryBuilder, | ||
TransactionHelper, | ||
}, | ||
} = require('../../database'); | ||
|
||
/** | ||
* GetLogsByTagUseCase | ||
*/ | ||
class GetLogsByTagUseCase { | ||
/** | ||
* Executes this use case. | ||
* | ||
* @param {Object} dto The GetTagDto containing all data. | ||
* @returns {Promise} Promise object represents the result of this use case. | ||
*/ | ||
async execute(dto) { | ||
const queryBuilder = new QueryBuilder(); | ||
const { params } = dto; | ||
const { tagId } = params; | ||
|
||
queryBuilder.where('id', tagId); | ||
return TransactionHelper.provide(async () => { | ||
const tag = await TagRepository.findOne(queryBuilder); | ||
return tag ? LogRepository.findAllByTagId(tag.id) : null; | ||
}); | ||
} | ||
} | ||
|
||
module.exports = GetLogsByTagUseCase; |
Oops, something went wrong.