@@ -3,12 +3,13 @@ import { db } from "@flagix/db";
33import type { Prisma } from "@flagix/db/client" ;
44import { formatDistanceToNow } from "date-fns" ;
55import { type Response , Router } from "express" ;
6- import { env , env as environmentVariable } from "@/config/env" ;
6+ import { env as environmentVariable } from "@/config/env" ;
77import { PROJECT_ADMIN_ROLES } from "@/constants/project" ;
88import { calculateAbStats } from "@/lib/analytics/stats" ;
99import {
1010 createEnvironmentSchema ,
1111 createProjectSchema ,
12+ feedbackSchema ,
1213 inviteSchema ,
1314 updateProjectSchema ,
1415 updateRoleSchema ,
@@ -22,7 +23,7 @@ import {
2223 getTinybirdCount ,
2324 pivotAnalyticsData ,
2425} from "@/utils/analytics" ;
25- import { sendProjectInviteEmail } from "@/utils/project" ;
26+ import { sendFeedbackEmail , sendProjectInviteEmail } from "@/utils/project" ;
2627
2728const router = Router ( ) ;
2829
@@ -135,6 +136,38 @@ router.get("/", async (req: RequestWithSession, res: Response) => {
135136 }
136137} ) ;
137138
139+ router . post (
140+ "/feedback" ,
141+ async ( req : RequestWithSession , res : Response ) => {
142+ const session = req . session ;
143+
144+ if ( ! session || ! session . user ) {
145+ return res . status ( 401 ) . json ( { error : "unauthenticated" } ) ;
146+ }
147+
148+ const userEmail = session . user . email ;
149+ const userName = session . user . name ;
150+
151+ try {
152+ const body = feedbackSchema . parse ( req . body ) ;
153+
154+ await sendFeedbackEmail ( {
155+ userEmail,
156+ userName,
157+ feedback : body . feedback ,
158+ } ) ;
159+
160+ res . status ( 200 ) . json ( { success : true , message : "Feedback submitted successfully" } ) ;
161+ } catch ( error ) {
162+ console . error ( "Failed to submit feedback:" , error ) ;
163+ if ( error instanceof Error && error . name === "ZodError" ) {
164+ return res . status ( 400 ) . json ( { error : "Invalid feedback data" } ) ;
165+ }
166+ res . status ( 500 ) . json ( { error : "Failed to submit feedback" } ) ;
167+ }
168+ }
169+ ) ;
170+
138171router . use ( "/:projectId" , resolveRoleByProjectParams ) ;
139172
140173router . get (
@@ -1358,7 +1391,9 @@ router.get(
13581391 try {
13591392 const tbUrl = `https://api.europe-west2.gcp.tinybird.co/v0/pipes/usage_analytics.json?projectId=${ projectId } &days=${ days } ` ;
13601393 const response = await fetch ( tbUrl , {
1361- headers : { Authorization : `Bearer ${ env . TINYBIRD_TOKEN } ` } ,
1394+ headers : {
1395+ Authorization : `Bearer ${ environmentVariable . TINYBIRD_TOKEN } ` ,
1396+ } ,
13621397 } ) ;
13631398
13641399 if ( ! response . ok ) {
@@ -1459,12 +1494,12 @@ router.get(
14591494 const [ summaryRes , trendRes ] = await Promise . all ( [
14601495 fetch ( summaryUrl , {
14611496 headers : {
1462- Authorization : `Bearer ${ env . TINYBIRD_TOKEN } ` ,
1497+ Authorization : `Bearer ${ environmentVariable . TINYBIRD_TOKEN } ` ,
14631498 } ,
14641499 } ) ,
14651500 fetch ( trendUrl , {
14661501 headers : {
1467- Authorization : `Bearer ${ env . TINYBIRD_TOKEN } ` ,
1502+ Authorization : `Bearer ${ environmentVariable . TINYBIRD_TOKEN } ` ,
14681503 } ,
14691504 } ) ,
14701505 ] ) ;
0 commit comments