From 9ceed79cf32c896f8a998399bf1b296506b2cd4a Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 8 Apr 2025 03:08:19 +0000
Subject: 로그인 및 미들웨어 처리. 구조 변경
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations_backup/0108_known_grim_reaper.sql | 42 +++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 db/migrations_backup/0108_known_grim_reaper.sql

(limited to 'db/migrations_backup/0108_known_grim_reaper.sql')

diff --git a/db/migrations_backup/0108_known_grim_reaper.sql b/db/migrations_backup/0108_known_grim_reaper.sql
new file mode 100644
index 00000000..3cf24516
--- /dev/null
+++ b/db/migrations_backup/0108_known_grim_reaper.sql
@@ -0,0 +1,42 @@
+DROP VIEW "public"."vendor_detail_view";--> statement-breakpoint
+CREATE VIEW "public"."vendor_detail_view" AS (select "id", "vendor_name", "vendor_code", "tax_id", "address", "country", "phone", "email", "website", "status", "representative_name", "representative_birth", "representative_email", "representative_phone", "corporate_registration_number", "credit_agency", "credit_rating", "cash_flow_rating", "created_at", "updated_at", 
+        (SELECT COALESCE(
+          json_agg(
+            json_build_object(
+              'id', c.id,
+              'contactName', c.contact_name,
+              'contactPosition', c.contact_position,
+              'contactEmail', c.contact_email,
+              'contactPhone', c.contact_phone,
+              'isPrimary', c.is_primary
+            )
+          ),
+          '[]'::json
+        )
+        FROM vendor_contacts c
+        WHERE c.vendor_id = vendors.id)
+       as "contacts", 
+        (SELECT COALESCE(
+          json_agg(
+            json_build_object(
+              'id', a.id,
+              'fileName', a.file_name,
+              'filePath', a.file_path,
+              'attachmentType', a.attachment_type,
+              'createdAt', a.created_at
+            )
+            ORDER BY a.attachment_type, a.created_at DESC
+          ),
+          '[]'::json
+        )
+        FROM vendor_attachments a
+        WHERE a.vendor_id = vendors.id)
+       as "attachments", 
+        (SELECT COUNT(*)
+        FROM vendor_attachments a
+        WHERE a.vendor_id = vendors.id)
+       as "attachment_count", 
+        (SELECT COUNT(*) 
+        FROM vendor_contacts c
+        WHERE c.vendor_id = vendors.id)
+       as "contact_count" from "vendors");
\ No newline at end of file
-- 
cgit v1.2.3

