forked from OneUptime/oneuptime
-
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.
- Loading branch information
Showing
10 changed files
with
191 additions
and
1 deletion.
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
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
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,26 @@ | ||
import BadDataException from 'Common/Types/Exception/BadDataException'; | ||
import ComponentMetadata from 'Common/Types/Workflow/Component'; | ||
import ComponentID from 'Common/Types/Workflow/ComponentID'; | ||
import ManualComponents from 'Common/Types/Workflow/Components/Manual'; | ||
import ComponentCode, { | ||
InitProps, | ||
} from '../ComponentCode'; | ||
|
||
export default class ManualTrigger extends ComponentCode { | ||
public constructor() { | ||
super(); | ||
const Component: ComponentMetadata | undefined = | ||
ManualComponents.find((i: ComponentMetadata) => { | ||
return i.id === ComponentID.Manual; | ||
}); | ||
|
||
if (!Component) { | ||
throw new BadDataException('Component not found.'); | ||
} | ||
this.setMetadata(Component); | ||
} | ||
|
||
public override async init(_props: InitProps): Promise<void> { | ||
// do nothing because its a manual component. | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Express, { | ||
ExpressRequest, | ||
ExpressResponse, | ||
ExpressRouter, | ||
} from 'CommonServer/Utils/Express'; | ||
import Response from 'CommonServer/Utils/Response'; | ||
import ObjectID from 'Common/Types/ObjectID'; | ||
import BadDataException from 'Common/Types/Exception/BadDataException'; | ||
import WorkflowService from 'CommonServer/Services/WorkflowService'; | ||
import Workflow from 'Model/Models/Workflow'; | ||
import ClusterKeyAuthorization from 'CommonServer/Middleware/ClusterKeyAuthorization'; | ||
import ComponentCode from 'CommonServer/Types/Workflow/ComponentCode'; | ||
import Components from 'CommonServer/Types/Workflow/Components/Index'; | ||
|
||
export default class WorkflowAPI { | ||
public router!: ExpressRouter; | ||
|
||
public constructor() { | ||
this.router = Express.getRouter(); | ||
|
||
this.router.get(`/update/:workflowId`, ClusterKeyAuthorization.isAuthorizedServiceMiddleware, this.updateWorkflow); | ||
|
||
this.router.post(`/update/:workflowId`, ClusterKeyAuthorization.isAuthorizedServiceMiddleware, this.updateWorkflow); | ||
} | ||
|
||
public async updateWorkflow( | ||
req: ExpressRequest, | ||
res: ExpressResponse | ||
): Promise<void> { | ||
// add this workflow to the run queue and return the 200 response. | ||
|
||
if (!req.params['workflowId']) { | ||
return Response.sendErrorResponse( | ||
req, | ||
res, | ||
new BadDataException('workflowId not found in URL') | ||
); | ||
} | ||
|
||
const workflow: Workflow | null = await WorkflowService.findOneById({ | ||
id: new ObjectID(req.params['workflowId']), | ||
select: { | ||
_id: true, | ||
triggerId: true, | ||
}, | ||
props: { | ||
isRoot: true, | ||
} | ||
}); | ||
|
||
if(!workflow){ | ||
return Response.sendJsonObjectResponse(req, res, { | ||
status: 'Workflow not found', | ||
}); | ||
} | ||
|
||
|
||
const componentCode: ComponentCode | undefined = Components[workflow.triggerId as string]; | ||
|
||
if(!componentCode){ | ||
return Response.sendJsonObjectResponse(req, res, { | ||
status: 'Component not found', | ||
}); | ||
} | ||
|
||
await componentCode.update({ | ||
workflowId: workflow.id! | ||
}); | ||
|
||
return Response.sendJsonObjectResponse(req, res, { | ||
status: 'Updated', | ||
}); | ||
} | ||
} |
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