Retrieving keywords APIs
We will need to create a new controller and service in the keyword module to support retrieving keywords. We want to allow the UI to list all keywords, get a specific keyword, and get a list of “hot keywords.” Let’s create the service first.
@
Injectable
()
export
class
KeywordService
implements
IKeywordService
{
constructor
(
@
Inject
(
'KeywordRepository'
)
private
readonly
keywordRepository
:typeof
Keyword
,
@
Inject
(
'KeywordEntryRepository'
)
private
readonly
keywordEntryRepository
:typeof
KeywordEntry
)
{
}
public
async
findAll
(
search?
:string
,
limit?
:number
)
:
Promise
<
Array
<
Keyword
>>
{
let
options
:IFindOptions
<
Keyword
>
=
{};
if
(
search
)
{
if
(
!
limit
||
limit
<
1
||
limit
===
NaN
)
{
limit
=
10
;
}
options
=
{
where
:
{
keyword
:
{
[
Op
.
like
]
:
`
%
$
{
search
}
%
...