@@ -5,12 +5,11 @@ import { createClientServerComponent } from "@/utils/supabase/server";
55export const getBoardData = async ( boardId : String ) => {
66 try {
77 const supabase = await createClientServerComponent ( ) ;
8-
9- // Fetch board with columns
8+
9+ // Fetch the board and its columns
1010 const { data : boardData , error } = await supabase
1111 . from ( "kanban_boards" )
12- . select (
13- `
12+ . select ( `
1413 id,
1514 name,
1615 description,
@@ -24,17 +23,16 @@ export const getBoardData = async (boardId: String) => {
2423 created_at,
2524 updated_at
2625 )
27- ` ,
28- )
26+ ` )
2927 . eq ( "id" , boardId )
3028 . single ( ) ;
3129
3230 if ( error ) throw error ;
3331
34- // BUG FIX: Fetch only NON-ARCHIVED tasks (handles NULL values)
35- if ( boardData ?. kanban_columns && boardData . kanban_columns . length > 0 ) {
32+ if ( boardData ?. kanban_columns ) {
3633 const columnIds = boardData . kanban_columns . map ( ( col : any ) => col . id ) ;
37-
34+
35+ // Fetch tasks
3836 const { data : tasks , error : tasksError } = await supabase
3937 . from ( "tasks" )
4038 . select ( `
@@ -75,15 +73,25 @@ export const getBoardData = async (boardId: String) => {
7573
7674 if ( tasksError ) throw tasksError ;
7775
78- // BUG FIX: Double-check filtering on client side for extra safety
79- const activeTasks = tasks ?. filter ( ( task : any ) =>
80- task . is_archive !== true
81- ) || [ ] ;
76+ // Fetch ticket codes separately
77+ const taskIds = tasks ?. map ( ( task : any ) => task . id ) || [ ] ;
78+ const { data : ticketCodes , error : ticketError } = await supabase
79+ . from ( "task_ticket_codes" )
80+ . select ( `task_id, ticket_code` )
81+ . in ( "task_id" , taskIds ) ;
82+
83+ if ( ticketError ) throw ticketError ;
84+
85+ // Merge ticket_code into tasks
86+ const tasksWithTicket = tasks ?. map ( ( task : any ) => ( {
87+ ...task ,
88+ ticket_code : ticketCodes ?. find ( ( t : any ) => t . task_id === task . id ) ?. ticket_code || null ,
89+ } ) ) ;
8290
8391 // Attach tasks to their respective columns
8492 boardData . kanban_columns = boardData . kanban_columns . map ( ( column : any ) => ( {
8593 ...column ,
86- tasks : activeTasks . filter ( ( task : any ) => task . kanban_column_id === column . id )
94+ tasks : tasksWithTicket ? .filter ( ( task : any ) => task . kanban_column_id === column . id ) || [ ] ,
8795 } ) ) ;
8896 } else {
8997 // If no columns exist, initialize empty tasks array
@@ -92,7 +100,7 @@ export const getBoardData = async (boardId: String) => {
92100 tasks : [ ]
93101 } ) ) || [ ] ;
94102 }
95-
103+
96104 return boardData ;
97105 } catch ( error ) {
98106 console . error ( "Error fetching board data:" , error ) ;
@@ -135,4 +143,4 @@ export const getSprintsData = async (projectId: String) => {
135143 console . error ( "Error fetching sprints data:" , error ) ;
136144 throw error ;
137145 }
138- } ;
146+ } ;
0 commit comments