-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aura-nw/feat/search-product
[DEV] Feat/search product
- Loading branch information
Showing
5 changed files
with
111 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Hapi from '@hapi/hapi'; | ||
import { queryProducts } from '#common/elastic-search'; | ||
import Joi from 'joi'; | ||
|
||
export const searchProductionRoute: Hapi.ServerRoute = { | ||
method: 'GET', | ||
path: '/search', | ||
options: { | ||
description: 'Search product by name, owner', | ||
notes: 'Search product by name, owner', | ||
tags: ['api', 'Product'], | ||
plugins: { | ||
'hapi-swagger': {}, | ||
}, | ||
validate: { | ||
query: Joi.object({ | ||
name: Joi.string().required().example('Product name'), | ||
limit: Joi.number().max(100).default(10).example(10), | ||
}), | ||
}, | ||
cache: { | ||
// client side cache for 30s | ||
expiresIn: 30 * 1000, | ||
privacy: 'private', | ||
}, | ||
// response: { schema: Joi.object({}) }, | ||
}, | ||
handler: (request: Hapi.Request) => { | ||
const { name, limit } = request.query; | ||
console.log('request.query', request.query); | ||
return queryProducts({ keyword: name, limit }); | ||
}, | ||
}; |
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