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

Refactor workflows endpoints for user management #2676

Merged

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Jan 13, 2022

  • POST /workflows
  • GET /workflows/:id
  • GET /workflows
  • PATCH /workflows/:id
  • DELETE /workflows/:id
  • GET /active
  • GET /active/error/:id

Pinned chokidar to fix build: #2696

Comment on lines +836 to +853
return {
id: id.toString(),
...rest,
tags: tags?.map(({ id, ...rest }) => ({ id: id.toString(), ...rest })) ?? [],
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying instead of mutating here is inefficient, but TS is right to complain about forcing the field type change without adjusting the type in the model, and the model's field type should not be adjusted - it should reflect the column type.

Hence I think we need to have workflow ID and tag ID types in the FE match exactly our class models to stop doing this needless copy or mutation work - this applies to other workflow endpoints as well.

if (userId) {
queryBuilder.innerJoin('w.shared', 'shared');
queryBuilder.andWhere('shared.user = :userId', { userId });
async getActiveWorkflows(user?: User): Promise<IWorkflowDb[]> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, optional user since getActiveWorkflows() is used without arg by removeAll(), which is used in start.ts, ActiveWorkflowRunner.ts, and TestWebhooks.ts. Delving there would increase the scope of the PR.

@ivov ivov added feature Large self-contained feature n8n team Authored by the n8n team labels Jan 13, 2022
} else {
const shared = await Db.collections.SharedWorkflow!.find({
relations: ['workflow'],
where: whereClause({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have possibly additional filters to this whereClause allowing us to use active = true as part of it. This would reduce the need for the accumulator below without sacrificing re-usability.

I know the whereClause function already expects a third optional argument so maybe we should rethink how this can work.

Let me know if you think we should change this now or merge first and then make all changes at once when refactoring code to centralize these helpers into a model-like class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, let's do away with reduce() and keep the filters flexible, ideally merging first and then refactoring, so that we have a full view of all the call variants that we need to account for in UserManagementModel.

@krynble krynble force-pushed the user-management-backend-workflows-endpoints branch from c206a9e to 6a753a3 Compare January 20, 2022 15:37
@krynble krynble merged commit d1ba976 into user-management-backend Jan 20, 2022
@krynble krynble deleted the user-management-backend-workflows-endpoints branch January 20, 2022 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Large self-contained feature n8n team Authored by the n8n team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants