@@ -136,6 +136,7 @@ const myBuildQuery = (fetchType, resource, params) => {
136
136
else if ( fetchType === 'GET_LIST' ) {
137
137
let page = params . pagination . page ;
138
138
let perPage = params . pagination . perPage ;
139
+ let filter = params . filter ;
139
140
switch ( resource ) {
140
141
case "Routine" :
141
142
const get_list_routine = gql `
@@ -146,7 +147,6 @@ const myBuildQuery = (fetchType, resource, params) => {
146
147
isDraft
147
148
batch
148
149
faculty
149
-
150
150
}
151
151
}
152
152
}
@@ -163,17 +163,21 @@ const myBuildQuery = (fetchType, resource, params) => {
163
163
} ;
164
164
case "Event" :
165
165
const get_list_event = gql `
166
- query all${ resource } s {
167
- all${ resource } s {
168
- title
169
- date
170
- id
171
- registrants
172
- noOfRegistrants
173
- categories
174
- location
175
- description
176
- }
166
+ query allEvents($page : Int, $perPage : Int, $filter : FilterEvent){
167
+ event{
168
+ allEvents(page : $page, perPage : $perPage, filter : $filter){
169
+ count
170
+ data {
171
+ id
172
+ date
173
+ title
174
+ location
175
+ categories
176
+ noOfRegistrants
177
+ description
178
+ }
179
+ }
180
+ }
177
181
}
178
182
` ;
179
183
return {
@@ -182,31 +186,39 @@ const myBuildQuery = (fetchType, resource, params) => {
182
186
parseResponse : response => {
183
187
console . log ( response ) ;
184
188
return {
185
- data : response . data [ `all ${ resource } s` ] ,
186
- total : response . data [ `all ${ resource } s` ] . length ,
189
+ data : response . data . event . allEvents . data ,
190
+ total : response . data . event . allEvents . count ,
187
191
} ;
188
192
} ,
189
193
} ;
190
194
case "User" :
191
195
const get_list_user = gql `
192
- query allUsers($page : Int, $perPage : Int){
196
+ query allUsers($page : Int, $perPage : Int, $filter : FilterUser ){
193
197
user{
194
- allUsers(page : $page, perPage : $perPage) {
195
- id,
196
- fullName,
197
- primaryEmail,
198
+ allUsers(page : $page, perPage : $perPage, filter : $filter) {
199
+ count
200
+ data {
201
+ id
202
+ fullName
203
+ primaryEmail
204
+ userRole
205
+ gender
206
+ batch
207
+ faculty
208
+ userType
209
+ }
198
210
}
199
211
}
200
212
}
201
213
` ;
202
214
return {
203
215
query : get_list_user ,
204
- variables : { page, perPage} , // You can add variables if needed
216
+ variables : { page, perPage, filter } , // You can add variables if needed
205
217
parseResponse : response => {
206
218
console . log ( response ) ;
207
219
return {
208
- data : response . data . user . allUsers ,
209
- total : response . data . user . allUsers . length ,
220
+ data : response . data . user . allUsers . data ,
221
+ total : response . data . user . allUsers . count ,
210
222
} ;
211
223
} ,
212
224
} ;
@@ -289,93 +301,165 @@ const myBuildQuery = (fetchType, resource, params) => {
289
301
}
290
302
} else if ( fetchType === 'UPDATE' ) {
291
303
let data = params . data ;
292
- let schedule = {
293
- ...data . schedule ,
294
- } ;
295
- delete schedule . __typename ;
296
- for ( let key in schedule ) {
297
- console . log ( key ) ;
298
- if ( Array . isArray ( schedule [ key ] ) ) {
299
- schedule [ key ] = schedule [ key ] . map ( ( d ) => {
300
- delete d . __typename ;
301
- return d ;
302
- } ) ;
303
- }
304
- }
305
-
306
- console . log ( schedule ) ;
307
- const update_routine = gql `
308
- fragment DayScheduleFields on SubjectSchedule {
309
- subject
310
- startTime
311
- endTime
312
- }
313
- mutation updateRoutine($id : String!, $batch :Int!, $faculty :Faculty!, $schedule : InputDaySchedule!, $isDraft : Boolean!) {
314
- routine {
315
- updateRoutine(id: $id, updatedRoutine: {
316
- batch : $batch,
317
- isDraft : $isDraft,
318
- faculty : $faculty,
319
- schedule : $schedule
320
- }){
321
- id
322
- batch
323
- isDraft
324
- faculty
325
- schedule{
326
- sun { ...DayScheduleFields }
327
- mon { ...DayScheduleFields }
328
- tue { ...DayScheduleFields }
329
- wed { ...DayScheduleFields }
330
- thu { ...DayScheduleFields }
331
- fri { ...DayScheduleFields }
332
- }
304
+ switch ( resource ) {
305
+ case "Routine" :
306
+ let schedule = {
307
+ ...data . schedule ,
308
+ } ;
309
+ delete schedule . __typename ;
310
+ for ( let key in schedule ) {
311
+ console . log ( key ) ;
312
+ if ( Array . isArray ( schedule [ key ] ) ) {
313
+ schedule [ key ] = schedule [ key ] . map ( ( d ) => {
314
+ delete d . __typename ;
315
+ return d ;
316
+ } ) ;
317
+ }
333
318
}
334
- }
335
- }` ;
336
319
337
- return {
338
- query : update_routine ,
339
- variables : {
340
- id : params . data . id ,
341
- batch : params . data . batch ,
342
- faculty : params . data . faculty ,
343
- isDraft : params . data . isDraft ,
344
- schedule : schedule
345
- } , // You can add variables if needed
346
- parseResponse : response => {
347
- console . log ( response ) ;
320
+ const update_routine = gql `
321
+ fragment DayScheduleFields on SubjectSchedule {
322
+ subject
323
+ startTime
324
+ endTime
325
+ }
326
+ mutation updateRoutine(
327
+ $id : String!,
328
+ $batch :Int!,
329
+ $faculty :Faculty!,
330
+ $schedule : InputDaySchedule!,
331
+ $isDraft : Boolean!) {
332
+ routine {
333
+ updateRoutine(id: $id, updatedRoutine: {
334
+ batch : $batch,
335
+ isDraft : $isDraft,
336
+ faculty : $faculty,
337
+ schedule : $schedule
338
+ }){
339
+ id
340
+ batch
341
+ isDraft
342
+ faculty
343
+ schedule{
344
+ sun { ...DayScheduleFields }
345
+ mon { ...DayScheduleFields }
346
+ tue { ...DayScheduleFields }
347
+ wed { ...DayScheduleFields }
348
+ thu { ...DayScheduleFields }
349
+ fri { ...DayScheduleFields }
350
+ }
351
+ }
352
+ }
353
+ }` ;
354
+
348
355
return {
349
- data : {
350
- ...response . data . routine . updateRoutine
356
+ query : update_routine ,
357
+ variables : {
358
+ id : params . data . id ,
359
+ batch : params . data . batch ,
360
+ faculty : params . data . faculty ,
361
+ isDraft : params . data . isDraft ,
362
+ schedule : schedule
363
+ } , // You can add variables if needed
364
+ parseResponse : response => {
365
+ console . log ( response ) ;
366
+ return {
367
+ data : {
368
+ ...response . data . routine . updateRoutine
369
+ } ,
370
+ } ;
351
371
} ,
352
372
} ;
353
- } ,
354
- } ;
355
- } else if ( fetchType === 'DELETE' ) {
356
- switch ( resource ) {
357
- case "Routine" :
358
- const delete_mutation = gql `
359
- mutation deleteRoutine($id: String!) {
360
- routine{
361
- delete${ resource } (id: $id)
362
- }
363
- }
364
- ` ;
373
+ case "User" :
374
+ console . log ( params ) ;
375
+ const update_user = gql `
376
+ mutation updateUser(
377
+ $id : String!,
378
+ $fullName: String,
379
+ $primaryEmail: String!,
380
+ $password: String,
381
+ $secondaryEmail: String,
382
+ $gender: Gender,
383
+ $phoneNumber: String,
384
+ $registeredEvents : [String!]
385
+ $certificates : [String!]
386
+ $batch: Int,
387
+ $imageUrl: String,
388
+ $userRole: UserRole,
389
+ $faculty: Faculty
390
+ $userType: UserType,
391
+ ) {
392
+ user {
393
+ updateUser(
394
+ id : $id
395
+ updatedUser: {
396
+ fullName: $fullName,
397
+ primaryEmail: $primaryEmail,
398
+ password: $password,
399
+ secondaryEmail: $secondaryEmail,
400
+ gender: $gender,
401
+ phoneNumber: $phoneNumber,
402
+ registeredEvents : $registeredEvents,
403
+ certificates : $certificates,
404
+ batch: $batch,
405
+ imageUrl: $imageUrl,
406
+ userRole: $userRole,
407
+ faculty: $faculty,
408
+ userType: $userType,
409
+ })
410
+ }
411
+ }
412
+ ` ;
413
+
365
414
return {
366
- query : delete_mutation ,
367
- variables : { id : params . id } ,
415
+ query : update_user ,
416
+ variables : {
417
+ id : params . id ,
418
+ fullName : data . fullName ,
419
+ primaryEmail : data . primaryEmail ,
420
+ password : data . password ,
421
+ secondaryEmail : data . secondaryEmail ,
422
+ gender : data . gender ,
423
+ phoneNumber : data . phoneNumber ,
424
+ registeredEvents : data . registeredEvents ,
425
+ certificates : data . certificates ,
426
+ batch : data . batch ,
427
+ imageUrl : data . imageUrl ,
428
+ userRole : data . userRole ,
429
+ faculty : data . faculty ,
430
+ userType : data . userType ,
431
+ } ,
368
432
parseResponse : response => {
369
- if ( response . data . routine . deleteRoutine > 0 ) {
370
- return { data : { id : params . id } } ;
371
- }
372
- throw new Error ( `Could not delete ${ resource } ` ) ;
433
+ console . log ( data ) ;
434
+ console . log ( response ) ;
435
+ return {
436
+ data
437
+ } ;
373
438
} ,
374
439
} ;
375
440
}
376
441
377
- } else if ( fetchType === 'GET_ONE' ) {
378
- console . log ( 'I AM HERE TO GET ONE' ) ;
442
+ } else if ( fetchType === 'DELETE' ) {
443
+ let id = params . id ;
444
+ const delete_mutation = gql `
445
+ mutation delete${ resource } ($id: String!) {
446
+ ${ resource . toLowerCase ( ) } {
447
+ delete${ resource } (id: $id)
448
+ }
449
+ }
450
+ ` ;
451
+ return {
452
+ query : delete_mutation ,
453
+ variables : {
454
+ id
455
+ } ,
456
+ parseResponse : response => {
457
+ if ( response . data [ resource . toLowerCase ( ) ] [ `delete${ resource } ` ] > 0 ) {
458
+ return { data : { id : params . id } } ;
459
+ }
460
+ throw new Error ( `Could not delete ${ resource } ` ) ;
461
+ } ,
462
+ } ;
379
463
}
380
464
return null ; // Return null for unsupported fetch types
381
465
} ;
0 commit comments