import BaseDataSource from '../shared/base.datasource' ; import { MutationLinkViewerSocialAccountArgs , MutationUnlinkViewerSocialAccountArgs , UserInput , } from '../generated/graphql' ; import { ID } from '@api/shared/shared.types' ; import { verifySocialAccountToken } from '@api/auth/authtoken.utils' ; export class UserAPI extends BaseDataSource { async findOneUserById ( id ) { const { db } = this . context ; const user = await db . user . findOneById ( id ) ; return user ; } async updateUser ( id , input ) { const { db } = this . context ; const user = await db . user . patch ( id , input ) ; return user ; } async linkViewerSocialAccount ( args ) { const { profileId } = await verifySocialAccountToken ( args ) ; const { db } = this . context ; const { socialAccountType } = args ; const updatedViewer = await db . user . linkSocialAccount ( { socialAccountType , profileId , } ) ; return updatedViewer ; } async unlinkViewerSocialAccount ( args ) { const { socialAccountType } = args ; const { db } = this . context ; const updatedViewer = await db . user . unlinkSocialAccount ( socialAccountType ) ; return updatedViewer ; } }