@@ -19,7 +19,10 @@ import {
1919 isUsersCheckUsernameAvailabilityParamsGET ,
2020 isUsersSendConfirmationEmailParamsPOST ,
2121 ajv ,
22+ validateBadRequestErrorResponse ,
23+ validateUnauthorizedErrorResponse ,
2224} from '@rocket.chat/rest-typings' ;
25+ import { ajv } from '@rocket.chat/rest-typings/src/v1/Ajv' ;
2326import { getLoginExpirationInMs , wrapExceptions } from '@rocket.chat/tools' ;
2427import { Accounts } from 'meteor/accounts-base' ;
2528import { Match , check } from 'meteor/check' ;
@@ -97,20 +100,6 @@ API.v1.addRoute(
97100 } ,
98101) ;
99102
100- API . v1 . addRoute (
101- 'users.getAvatarSuggestion' ,
102- {
103- authRequired : true ,
104- } ,
105- {
106- async get ( ) {
107- const suggestions = await getAvatarSuggestionForUser ( this . user ) ;
108-
109- return API . v1 . success ( { suggestions } ) ;
110- } ,
111- } ,
112- ) ;
113-
114103API . v1 . addRoute (
115104 'users.update' ,
116105 { authRequired : true , twoFactorRequired : true , validateParams : isUsersUpdateParamsPOST } ,
@@ -764,72 +753,132 @@ API.v1.addRoute(
764753 } ,
765754) ;
766755
767- const usersEndpoints = API . v1 . post (
768- 'users.createToken' ,
769- {
770- authRequired : true ,
771- body : ajv . compile < { userId : string ; secret : string } > ( {
772- type : 'object' ,
773- properties : {
774- userId : {
775- type : 'string' ,
776- minLength : 1 ,
777- } ,
778- secret : {
779- type : 'string' ,
780- minLength : 1 ,
781- } ,
782- } ,
783- required : [ 'userId' , 'secret' ] ,
784- additionalProperties : false ,
785- } ) ,
786- response : {
787- 200 : ajv . compile < { data : { userId : string ; authToken : string } } > ( {
756+ const usersEndpoints = API . v1
757+ . post (
758+ 'users.createToken' ,
759+ {
760+ authRequired : true ,
761+ body : ajv . compile < { userId : string ; secret : string } > ( {
788762 type : 'object' ,
789763 properties : {
790- data : {
791- type : 'object' ,
792- properties : {
793- userId : {
794- type : 'string' ,
795- minLength : 1 ,
796- } ,
797- authToken : {
798- type : 'string' ,
799- minLength : 1 ,
800- } ,
801- } ,
802- required : [ 'userId' ] ,
803- additionalProperties : false ,
764+ userId : {
765+ type : 'string' ,
766+ minLength : 1 ,
804767 } ,
805- success : {
806- type : 'boolean ' ,
807- enum : [ true ] ,
768+ secret : {
769+ type : 'string ' ,
770+ minLength : 1 ,
808771 } ,
809772 } ,
810- required : [ 'data' , 'success' ] ,
811- additionalProperties : false ,
812- } ) ,
813- 400 : ajv . compile ( {
814- type : 'object' ,
815- properties : {
816- success : { type : 'boolean' , enum : [ false ] } ,
817- error : { type : 'string' } ,
818- errorType : { type : 'string' } ,
819- } ,
820- required : [ 'success' ] ,
773+ required : [ 'userId' , 'secret' ] ,
821774 additionalProperties : false ,
822775 } ) ,
776+ response : {
777+ 200 : ajv . compile < { data : { userId : string ; authToken : string } } > ( {
778+ type : 'object' ,
779+ properties : {
780+ data : {
781+ type : 'object' ,
782+ properties : {
783+ userId : {
784+ type : 'string' ,
785+ minLength : 1 ,
786+ } ,
787+ authToken : {
788+ type : 'string' ,
789+ minLength : 1 ,
790+ } ,
791+ } ,
792+ required : [ 'userId' ] ,
793+ additionalProperties : false ,
794+ } ,
795+ success : {
796+ type : 'boolean' ,
797+ enum : [ true ] ,
798+ } ,
799+ } ,
800+ required : [ 'data' , 'success' ] ,
801+ additionalProperties : false ,
802+ } ) ,
803+ 400 : ajv . compile ( {
804+ type : 'object' ,
805+ properties : {
806+ success : { type : 'boolean' , enum : [ false ] } ,
807+ error : { type : 'string' } ,
808+ errorType : { type : 'string' } ,
809+ } ,
810+ required : [ 'success' ] ,
811+ additionalProperties : false ,
812+ } ) ,
813+ } ,
823814 } ,
824- } ,
825- async function action ( ) {
826- const user = await getUserFromParams ( this . bodyParams ) ;
815+ async function action ( ) {
816+ const user = await getUserFromParams ( this . bodyParams ) ;
827817
828- const data = await generateAccessToken ( user . _id , this . bodyParams . secret ) ;
818+ const data = await generateAccessToken ( user . _id , this . bodyParams . secret ) ;
829819
830- return API . v1 . success ( { data } ) ;
831- } ,
832- ) ;
820+ return API . v1 . success ( { data } ) ;
821+ } ,
822+ )
823+ . get (
824+ 'users.getAvatarSuggestion' ,
825+ {
826+ authRequired : true ,
827+ response : {
828+ 400 : validateBadRequestErrorResponse ,
829+ 401 : validateUnauthorizedErrorResponse ,
830+ 200 : ajv . compile < {
831+ suggestions : Record <
832+ string ,
833+ {
834+ blob : string ;
835+ contentType : string ;
836+ service : string ;
837+ url : string ;
838+ }
839+ > ;
840+ } > ( {
841+ type : 'object' ,
842+ properties : {
843+ success : {
844+ type : 'boolean' ,
845+ enum : [ true ] ,
846+ } ,
847+ suggestions : {
848+ type : 'object' ,
849+ additionalProperties : {
850+ type : 'object' ,
851+ properties : {
852+ blob : {
853+ type : 'string' ,
854+ } ,
855+ contentType : {
856+ type : 'string' ,
857+ } ,
858+ service : {
859+ type : 'string' ,
860+ } ,
861+ url : {
862+ type : 'string' ,
863+ format : 'uri' ,
864+ } ,
865+ } ,
866+ required : [ 'blob' , 'contentType' , 'service' , 'url' ] ,
867+ additionalProperties : false ,
868+ } ,
869+ } ,
870+ } ,
871+ required : [ 'success' , 'suggestions' ] ,
872+ additionalProperties : false ,
873+ } ) ,
874+ } ,
875+ } ,
876+ async function action ( ) {
877+ const suggestions = await getAvatarSuggestionForUser ( this . user ) ;
878+
879+ return API . v1 . success ( { suggestions } ) ;
880+ } ,
881+ ) ;
833882
834883API . v1 . addRoute (
835884 'users.getPreferences' ,
0 commit comments