File tree Expand file tree Collapse file tree 1 file changed +19
-9
lines changed
Expand file tree Collapse file tree 1 file changed +19
-9
lines changed Original file line number Diff line number Diff line change 1- import type { SpaceState } from 'graph-framework-space-events' ;
1+ import { Schema } from 'effect' ;
2+ import { SpaceState } from 'graph-framework-space-events' ;
23import { prisma } from '../prisma.js' ;
34
45type Params = {
56 accountId : string ;
67} ;
78
9+ const decodeSpaceState = Schema . decodeUnknownEither ( SpaceState ) ;
10+
811export const listInvitations = async ( { accountId } : Params ) => {
912 const result = await prisma . invitation . findMany ( {
1013 where : {
@@ -24,12 +27,19 @@ export const listInvitations = async ({ accountId }: Params) => {
2427 } ,
2528 } ) ;
2629
27- return result . map ( ( invitation ) => {
28- const state = JSON . parse ( invitation . space . events [ 0 ] . state ) as SpaceState ;
29- return {
30- id : invitation . id ,
31- previousEventHash : state . lastEventHash ,
32- spaceId : invitation . spaceId ,
33- } ;
34- } ) ;
30+ return result
31+ . map ( ( invitation ) => {
32+ const result = decodeSpaceState ( JSON . parse ( invitation . space . events [ 0 ] . state ) ) ;
33+ if ( result . _tag === 'Right' ) {
34+ const state = result . right ;
35+ return {
36+ id : invitation . id ,
37+ previousEventHash : state . lastEventHash ,
38+ spaceId : invitation . spaceId ,
39+ } ;
40+ }
41+ console . error ( 'Invalid space state from the DB' , result . left ) ;
42+ return null ;
43+ } )
44+ . filter ( ( invitation ) => invitation !== null ) ;
3545} ;
You can’t perform that action at this time.
0 commit comments