mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
⚡ Add tags to /workflow
This commit is contained in:
parent
85efe0424b
commit
69dc3a6dd7
|
@ -499,6 +499,22 @@ class App {
|
|||
// Save the workflow in DB
|
||||
const result = await Db.collections.Workflow!.save(newWorkflowData);
|
||||
|
||||
const { tags } = req.body as { tags: string };
|
||||
|
||||
if (tags) {
|
||||
const tagIds = tags.split(',').map(Number);
|
||||
|
||||
for (const tagId of tagIds) {
|
||||
await TagHelpers.validateId(tagId);
|
||||
}
|
||||
|
||||
await getConnection().createQueryBuilder()
|
||||
.insert()
|
||||
.into('workflows_tags')
|
||||
.values(tags.split(',').map(tagId => ({ workflowId: result.id, tagId })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
// Convert to response format in which the id is a string
|
||||
(result as IWorkflowBase as IWorkflowResponse).id = result.id.toString();
|
||||
return result as IWorkflowBase as IWorkflowResponse;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { FindOneOptions, getConnection } from "typeorm";
|
|||
import { Db, ResponseHelper } from ".";
|
||||
|
||||
/**
|
||||
* Validate whether a tag name exists so that it cannot be used for a create/update operation.
|
||||
* Validate whether a tag name exists so that it cannot be used for a tag create or tag update operation.
|
||||
*/
|
||||
export async function validateName(name: string): Promise<void> | never {
|
||||
const findQuery = { where: { name } } as FindOneOptions;
|
||||
|
@ -14,7 +14,7 @@ export async function validateName(name: string): Promise<void> | never {
|
|||
}
|
||||
|
||||
/**
|
||||
* Validate whether a tag ID exists so that it can be used for an update operation.
|
||||
* Validate whether a tag ID exists so that it can be used for a workflow create or tag update operation.
|
||||
*/
|
||||
export async function validateId(id: number): Promise<void> | never {
|
||||
const findQuery = { where: { id } } as FindOneOptions;
|
||||
|
|
Loading…
Reference in a new issue