1+ import { assertUserInfo } from "@/assertions/user" ;
12import { UserPlan } from "@/types/user" ;
23import { APIUserInfo } from "@squarecloud/api-types/v2" ;
34import { BaseApplication , Collection , SquareCloudAPI } from ".." ;
@@ -24,15 +25,21 @@ export class User {
2425 applications : Collection < string , BaseApplication > ;
2526
2627 constructor ( client : SquareCloudAPI , data : APIUserInfo ) {
27- this . id = data . user . id ;
28- this . tag = data . user . tag ;
29- this . locale = data . user . locale ;
28+ assertUserInfo ( data ) ;
29+
30+ const { user, applications } = data ;
31+ const { id, tag, locale, plan, email } = user ;
32+ const { duration } = plan ;
33+
34+ this . id = id ;
35+ this . tag = tag ;
36+ this . locale = locale ;
37+ this . email = email ;
3038 this . plan = {
31- ...data . user . plan ,
32- expiresInTimestamp : data . user . plan . duration ?? undefined ,
33- expiresIn : data . user . plan . duration ? new Date ( data . user . plan . duration ) : undefined ,
39+ ...plan ,
40+ expiresInTimestamp : duration ?? undefined ,
41+ expiresIn : duration ? new Date ( duration ) : undefined ,
3442 } ;
35- this . email = data . user . email ;
36- this . applications = new Collection ( data . applications . map ( ( app ) => [ app . id , new BaseApplication ( client , app ) ] ) ) ;
43+ this . applications = new Collection ( applications . map ( ( app ) => [ app . id , new BaseApplication ( client , app ) ] ) ) ;
3744 }
3845}
0 commit comments