File tree Expand file tree Collapse file tree 2 files changed +38
-26
lines changed
Expand file tree Collapse file tree 2 files changed +38
-26
lines changed Original file line number Diff line number Diff line change 1+ import { type LoaderFunctionArgs , redirect } from "@remix-run/server-runtime" ;
2+ import { z } from "zod" ;
3+ import { prisma } from "~/db.server" ;
4+ import { requireUserId } from "~/services/session.server" ;
5+
6+ const ParamsSchema = z . object ( {
7+ projectRef : z . string ( ) ,
8+ } ) ;
9+
10+ export async function loader ( { params, request } : LoaderFunctionArgs ) {
11+ const userId = await requireUserId ( request ) ;
12+
13+ const validatedParams = ParamsSchema . parse ( params ) ;
14+
15+ const project = await prisma . project . findFirst ( {
16+ where : {
17+ externalRef : validatedParams . projectRef ,
18+ organization : {
19+ members : {
20+ some : {
21+ userId,
22+ } ,
23+ } ,
24+ } ,
25+ } ,
26+ include : {
27+ organization : true ,
28+ } ,
29+ } ) ;
30+
31+ if ( ! project ) {
32+ return new Response ( "Not found" , { status : 404 } ) ;
33+ }
34+
35+ // Redirect to the project's runs page
36+ return redirect ( `/orgs/${ project . organization . slug } /projects/${ project . slug } ` ) ;
37+ }
Original file line number Diff line number Diff line change 11import { type LoaderFunctionArgs , redirect } from "@remix-run/server-runtime" ;
22import { z } from "zod" ;
3- import { prisma } from "~/db.server" ;
4- import { requireUserId } from "~/services/session.server" ;
53
64const ParamsSchema = z . object ( {
75 projectRef : z . string ( ) ,
86} ) ;
97
108export async function loader ( { params, request } : LoaderFunctionArgs ) {
11- const userId = await requireUserId ( request ) ;
12-
139 const validatedParams = ParamsSchema . parse ( params ) ;
1410
15- const project = await prisma . project . findFirst ( {
16- where : {
17- externalRef : validatedParams . projectRef ,
18- organization : {
19- members : {
20- some : {
21- userId,
22- } ,
23- } ,
24- } ,
25- } ,
26- include : {
27- organization : true ,
28- } ,
29- } ) ;
30-
31- if ( ! project ) {
32- return new Response ( "Not found" , { status : 404 } ) ;
33- }
34-
35- // Redirect to the project's runs page
36- return redirect ( `/orgs/${ project . organization . slug } /projects/${ project . slug } ` ) ;
11+ return redirect ( `/projects/${ validatedParams . projectRef } ` ) ;
3712}
You can’t perform that action at this time.
0 commit comments