forked from Sunbird-Obsrv/obsrv-api-service
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #221 from Rakshitha-D/connector_list
#OBS-I145: Connector Read api
- Loading branch information
Showing
6 changed files
with
549 additions
and
94 deletions.
There are no files selected for viewing
226 changes: 192 additions & 34 deletions
226
api-service/postman-collection/updated_v2_collection.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
api-service/src/controllers/ConnectorsRead/ConnectorsRead.ts
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,22 @@ | ||
import { Request, Response } from "express"; | ||
import { obsrvError } from "../../types/ObsrvError"; | ||
import { ResponseHandler } from "../../helpers/ResponseHandler"; | ||
import httpStatus from "http-status"; | ||
import { connectorService } from "../../services/ConnectorService"; | ||
import _ from "lodash"; | ||
|
||
const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "licence", "owner", "iconurl", "status", "ui_spec", "created_by", "updated_by", "created_date", "updated_date", "live_date"]; | ||
|
||
const connectorsRead = async (req: Request, res: Response) => { | ||
const { id } = req.params; | ||
const { mode } = req.query; | ||
const isEditMode = _.toLower(_.toString(mode)) === "edit" | ||
const status = isEditMode ? "Draft" : "Live" | ||
const connector = await connectorService.getConnector({ id, status }, defaultFields) | ||
if (!connector) { | ||
throw obsrvError("", "CONNECTOR_NOT_FOUND", `Connector not found: ${id}`, "NOT_FOUND", 404); | ||
} | ||
ResponseHandler.successResponse(req, res, { status: httpStatus.OK, data: connector }); | ||
} | ||
|
||
export default connectorsRead; |
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
Oops, something went wrong.