1
1
import { InputType , ObjectType } from '@nestjs/graphql' ;
2
2
import { Type } from 'class-transformer' ;
3
3
import { ValidateNested } from 'class-validator' ;
4
+ import { set } from 'lodash' ;
4
5
import {
5
6
DateFilter ,
6
7
DateTimeFilter ,
@@ -14,6 +15,7 @@ import {
14
15
type Sensitivity ,
15
16
SortablePaginationInput ,
16
17
} from '~/common' ;
18
+ import { Transform } from '~/common/transform.decorator' ;
17
19
import { LocationFilters } from '../../location/dto' ;
18
20
import { PartnershipFilters } from '../../partnership/dto' ;
19
21
import { ProjectMemberFilters } from '../project-member/dto' ;
@@ -88,21 +90,17 @@ export abstract class ProjectFilters {
88
90
@ValidateNested ( )
89
91
readonly mouEnd ?: DateFilter ;
90
92
91
- @OptionalField ( {
92
- description : 'only mine' ,
93
- deprecationReason : 'Use `isMember` instead.' ,
94
- } )
95
- readonly mine ?: boolean ;
96
-
97
- @OptionalField ( {
98
- description : 'Only projects that the requesting user is a member of' ,
99
- } )
100
- readonly isMember ?: boolean ;
101
-
102
93
@FilterField ( ( ) => ProjectMemberFilters , {
103
94
description :
104
95
"Only projects with the requesting user's membership that matches these filters" ,
105
96
} )
97
+ @Transform ( ( { value, obj } ) => {
98
+ // Only ran when GQL specifies membership
99
+ if ( value . active == null && ( obj . mine || obj . isMember ) ) {
100
+ value . active = true ;
101
+ }
102
+ return value ;
103
+ } )
106
104
readonly membership ?: ProjectMemberFilters & { } ;
107
105
108
106
@FilterField ( ( ) => ProjectMemberFilters , {
@@ -138,6 +136,28 @@ export abstract class ProjectFilters {
138
136
readonly primaryLocation ?: LocationFilters & { } ;
139
137
}
140
138
139
+ Object . defineProperty ( ProjectFilters . prototype , 'mine' , {
140
+ set ( value : boolean ) {
141
+ // Ensure this is set when membership has not been declared
142
+ value && ! this . membership && set ( this , 'membership.active' , true ) ;
143
+ } ,
144
+ } ) ;
145
+ OptionalField ( ( ) => Boolean , {
146
+ description : 'only mine' ,
147
+ deprecationReason : 'Use `isMember` instead.' ,
148
+ } ) ( ProjectFilters . prototype , 'mine' ) ;
149
+
150
+ Object . defineProperty ( ProjectFilters . prototype , 'isMember' , {
151
+ set ( value : boolean ) {
152
+ // Ensure this is set when membership has not been declared
153
+ value && ! this . membership && set ( this , 'membership.active' , true ) ;
154
+ } ,
155
+ } ) ;
156
+ OptionalField ( ( ) => Boolean , {
157
+ description :
158
+ 'Only projects that the requesting user is an active member of. false does nothing.' ,
159
+ } ) ( ProjectFilters . prototype , 'isMember' ) ;
160
+
141
161
@InputType ( )
142
162
export class ProjectListInput extends SortablePaginationInput < keyof IProject > ( {
143
163
defaultSort : 'name' ,
0 commit comments