1- import { FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' ;
2- import { ApplicationError , ErrorCode } from '@openops/shared' ;
1+ import {
2+ FastifyPluginCallbackTypebox ,
3+ Type ,
4+ } from '@fastify/type-provider-typebox' ;
5+ import {
6+ ApplicationError ,
7+ ErrorCode ,
8+ Project ,
9+ SeekPage ,
10+ } from '@openops/shared' ;
311import { paginationHelper } from '../helper/pagination/pagination-utils' ;
412import { projectService } from './project-service' ;
513
@@ -8,23 +16,45 @@ export const userProjectController: FastifyPluginCallbackTypebox = (
816 _opts ,
917 done ,
1018) => {
11- fastify . get ( '/:id' , async ( request , response ) => {
12- try {
13- return await projectService . getOneOrThrow ( request . principal . projectId ) ;
14- } catch ( err ) {
15- if ( err instanceof ApplicationError ) {
16- err . error . code = ErrorCode . ENTITY_NOT_FOUND ;
17- return response . code ( 401 ) . send ( ) ;
19+ fastify . get (
20+ '/:id' ,
21+ GetUserProjectRequestOptions ,
22+ async ( request , response ) => {
23+ try {
24+ return await projectService . getOneOrThrow ( request . principal . projectId ) ;
25+ } catch ( err ) {
26+ if ( err instanceof ApplicationError ) {
27+ err . error . code = ErrorCode . ENTITY_NOT_FOUND ;
28+ return response . code ( 401 ) . send ( ) ;
29+ }
30+ throw err ;
1831 }
19- throw err ;
20- }
21- } ) ;
32+ } ,
33+ ) ;
2234
23- fastify . get ( '/' , async ( request ) => {
35+ fastify . get ( '/' , ListUserProjectsRequestOptions , async ( request ) => {
2436 return paginationHelper . createPage (
2537 [ await projectService . getOneOrThrow ( request . principal . projectId ) ] ,
2638 null ,
2739 ) ;
2840 } ) ;
2941 done ( ) ;
3042} ;
43+
44+ const ProjectWithoutToken = Type . Omit ( Project , [ 'tablesDatabaseToken' ] ) ;
45+
46+ const GetUserProjectRequestOptions = {
47+ schema : {
48+ response : {
49+ 200 : ProjectWithoutToken ,
50+ } ,
51+ } ,
52+ } ;
53+
54+ const ListUserProjectsRequestOptions = {
55+ schema : {
56+ response : {
57+ 200 : SeekPage ( ProjectWithoutToken ) ,
58+ } ,
59+ } ,
60+ } ;
0 commit comments