ehsan-dashboards/dashboards/room_service_GET.ts

88 lines
2.4 KiB
TypeScript

/**
* @swagger
* /v2/site/rooms/{id}:
* get:
* summary: Get room search results by ID
* description: Retrieves Elasticsearch search results for a specific room including related and similar rooms
* tags: [Rooms]
* security: []
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* example: 42
* description: Room ID to search for
* responses:
* 200:
* description: Search results retrieved successfully
* content:
* application/json:
* schema:
* type: object
* properties:
* success:
* type: integer
* example: 0
* data:
* type: object
* properties:
* items:
* type: array
* description: Array of related rooms
* 404:
* description: No data found for this room
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* example:
* success: 1
* data: null
* error: 'No data found'
* 500:
* $ref: '#/components/responses/InternalServerError'
*/
import { Client } from "@elastic/elasticsearch";
import { ServiceMethod, ThrowError } from "handler";
import { getElasticSearch } from "models/helper/search/getElasticSearch";
const elasticsearchClient = new Client({
node: process.env.ELASTIC,
});
const get: ServiceMethod = async (req, res, next) => {
try {
const [search] = await Promise.all([
getElasticSearch(elasticsearchClient, {
rid: req.pathQuery?.id,
compact: false
}),
]);
// Check if search items are empty and return 404 if no results
if (!search.items || search.items.length === 0) {
return res.status(404).send({
success: 1,
data: null,
error: "No data found",
});
}
res.send({
data: {
...search,
items: [...search.items],
},
success: 0,
});
} catch (error: any) {
res.status(500).send({
success: 1,
data: null,
error: error instanceof ThrowError ? error.prepare(res.__).message : [],
});
}
};
export default [get];