Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#OBS-I145: Connector Read api #221

Merged
merged 8 commits into from
Aug 1, 2024
Merged
226 changes: 192 additions & 34 deletions api-service/postman-collection/updated_v2_collection.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ResponseHandler } from "../../helpers/ResponseHandler";
import httpStatus from "http-status";
import { connectorService } from "../../services/ConnectorService";

const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "technology", "runtime", "licence", "owner", "iconurl", "status", "created_by", "updated_by", "created_date", "updated_date"];
const defaultFields = ["id", "connector_id", "name", "type", "category", "version", "description", "technology", "runtime", "licence", "owner", "iconurl", "status", "created_by", "updated_by", "created_date", "updated_date", "live_date"];

const validateRequest = (req: Request) => {
const isRequestValid: Record<string, any> = schemaValidation(req.body, ConnectorListSchema)
Expand Down
22 changes: 22 additions & 0 deletions api-service/src/controllers/ConnectorsRead/ConnectorsRead.ts
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;
2 changes: 2 additions & 0 deletions api-service/src/routes/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import datasetReset from "../controllers/DatasetReset/DatasetReset";
import DatasetExport from "../controllers/DatasetExport/DatasetExport";
import DatasetCopy from "../controllers/DatasetCopy/DatasetCopy";
import ConnectorsList from "../controllers/ConnectorsList/ConnectorsList";
import ConnectorsRead from "../controllers/ConnectorsRead/ConnectorsRead";
import DatasetImport from "../controllers/DatasetImport/DatasetImport";

export const router = express.Router();
Expand All @@ -51,6 +52,7 @@ router.post("/datasets/dataschema", setDataToRequestObject("api.datasets.datasch
router.get("/datasets/export/:dataset_id", setDataToRequestObject("api.datasets.export"), onRequest({ entity: Entity.Management }), DatasetExport);
router.post("/datasets/copy", setDataToRequestObject("api.datasets.copy"), onRequest({ entity: Entity.Management }), DatasetCopy);
router.post("/connectors/list", setDataToRequestObject("api.connectors.list"), onRequest({ entity: Entity.Management }), ConnectorsList);
router.get("/connectors/read/:id", setDataToRequestObject("api.connectors.read"), onRequest({entity: Entity.Management }), ConnectorsRead);
router.post("/datasets/import", setDataToRequestObject("api.datasets.import"), onRequest({ entity: Entity.Management }), DatasetImport);

//Wrapper Service
Expand Down
6 changes: 5 additions & 1 deletion api-service/src/services/ConnectorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { ConnectorRegistry } from "../models/ConnectorRegistry";

class ConnectorService {

findConnectors = async (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
findConnectors = (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
return ConnectorRegistry.findAll({ where, attributes, raw: true });
}

getConnector = (where?: Record<string, any>, attributes?: string[]): Promise<any> => {
return ConnectorRegistry.findOne({ where, attributes, raw: true });
}

}

export const connectorService = new ConnectorService();
Loading
Loading