Files
website-secure/n8n/create-component.json
T
pm f5dac14dd4
DevSecOps Enterprise Pipeline - Next.js / security-gate-and-deploy (push) Failing after 8s
feat: migração para Next.js e pipeline DevSecOps finalizada
2026-06-01 15:36:35 +01:00

313 lines
9.0 KiB
JSON

{
"name": "Linse - Create New Component",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "create-component",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-trigger",
"name": "Webhook Trigger",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [240, 300],
"webhookId": "create-component-webhook"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "check-part-number",
"leftValue": "={{ $json.body.part_number }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "isNotEmpty"
}
},
{
"id": "check-name",
"leftValue": "={{ $json.body.name }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "isNotEmpty"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "validate-input",
"name": "Validate Input",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [460, 300]
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT id FROM categories WHERE name = '{{ $json.body.category_name }}' LIMIT 1",
"options": {}
},
"id": "lookup-category",
"name": "Lookup Category",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [680, 200],
"credentials": {
"postgres": {
"id": "POSTGRES_CREDENTIAL_ID",
"name": "Linse Postgres"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT id FROM components WHERE part_number = '{{ $('Webhook Trigger').item.json.body.part_number }}' LIMIT 1",
"options": {}
},
"id": "check-duplicate",
"name": "Check Duplicate Part Number",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [900, 200],
"credentials": {
"postgres": {
"id": "POSTGRES_CREDENTIAL_ID",
"name": "Linse Postgres"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "no-duplicate",
"leftValue": "={{ $json.length }}",
"rightValue": 0,
"operator": {
"type": "number",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "is-duplicate",
"name": "Is Duplicate?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [1120, 200]
},
{
"parameters": {
"operation": "executeQuery",
"query": "INSERT INTO components (\n part_number,\n name,\n description,\n category_id,\n manufacturer,\n package_type,\n unit_price,\n stock_quantity,\n min_stock_level,\n datasheet_url,\n supplier,\n supplier_part_number,\n shelf_location\n) VALUES (\n '{{ $('Webhook Trigger').item.json.body.part_number }}',\n '{{ $('Webhook Trigger').item.json.body.name }}',\n {{ $('Webhook Trigger').item.json.body.description ? \"'\" + $('Webhook Trigger').item.json.body.description + \"'\" : 'NULL' }},\n {{ $('Lookup Category').item.json.id ? $('Lookup Category').item.json.id : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.manufacturer ? \"'\" + $('Webhook Trigger').item.json.body.manufacturer + \"'\" : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.package_type ? \"'\" + $('Webhook Trigger').item.json.body.package_type + \"'\" : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.unit_price || 0 }},\n {{ $('Webhook Trigger').item.json.body.stock_quantity || 0 }},\n {{ $('Webhook Trigger').item.json.body.min_stock_level || 0 }},\n {{ $('Webhook Trigger').item.json.body.datasheet_url ? \"'\" + $('Webhook Trigger').item.json.body.datasheet_url + \"'\" : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.supplier ? \"'\" + $('Webhook Trigger').item.json.body.supplier + \"'\" : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.supplier_part_number ? \"'\" + $('Webhook Trigger').item.json.body.supplier_part_number + \"'\" : 'NULL' }},\n {{ $('Webhook Trigger').item.json.body.shelf_location ? \"'\" + $('Webhook Trigger').item.json.body.shelf_location + \"'\" : 'NULL' }}\n) RETURNING *",
"options": {}
},
"id": "insert-component",
"name": "Insert Component",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [1340, 100],
"credentials": {
"postgres": {
"id": "POSTGRES_CREDENTIAL_ID",
"name": "Linse Postgres"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT c.*, cat.name AS category_name FROM components c LEFT JOIN categories cat ON c.category_id = cat.id WHERE c.id = {{ $json[0].id }}",
"options": {}
},
"id": "fetch-created-component",
"name": "Fetch Created Component",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.5,
"position": [1560, 100],
"credentials": {
"postgres": {
"id": "POSTGRES_CREDENTIAL_ID",
"name": "Linse Postgres"
}
}
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ { \"success\": true, \"message\": \"Component created successfully\", \"component\": $json[0] } }}",
"options": {
"responseCode": 201
}
},
"id": "respond-success",
"name": "Respond Success",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [1780, 100]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ { \"success\": false, \"error\": \"Component with part_number '\" + $('Webhook Trigger').item.json.body.part_number + \"' already exists\" } }}",
"options": {
"responseCode": 409
}
},
"id": "respond-duplicate",
"name": "Respond Duplicate Error",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [1340, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={{ { \"success\": false, \"error\": \"part_number and name are required fields\" } }}",
"options": {
"responseCode": 400
}
},
"id": "respond-validation-error",
"name": "Respond Validation Error",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [680, 420]
}
],
"connections": {
"Webhook Trigger": {
"main": [
[
{
"node": "Validate Input",
"type": "main",
"index": 0
}
]
]
},
"Validate Input": {
"main": [
[
{
"node": "Lookup Category",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond Validation Error",
"type": "main",
"index": 0
}
]
]
},
"Lookup Category": {
"main": [
[
{
"node": "Check Duplicate Part Number",
"type": "main",
"index": 0
}
]
]
},
"Check Duplicate Part Number": {
"main": [
[
{
"node": "Is Duplicate?",
"type": "main",
"index": 0
}
]
]
},
"Is Duplicate?": {
"main": [
[
{
"node": "Insert Component",
"type": "main",
"index": 0
}
],
[
{
"node": "Respond Duplicate Error",
"type": "main",
"index": 0
}
]
]
},
"Insert Component": {
"main": [
[
{
"node": "Fetch Created Component",
"type": "main",
"index": 0
}
]
]
},
"Fetch Created Component": {
"main": [
[
{
"node": "Respond Success",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [
{
"name": "Linse",
"id": "linse-tag"
},
{
"name": "Components",
"id": "components-tag"
}
],
"meta": {
"templateCredsSetupCompleted": false,
"instanceId": ""
},
"pinData": {}
}