From ff51d685e0e01ab3a20587dffbbeb609567ee280 Mon Sep 17 00:00:00 2001 From: tmaog Date: Mon, 11 Mar 2024 10:30:41 +0100 Subject: [PATCH 1/2] type change --- src/models/flow.model.ts | 5 +++++ src/types/PolyglotFlow.ts | 1 + 2 files changed, 6 insertions(+) diff --git a/src/models/flow.model.ts b/src/models/flow.model.ts index 860f070..5c658c6 100644 --- a/src/models/flow.model.ts +++ b/src/models/flow.model.ts @@ -27,6 +27,11 @@ export const flowSchema = new mongoose.Schema({ type: String, required: true }, + publish: { + type: Boolean, + required: true, + default: false, + }, learningPathId: { type: String }, diff --git a/src/types/PolyglotFlow.ts b/src/types/PolyglotFlow.ts index 47227d8..d7f2265 100644 --- a/src/types/PolyglotFlow.ts +++ b/src/types/PolyglotFlow.ts @@ -10,6 +10,7 @@ export type PolyglotFlowInfo = { author: string; learningPathId: string; description: string; + publish: boolean; tags: string[]; execution: PolyglotExecutionData; } From 56ecd237127e48bea1e9ae9ac431b452625b3c11 Mon Sep 17 00:00:00 2001 From: tmaog Date: Sat, 16 Mar 2024 16:23:28 +0100 Subject: [PATCH 2/2] api for publish and --- src/controllers/flows.controllers.ts | 21 +++++++++++++++++++++ src/routes/flows.routes.ts | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/controllers/flows.controllers.ts b/src/controllers/flows.controllers.ts index 6fef406..5a67c96 100644 --- a/src/controllers/flows.controllers.ts +++ b/src/controllers/flows.controllers.ts @@ -207,6 +207,7 @@ export async function updateFlow(req: Request, res: Response, next: NextFunction // await body("flow", "Flow is required").exists().run(req); try { + req.body.publish=false; const flow = await updateFlowQuery(req.params.id, req.body); if (!flow) { @@ -220,6 +221,26 @@ export async function updateFlow(req: Request, res: Response, next: NextFunction } +//function to publish the flow (change publish to true) +export async function publishFlow(req: Request, res: Response, next : NextFunction) { + + try { + + req.body.publish=true; + + const flows = await updateFlowQuery(req.params.id, req.body); + + if (!flows) { + return res.status(404).send() + } + + return res.status(200).send(flows); + } catch (err) { + return next(err); + } + +} + export async function createFlow(req: Request, res: Response, next : NextFunction) { try { const newFlow = req.body as PolyglotFlowInfo; diff --git a/src/routes/flows.routes.ts b/src/routes/flows.routes.ts index b312d0f..5301e8a 100644 --- a/src/routes/flows.routes.ts +++ b/src/routes/flows.routes.ts @@ -25,5 +25,7 @@ router.route("/:ctxId/run") // version of notebook with only ctx information router.route("/:id/:ctxId/run") //2nd version of notebook with ctx information and flowId .get(FlowController.downloadNotebookVSC2); +router.route("/:id/publish") //function to publish the flow + .put(checkAuth, FlowController.publishFlow); export default router; \ No newline at end of file