import { FriendConstants , interceptorConstants , ResponseMessagesConstants , User } from '../../projects/shared-library/src/lib/shared/model' ; import { MakeFriends } from '../utils/make-friends' ; import { Utils } from '../utils/utils' ; export class FriendController { /**
     * getSubscriptionCount
     * return count
     */ static async createFriends ( req , res ) { const token = req . body . token ; const userId = req . body . userId ; const email = req . body . email ; try { const makeFriends = new MakeFriends ( token , userId , email ) ; const invitee = await makeFriends . validateToken ( ) ; Utils . sendResponse ( res , interceptorConstants . SUCCESS , { created_uid : invitee } ) ; } catch ( error ) { Utils . sendError ( res , error ) ; } } /**
     * createInvitations
     * return string
     */ static async createInvitations ( req , res ) { const userId = req . body . userId ; let emails = req . body . emails ; const inviteeUserId = req . body . inviteeUserId ; if ( ( inviteeUserId || emails ) && userId ) { const makeFriends = new MakeFriends ( undefined , userId , undefined ) ; try { if ( inviteeUserId ) { const user = await makeFriends . getUser ( inviteeUserId ) ; if ( inviteeUserId && user ) { emails = [ user . email ] ; const status = await makeFriends . createInvitations ( emails ) ; Utils . sendResponse ( res , interceptorConstants . SUCCESS , { messages : status . join ( FriendConstants . BR_HTML ) } ) ; } } else { const status = await makeFriends . createInvitations ( emails ) ; Utils . sendResponse ( res , interceptorConstants . SUCCESS , { messages : status . join ( FriendConstants . BR_HTML ) } ) ; } } catch ( error ) { Utils . sendError ( res , error ) ; } } else { Utils . sendResponse ( res , interceptorConstants . BAD_REQUEST , ResponseMessagesConstants . BAD_REQUEST ) ; } } }