Skip to content

Commit

Permalink
refactor: add user address to profile endpoint response, add UserProf…
Browse files Browse the repository at this point in the history
…ile type (#1879)
  • Loading branch information
1emu authored Jul 17, 2024
1 parent 4d19830 commit 841394f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/entities/User/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<UserProfile> {
const address = validateAddress(req.params.address)
return await UserService.getProfile(address)
}
Expand Down
9 changes: 5 additions & 4 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -212,7 +212,7 @@ export class UserService {
}
}

static async getProfile(address: string) {
static async getProfile(address: string): Promise<UserProfile> {
try {
const user = await UserModel.findOne<UserAttributes>({ address: address.toLowerCase() })
if (!user) {
Expand All @@ -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,
Expand Down

0 comments on commit 841394f

Please sign in to comment.