Upload files to "Gheeraert"
This commit is contained in:
@@ -0,0 +1,337 @@
|
||||
{
|
||||
"name": "Gheeraert workflow 3 — statussen ophalen",
|
||||
"nodes": [
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "SELECT\n id,\n purchase_order_number,\n transpas_legnr,\n transpas_reference,\n gheeraert_order_id,\n last_status_poll_at,\n next_status_poll_at,\n delivered_at,\n pod_online_at,\n pod_downloaded_at\nFROM public.ghe_order_log\nWHERE file_upload_status = 'sent'\n AND gheeraert_order_id IS NOT NULL\n AND is_closed = false\n AND (\n next_status_poll_at IS NULL\n OR next_status_poll_at <= CURRENT_TIMESTAMP\n )\nORDER BY\n COALESCE(last_status_poll_at, created_at),\n id\nLIMIT 25;",
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.postgres",
|
||||
"typeVersion": 2.6,
|
||||
"position": [
|
||||
224,
|
||||
-272
|
||||
],
|
||||
"id": "efb74e39-f147-40e3-af5b-c8022ad51944",
|
||||
"name": "Get Orders With Gheeraert ID",
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "pxziuCOuNpsUFKrm",
|
||||
"name": "transpas_n8n_gheeraert"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"method": "POST",
|
||||
"url": "https://my-uat.gheeraert.be/token",
|
||||
"sendBody": true,
|
||||
"contentType": "form-urlencoded",
|
||||
"bodyParameters": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "grant_type",
|
||||
"value": "password"
|
||||
},
|
||||
{
|
||||
"name": "username",
|
||||
"value": "api@dewittransport.nl"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"value": "my.gheeraert"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.4,
|
||||
"position": [
|
||||
448,
|
||||
-272
|
||||
],
|
||||
"id": "b049495e-5e3d-4c86-8ad7-5283fdf82efe",
|
||||
"name": "Get Gheeraert Token"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"url": "={{ 'https://my-uat.gheeraert.be/api/OrderTracking/' + $('Get Orders With Gheeraert ID').item.json.gheeraert_order_id }}",
|
||||
"sendHeaders": true,
|
||||
"headerParameters": {
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Authorization",
|
||||
"value": "={{ 'Bearer ' + $('Get Gheeraert Token').first().json.access_token }}"
|
||||
},
|
||||
{
|
||||
"name": "Accept",
|
||||
"value": "application/json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {
|
||||
"response": {
|
||||
"response": {
|
||||
"responseFormat": "json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.httpRequest",
|
||||
"typeVersion": 4.4,
|
||||
"position": [
|
||||
672,
|
||||
-272
|
||||
],
|
||||
"id": "1407cf2f-34b0-4a58-bdc3-86ac1ea72777",
|
||||
"name": "Lookup Gheeraert OrderTracking",
|
||||
"onError": "continueRegularOutput"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "function simpleHash(input) {\n const str = String(input ?? '');\n let h1 = 0xdeadbeef ^ str.length;\n let h2 = 0x41c6ce57 ^ str.length;\n\n for (let i = 0; i < str.length; i++) {\n const ch = str.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n\n h1 =\n Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^\n Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n\n h2 =\n Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^\n Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n return (\n (h2 >>> 0).toString(16).padStart(8, '0') +\n (h1 >>> 0).toString(16).padStart(8, '0')\n );\n}\n\nreturn $input.all().map(item => {\n const j = item.json;\n\n const base = [\n j.gheeraert_order_id ?? '',\n j.status_id ?? '',\n j.tracking_date ?? '',\n j.tracking_comments ?? '',\n j.barcode ?? '',\n j.tracking_url ?? '',\n ].join('|');\n\n return {\n json: {\n ...j,\n status_hash: simpleHash(base),\n },\n };\n});"
|
||||
},
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
1120,
|
||||
-272
|
||||
],
|
||||
"id": "c517653a-9b40-4c9a-a1a8-c7e0f0cf3636",
|
||||
"name": "Make Status Hash"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "WITH input AS (\n SELECT $1::jsonb AS j\n),\ntyped AS (\n SELECT\n (j->>'order_log_id')::bigint AS order_log_id,\n (j->>'gheeraert_order_id')::integer AS gheeraert_order_id,\n (j->>'purchase_order_number')::varchar AS purchase_order_number,\n (j->>'status_id')::integer AS status_id,\n (j->>'tracking_date')::timestamp AS tracking_date,\n (j->>'tracking_comments')::text AS tracking_comments,\n (j->>'tracking_url')::text AS tracking_url,\n NULLIF(j->>'barcode', '')::varchar AS barcode,\n NULLIF(j->>'user_name', '')::varchar AS user_name,\n (j->>'status_hash')::varchar AS status_hash\n FROM input\n),\nins AS (\n INSERT INTO public.ghe_status_log (\n order_log_id,\n gheeraert_order_id,\n purchase_order_number,\n status_id,\n tracking_date,\n tracking_comments,\n tracking_url,\n barcode,\n user_name,\n status_hash\n )\n SELECT\n order_log_id,\n gheeraert_order_id,\n purchase_order_number,\n status_id,\n tracking_date,\n tracking_comments,\n tracking_url,\n barcode,\n user_name,\n status_hash\n FROM typed\n ON CONFLICT (status_hash)\n DO NOTHING\n RETURNING id\n)\nSELECT\n ins.id AS inserted_id,\n typed.order_log_id,\n typed.gheeraert_order_id,\n typed.purchase_order_number,\n typed.status_id,\n typed.tracking_date,\n typed.tracking_comments,\n typed.tracking_url,\n typed.barcode,\n typed.user_name,\n typed.status_hash\nFROM typed\nLEFT JOIN ins ON TRUE;",
|
||||
"options": {
|
||||
"queryReplacement": "={{ [JSON.stringify($json)] }}"
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.postgres",
|
||||
"typeVersion": 2.6,
|
||||
"position": [
|
||||
1440,
|
||||
-272
|
||||
],
|
||||
"id": "0612800b-26e7-415d-8bf3-225edbbb93e4",
|
||||
"name": "Insert ghe_status_log",
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "pxziuCOuNpsUFKrm",
|
||||
"name": "transpas_n8n_gheeraert"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"conditions": {
|
||||
"options": {
|
||||
"caseSensitive": true,
|
||||
"leftValue": "",
|
||||
"typeValidation": "strict",
|
||||
"version": 3
|
||||
},
|
||||
"conditions": [
|
||||
{
|
||||
"id": "5d26cbeb-2ed9-45a4-914b-754a130fc915",
|
||||
"leftValue": "={{ $json.inserted_id }}",
|
||||
"rightValue": "",
|
||||
"operator": {
|
||||
"type": "string",
|
||||
"operation": "notEmpty",
|
||||
"singleValue": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"combinator": "and"
|
||||
},
|
||||
"options": {}
|
||||
},
|
||||
"type": "n8n-nodes-base.if",
|
||||
"typeVersion": 2.3,
|
||||
"position": [
|
||||
1664,
|
||||
-272
|
||||
],
|
||||
"id": "7ef41b79-2a94-4ab3-9e0d-aecf274dcd7e",
|
||||
"name": "If"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"operation": "executeQuery",
|
||||
"query": "\nWITH input AS (\n SELECT $1::jsonb AS j\n)\nUPDATE public.ghe_order_log\nSET\n last_status_poll_at = CURRENT_TIMESTAMP,\n last_status_id = (j->>'status_id')::integer,\n last_status_text = (j->>'tracking_comments')::varchar,\n last_tracking_date = (j->>'tracking_date')::timestamp,\n\n delivered_at = CASE\n WHEN (j->>'status_id')::integer = 30 AND delivered_at IS NULL\n THEN (j->>'tracking_date')::timestamp\n ELSE delivered_at\n END,\n\n pod_online_at = CASE\n WHEN (j->>'status_id')::integer = 35 AND pod_online_at IS NULL\n THEN (j->>'tracking_date')::timestamp\n ELSE pod_online_at\n END,\n\n next_status_poll_at = CASE\n WHEN (j->>'status_id')::integer = 35 THEN CURRENT_TIMESTAMP + INTERVAL '1 day'\n WHEN (j->>'status_id')::integer = 30 THEN CURRENT_TIMESTAMP + INTERVAL '2 hours'\n ELSE CURRENT_TIMESTAMP + INTERVAL '15 minutes'\n END\nFROM input\nWHERE public.ghe_order_log.id = (j->>'order_log_id')::bigint;",
|
||||
"options": {
|
||||
"queryReplacement": "=={{ [JSON.stringify($json)] }}"
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.postgres",
|
||||
"typeVersion": 2.6,
|
||||
"position": [
|
||||
1920,
|
||||
-336
|
||||
],
|
||||
"id": "bb2fd5f0-0958-41aa-b739-a93689508021",
|
||||
"name": "Update ghe_order_log",
|
||||
"credentials": {
|
||||
"postgres": {
|
||||
"id": "pxziuCOuNpsUFKrm",
|
||||
"name": "transpas_n8n_gheeraert"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"content": "## workflow 1: orders versturen + loggen\n## workflow 2: Gheeraert OrderID ophalen\n## workflow 3: tracking ophalen + statuslog vullen\n",
|
||||
"width": 720
|
||||
},
|
||||
"type": "n8n-nodes-base.stickyNote",
|
||||
"typeVersion": 1,
|
||||
"position": [
|
||||
48,
|
||||
-464
|
||||
],
|
||||
"id": "3d0643a3-a9ab-481f-b8e3-cd00c9d54628",
|
||||
"name": "Sticky Note"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"rule": {
|
||||
"interval": [
|
||||
{
|
||||
"field": "cronExpression",
|
||||
"expression": "*/20 6-22 * * 1-5"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"type": "n8n-nodes-base.scheduleTrigger",
|
||||
"typeVersion": 1.3,
|
||||
"position": [
|
||||
0,
|
||||
-272
|
||||
],
|
||||
"id": "201f3623-82ac-43a6-aade-8d4d967a43bf",
|
||||
"name": "Schedule Trigger"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"jsCode": "const orders = $('Get Orders With Gheeraert ID').all().map(i => i.json);\n\nconst orderByGheeraertId = new Map(\n orders.map(order => [String(order.gheeraert_order_id), order])\n);\n\nconst out = [];\n\nfor (const item of $input.all()) {\n const t = item.json;\n\n const gheOrderId = String(t.OrderID ?? '');\n const order = orderByGheeraertId.get(gheOrderId);\n\n if (!order) {\n out.push({\n json: {\n error: true,\n error_text: `Geen matching order gevonden voor Gheeraert OrderID ${gheOrderId}`,\n gheeraert_order_id: t.OrderID ?? null,\n purchase_order_number: t.PurchaseOrderNumber ?? null,\n raw: t,\n },\n });\n continue;\n }\n\n out.push({\n json: {\n order_log_id: order.id ?? null,\n gheeraert_order_id: t.OrderID ?? order.gheeraert_order_id ?? null,\n purchase_order_number: t.PurchaseOrderNumber ?? order.purchase_order_number ?? null,\n transpas_legnr: order.transpas_legnr ?? t.ExtOrderNumber ?? null,\n transpas_reference: order.transpas_reference ?? null,\n\n status_id: t.StatusID ?? null,\n tracking_date: t.TrackingDate ?? null,\n tracking_comments: t.PublicTrackingComments ?? null,\n tracking_url: t.TrackingURL ?? null,\n barcode: t.Barcode ?? null,\n user_name: t.UserName ?? null,\n\n gheeraert_track_id: t.TrackID ?? null,\n location: t.Location ?? null,\n eta: t.ETA ?? null,\n raw: t,\n },\n });\n}\n\nreturn out;"
|
||||
},
|
||||
"type": "n8n-nodes-base.code",
|
||||
"typeVersion": 2,
|
||||
"position": [
|
||||
896,
|
||||
-272
|
||||
],
|
||||
"id": "0e004fcc-f058-4f5c-aa75-f4ee40768295",
|
||||
"name": "Attach Order Context"
|
||||
}
|
||||
],
|
||||
"pinData": {},
|
||||
"connections": {
|
||||
"Get Orders With Gheeraert ID": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Get Gheeraert Token",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Get Gheeraert Token": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Lookup Gheeraert OrderTracking",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Lookup Gheeraert OrderTracking": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Attach Order Context",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Make Status Hash": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Insert ghe_status_log",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Insert ghe_status_log": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "If",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"If": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Update ghe_order_log",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Schedule Trigger": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Get Orders With Gheeraert ID",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"Attach Order Context": {
|
||||
"main": [
|
||||
[
|
||||
{
|
||||
"node": "Make Status Hash",
|
||||
"type": "main",
|
||||
"index": 0
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"active": false,
|
||||
"settings": {
|
||||
"executionOrder": "v1",
|
||||
"binaryMode": "separate"
|
||||
},
|
||||
"versionId": "0c994af9-2e64-48c1-80ca-cb00d8ae00e5",
|
||||
"meta": {
|
||||
"templateCredsSetupCompleted": true,
|
||||
"instanceId": "bef8d409866a58c0777dfe7cca1b9c2400fd051c056d361501393ab423006b5f"
|
||||
},
|
||||
"nodeGroups": [],
|
||||
"id": "csPbDxZ03HyBjtwh",
|
||||
"tags": []
|
||||
}
|
||||
Reference in New Issue
Block a user