diff --git a/src/entities/User/types.ts b/src/entities/User/types.ts index f3496099a..54be9b9f9 100644 --- a/src/entities/User/types.ts +++ b/src/entities/User/types.ts @@ -9,6 +9,13 @@ export type UserAttributes = { is_discord_notifications_active?: boolean } +export type UserProfile = Pick< + UserAttributes, + 'address' | 'forum_id' | 'forum_verification_date' | 'discord_verification_date' +> & { + forum_username?: string | null +} + export type ValidationMessage = { address: string timestamp: string diff --git a/src/routes/user.ts b/src/routes/user.ts index 1b2e897cb..a98af79af 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -3,6 +3,7 @@ import handleAPI from 'decentraland-gatsby/dist/entities/Route/handle' import routes from 'decentraland-gatsby/dist/entities/Route/routes' import { Request } from 'express' +import { UserProfile } from '../entities/User/types' import { validateAccountTypes } from '../entities/User/utils' import { UserService } from '../services/user' import { validateAddress } from '../utils/validations' @@ -62,7 +63,7 @@ async function isValidated(req: Request) { return await UserService.isValidated(address, new Set(accounts)) } -async function getProfile(req: Request) { +async function getProfile(req: Request): Promise { const address = validateAddress(req.params.address) return await UserService.getProfile(address) } diff --git a/src/services/user.ts b/src/services/user.ts index 14d452b8c..5e01dd69c 100644 --- a/src/services/user.ts +++ b/src/services/user.ts @@ -4,13 +4,13 @@ import { PUSH_CHANNEL_ID } from '../constants' import { isSameAddress } from '../entities/Snapshot/utils' import { GATSBY_DISCOURSE_CONNECT_THREAD, MESSAGE_TIMEOUT_TIME } from '../entities/User/constants' import UserModel from '../entities/User/model' -import { AccountType, UserAttributes, ValidationComment, ValidationMessage } from '../entities/User/types' +import { AccountType, UserAttributes, UserProfile, ValidationComment, ValidationMessage } from '../entities/User/types' import { formatValidationMessage, getValidationComment, toAccountType, validateComment } from '../entities/User/utils' -import { DiscourseService } from '../services/DiscourseService' -import { ErrorService } from '../services/ErrorService' import { isProdEnv } from '../utils/governanceEnvs' import { getCaipAddress, getPushNotificationsEnv } from '../utils/notifications' +import { DiscourseService } from './DiscourseService' +import { ErrorService } from './ErrorService' import { DiscordService } from './discord' import PushAPI = require('@pushprotocol/restapi') @@ -212,7 +212,7 @@ export class UserService { } } - static async getProfile(address: string) { + static async getProfile(address: string): Promise { try { const user = await UserModel.findOne({ address: address.toLowerCase() }) if (!user) { @@ -222,6 +222,7 @@ export class UserService { const { forum_id, forum_verification_date, discord_verification_date } = user return { + address, forum_id, forum_username: forum_id ? (await DiscourseService.getUserById(forum_id))?.username : null, forum_verification_date,