@@ -72,33 +72,39 @@ export async function getSecondsCoded(slackId: string, date: Date) {
7272 return 0 ;
7373 }
7474
75- const codingTotal =
76- JSON . parse ( categoriesResultRaw [ 0 ] . categories ) . find (
77- ( { key } : { key : string } ) => key === "coding" ,
78- ) . total ?? 0 ;
75+ const total = JSON . parse ( categoriesResultRaw [ 0 ] . categories )
76+ . filter ( ( { key } : { key : string } ) =>
77+ [ "coding" , "building" , "debugging" ] . includes ( key ) ,
78+ )
79+ . reduce ( ( acc : number , { total } : { total : number } ) => acc + total , 0 ) ;
7980
80- if ( typeof codingTotal !== "number" ) {
81+ if ( typeof total !== "number" ) {
8182 return 0 ;
8283 }
8384
84- return codingTotal ;
85+ return total ;
8586}
8687
8788export async function getSecondsCodedTotal ( slackId : string ) {
8889 try {
89- const categories = await sql `
90+ const days = await sql `
9091 SELECT summary->>'categories' as categories
9192 FROM user_hakatime_daily_summary
9293 JOIN users ON user_id = users.slack_id
9394 WHERE users.slack_id = ${ slackId } ;` ;
9495
95- const total = categories . reduce (
96+ const total = days . reduce (
9697 ( acc : number , { categories } : { categories : string } ) => {
9798 const cats = JSON . parse ( categories ) ;
98- const coding = cats . find (
99- ( { key } : { key : string } ) => key === "coding" ,
100- ) ;
101- return acc + ( coding ?. total ?? 0 ) ;
99+ const dayTotal = cats
100+ . filter ( ( { key } : { key : string } ) =>
101+ [ "coding" , "building" , "debugging" ] . includes ( key ) ,
102+ )
103+ . reduce ( ( acc : number , { total } : { total : number } ) => {
104+ acc += total ;
105+ } , 0 ) ;
106+
107+ return acc + dayTotal ;
102108 } ,
103109 0 ,
104110 ) ;
0 commit comments