@@ -20,8 +20,8 @@ module.exports = createCoreController(
2020 "api::proposal.proposal" ,
2121 ( { strapi } ) => ( {
2222 async find ( ctx ) {
23- const sanitizedQueryParams = ctx . query
24-
23+
24+ const sanitizedQueryParams = ctx . query ;
2525 if ( ! sanitizedQueryParams . filters ) {
2626 sanitizedQueryParams . filters = { } ;
2727 }
@@ -31,10 +31,11 @@ module.exports = createCoreController(
3131 }
3232
3333 /////GOV ACTION TYPE///////////
34+
3435 const hasGovActionTypeIDFilter = sanitizedQueryParams . filters [ "$and" ] ?. find (
3536 ( elem ) => elem ?. hasOwnProperty ( "gov_action_type_id" )
3637 ) ;
37-
38+
3839 if ( hasGovActionTypeIDFilter ) {
3940 const hasGovActionTypeIDFilterInSanitize =
4041 sanitizedQueryParams ?. filters [ "$and" ] ?. some ( ( elem ) =>
@@ -47,7 +48,6 @@ module.exports = createCoreController(
4748 }
4849 }
4950 //////////////////////////
50-
5151 /////PROPOSAL NAME///////////
5252 const hasPropNameFilter = ctx ?. query ?. filters [ "$and" ] ?. find ( ( elem ) =>
5353 elem ?. hasOwnProperty ( "prop_name" )
@@ -64,7 +64,6 @@ module.exports = createCoreController(
6464 }
6565 }
6666 //////////////////////////////
67-
6867 /////PROPOSAL SUBMITTED///////////
6968 const hasPropSubmitedFilter = ctx ?. query ?. filters [ "$and" ] ?. find ( ( elem ) =>
7069 elem ?. hasOwnProperty ( "prop_submitted" )
@@ -96,7 +95,6 @@ module.exports = createCoreController(
9695 }
9796 }
9897 //////////////////////////////
99-
10098 /////PROPOSAL ID///////////
10199 const hasPropIdFilter = ctx ?. query ?. filters [ "$and" ] ?. find ( ( elem ) =>
102100 elem ?. hasOwnProperty ( "prop_id" )
@@ -122,17 +120,14 @@ module.exports = createCoreController(
122120 } ) ;
123121 }
124122 //////////////////////////////
125-
126123 /////IS DRAFT///////////
127124 const hasIsDraftFilter = ctx ?. query ?. filters [ "$and" ] ?. find ( ( elem ) =>
128125 elem ?. hasOwnProperty ( "is_draft" )
129126 ) ;
130-
131127 if ( hasIsDraftFilter ) {
132- if ( ! ctx ?. state ?. user ) {
133- return ctx . badRequest ( null , "User is required" ) ;
134- }
135-
128+ if ( ! ctx ?. state ?. user ) {
129+ return ctx . badRequest ( null , "User is required" ) ;
130+ }
136131 const hasIsDraftFilterInSanitize = sanitizedQueryParams ?. filters [
137132 "$and"
138133 ] ?. some ( ( elem ) => elem ?. hasOwnProperty ( "is_draft" ) ) ;
@@ -142,6 +137,14 @@ module.exports = createCoreController(
142137 user_id : ctx ?. state ?. user ?. id ,
143138 } ) ;
144139 }
140+ const hasUserFilterInSanitize = sanitizedQueryParams ?. filters [
141+ "$and"
142+ ] ?. some ( ( elem ) => elem ?. hasOwnProperty ( "user_id" ) ) ;
143+ if ( ! hasUserFilterInSanitize ) {
144+ sanitizedQueryParams . filters [ "$and" ] . push ( {
145+ user_id : ctx ?. state ?. user ?. id ,
146+ } )
147+ } ;
145148 } else {
146149 sanitizedQueryParams . filters [ "$and" ] . push ( {
147150 is_draft : false ,
@@ -176,7 +179,7 @@ module.exports = createCoreController(
176179 proposal . content = transformedProposalContent ?. data ;
177180 proposalsList . push ( proposal ) ;
178181 }
179-
182+ console . log ( JSON . stringify ( sanitizedQueryParams ) , "params" ) ;
180183 return this . transformResponse ( proposalsList , { pagination } ) ;
181184 } ,
182185 async findOne ( ctx ) {
0 commit comments