11import dayjs from "dayjs" ;
2+ import { AppTypes } from "../structures/App" ;
23
34interface UserData {
45 profilePicture : string ;
@@ -17,55 +18,56 @@ interface UserData {
1718 } ;
1819}
1920
21+ interface DestrucuredData {
22+ profilePicture : string ;
23+ bio : string ;
24+ userName : string ;
25+ id : string ;
26+ name : string ;
27+ school : string ;
28+ owner : boolean ;
29+ createdAt : dayjs . Dayjs ; // Update to correct type Dayjs
30+ role : string ;
31+ editAccessRoles ?: {
32+ roleIndex : number ;
33+ roleType : string ;
34+ } [ ] ;
35+ }
36+
2037class FilterData {
21- private client : any ;
38+ private client : AppTypes ;
2239
23- constructor ( client : any ) {
40+ constructor ( client : AppTypes ) {
2441 this . client = client ;
2542 }
2643
27- async user ( userType : string , findingUserData : UserData ) {
28- const destrucuredData : any = { } ;
44+ user ( userType : string , findingUserData : UserData ) : DestrucuredData {
45+ const destrucuredData : DestrucuredData = {
46+ profilePicture : findingUserData . profilePicture || "" ,
47+ bio : findingUserData . bio || "" ,
48+ userName : findingUserData . userName || "" ,
49+ id : String ( findingUserData . _id ) || "" ,
50+ name : findingUserData . name || "" ,
51+ school : findingUserData . school || "" ,
52+ owner : findingUserData . owner || false ,
53+ createdAt : dayjs ( findingUserData . createdAt ) , // Initialize with dayjs
54+ role : findingUserData . roles . roleType || "" ,
55+ } ;
2956
30- switch ( userType === "@me" ) {
31- case true : {
32- this . populateDestructuredData ( destrucuredData , findingUserData ) ;
33-
34- if ( findingUserData . roles . roleIndex === "1" ) {
35- destrucuredData . editAcessRoles = [
36- { roleIndex : 2 , roleType : "admin" } ,
37- { roleIndex : 3 , roleType : "staff" } ,
38- ] ;
39- } else if ( findingUserData . roles . roleIndex === "2" ) {
40- destrucuredData . editAcessRoles = [
41- { roleIndex : 3 , roleType : "staff" } ,
42- ] ;
43- } else if ( findingUserData . roles . roleIndex === "3" ) {
44- destrucuredData . editAcessRoles = [ ] ;
45- }
46- break ;
47- }
48- case false : {
49- this . populateDestructuredData ( destrucuredData , findingUserData ) ;
50- break ;
57+ if ( userType === "@me" ) {
58+ if ( findingUserData . roles . roleIndex === "1" ) {
59+ destrucuredData . editAccessRoles = [
60+ { roleIndex : 2 , roleType : "admin" } ,
61+ { roleIndex : 3 , roleType : "staff" } ,
62+ ] ;
63+ } else if ( findingUserData . roles . roleIndex === "2" ) {
64+ destrucuredData . editAccessRoles = [ { roleIndex : 3 , roleType : "staff" } ] ;
65+ } else if ( findingUserData . roles . roleIndex === "3" ) {
66+ destrucuredData . editAccessRoles = [ ] ;
5167 }
5268 }
53- return destrucuredData ;
54- }
5569
56- private populateDestructuredData (
57- destrucuredData : any ,
58- findingUserData : UserData
59- ) {
60- destrucuredData . profilePicture = findingUserData . profilePicture || "" ;
61- destrucuredData . bio = findingUserData . bio || "" ;
62- destrucuredData . userName = findingUserData . userName || "" ;
63- destrucuredData . id = String ( findingUserData . _id ) || "" ;
64- destrucuredData . name = findingUserData . name || "" ;
65- destrucuredData . school = findingUserData . school || "" ;
66- destrucuredData . owner = findingUserData . owner || false ;
67- destrucuredData . createdAt = dayjs ( findingUserData . createdAt ) || "" ;
68- destrucuredData . role = findingUserData . roles . roleType || "" ;
70+ return destrucuredData ;
6971 }
7072}
7173
0 commit comments