import { Role , Profile , User } from '@prisma/client' ; import { Context } from '../graphql/context' ; param user export const isAdmin = ( user ) : boolean => { if ( ! user ?. roles ) { return false ; } return user . roles . includes ( Role . ADMIN ) ; } ; param user param ctx export function isSelf ( user , ctx ) { return user . id === ctx . user ?. id ; } param object param ctx param idField export function canAccess ( object , ctx , idField = 'userId' ) { if ( ! ctx . user ) return false ; if ( isAdmin ( ctx . user ) ) return true ; if ( isSelf ( object , ctx ) ) return true ; return ( object as any ) [ idField ] === ctx . user ?. id ; }