11import { createServerFn } from "@tanstack/react-start" ;
2- import { Job , Repo } from './types'
3- import { fetchRepos } from "./backend" ;
4- import { fetchProjects , updateProject } from "./api" ;
2+ import { Job , OrgSettings , Project , Repo } from './types'
3+ import { fetchRepos , testSlackWebhook } from "./backend" ;
4+ import { fetchProject , fetchProjects , getOrgSettings , updateOrgSettings , updateProject } from "./api" ;
55
6+ export const getOrgSettingsFn = createServerFn ( { method : 'GET' } )
7+ . inputValidator ( ( data : { userId : string , organisationId : string } ) => data )
8+ . handler ( async ( { data } ) => {
9+ const settings : any = await getOrgSettings ( data . organisationId , data . userId )
10+ return settings
11+ } )
612
13+ export const updateOrgSettingsFn = createServerFn ( { method : 'POST' } )
14+ . inputValidator ( ( data : { userId : string , organisationId : string , settings : OrgSettings } ) => data )
15+ . handler ( async ( { data } ) => {
16+ const settings : any = await updateOrgSettings ( data . organisationId , data . userId , data . settings )
17+ return settings . result
18+ } )
719
820export const getProjectsFn = createServerFn ( { method : 'GET' } )
9- . inputValidator ( ( data : { userId : string , organisationId : string } ) => data )
21+ . inputValidator ( ( data : { userId : string , organisationId : string } ) => {
22+ if ( ! data . userId || ! data . organisationId ) {
23+ throw new Error ( 'Missing required fields: userId and organisationId are required' )
24+ }
25+ return data
26+ } )
1027 . handler ( async ( { data } ) => {
11- const projects : any = await fetchProjects ( data . organisationId , data . userId )
12- return projects . result
13- } )
28+ try {
29+ const projects : any = await fetchProjects ( data . organisationId , data . userId )
30+ return projects . result || [ ]
31+ } catch ( error ) {
32+ console . error ( 'Error in getProjectsFn:' , error )
33+ return [ ]
34+ }
35+ } )
1436
1537
1638export const updateProjectFn = createServerFn ( { method : 'POST' } )
@@ -34,6 +56,13 @@ export const getReposFn = createServerFn({method: 'GET'})
3456 return repos
3557 } )
3658
59+ export const getProjectFn = createServerFn ( { method : 'GET' } )
60+ . inputValidator ( ( data : { projectId : string , organisationId : string , userId : string } ) => data )
61+ . handler ( async ( { data } ) => {
62+ const project : any = await fetchProject ( data . projectId , data . organisationId , data . userId )
63+ return project
64+ } )
65+
3766
3867export const getRepoDetailsFn = createServerFn ( { method : 'GET' } )
3968 . inputValidator ( ( data : { repoId : string , organisationId : string , userId : string } ) => data )
@@ -68,3 +97,19 @@ export const getRepoDetailsFn = createServerFn({method: 'GET'})
6897
6998 return { repo, allJobs }
7099 } )
100+
101+ export const switchToOrganizationFn = createServerFn ( { method : 'POST' } )
102+ . inputValidator ( ( data : { organisationId : string , pathname : string } ) => data )
103+ . handler ( async ( { data } ) => {
104+ return null
105+ } )
106+
107+
108+
109+ export const testSlackWebhookFn = createServerFn ( { method : 'POST' } )
110+ . inputValidator ( ( data : { notification_url : string } ) => data )
111+ . handler ( async ( { data } ) => {
112+ const response : any = await testSlackWebhook ( data . notification_url )
113+ return response
114+ } )
115+
0 commit comments