Add tags to /workflow

This commit is contained in:
Iván Ovejero 2021-04-12 16:30:47 +02:00
parent 85efe0424b
commit 69dc3a6dd7
2 changed files with 18 additions and 2 deletions

View file

@ -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;

View file

@ -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;