Skip to content

Commit

Permalink
Merge pull request #302 from nevermined-io/feat/return-additional-inf…
Browse files Browse the repository at this point in the history
…ormation

feat: return additional information in the profile reduced
  • Loading branch information
eruizgar91 authored Mar 4, 2024
2 parents 2eaaa3f + e2da6ed commit 879da3d
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 182 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marketplace_api",
"version": "0.8.1",
"version": "0.8.2",
"description": "The API allowing to manage Nevermined Marketplace common functionalities",
"main": "main.ts",
"scripts": {
Expand Down
32 changes: 31 additions & 1 deletion src/user-profiles/dto/additional-information.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsUrl, IsOptional } from 'class-validator'
import { IsUrl, IsOptional, IsBoolean, IsEnum, ValidateNested } from 'class-validator'
import { PaymentMethodsAccepted } from '../../common/type'
import { Stripe } from '../user-profile.interface'
import { Type } from 'class-transformer'
import { StripeDto } from './stripe.dto'

export class AdditionalInformation {
@ApiProperty({
Expand All @@ -21,4 +25,30 @@ export class AdditionalInformation {
require_tld: false,
})
linkedinProfile: string

@ApiProperty({
example: true,
description:
'Flag identifying if the user is enabled to publish content in the marketplace. Possible values: true or false',
})
@IsBoolean()
@IsOptional()
isPublisherEnabled: boolean

@ApiProperty({
example: PaymentMethodsAccepted,
description: 'Payment methods accepted by the user',
})
@IsOptional()
@IsEnum(PaymentMethodsAccepted)
paymentMethodsAccepted: PaymentMethodsAccepted

@ApiProperty({
example: StripeDto,
description: 'Stripe account information',
})
@ValidateNested()
@IsOptional()
@Type(() => StripeDto)
stripe: Stripe
}
30 changes: 1 addition & 29 deletions src/user-profiles/dto/create-user-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsString, IsEmail, IsBoolean, IsEnum, IsOptional, ValidateNested } from 'class-validator'
import { Type } from 'class-transformer'
import { PaymentMethodsAccepted, State } from '../../common/type'
import { State } from '../../common/type'
import { AdditionalInformation } from './additional-information.dto'
import { StripeDto } from './stripe.dto'
import { Stripe } from '../user-profile.interface'

export class CreateUserProfileDto {
@ApiProperty({
Expand Down Expand Up @@ -67,30 +65,4 @@ export class CreateUserProfileDto {
@ValidateNested()
@Type(() => AdditionalInformation)
additionalInformation: AdditionalInformation

@ApiProperty({
example: true,
description:
'Flag identifying if the user is enabled to publish content in the marketplace. Possible values: true or false',
})
@IsBoolean()
@IsOptional()
isPublisherEnabled: boolean

@ApiProperty({
example: PaymentMethodsAccepted,
description: 'Payment methods accepted by the user',
})
@IsEnum(PaymentMethodsAccepted)
@IsOptional()
paymentMethodsAccepted: PaymentMethodsAccepted

@ApiProperty({
example: StripeDto,
description: 'Stripe account information',
})
@ValidateNested()
@IsOptional()
@Type(() => StripeDto)
stripe: Stripe
}
12 changes: 11 additions & 1 deletion src/user-profiles/dto/get-user-profile-restricted.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsString } from 'class-validator'
import { IsString, ValidateNested } from 'class-validator'
import { AdditionalInformation } from './additional-information.dto'
import { Type } from 'class-transformer'

export class RestrictedUserProfileDto {
@ApiProperty({
Expand All @@ -15,4 +17,12 @@ export class RestrictedUserProfileDto {
})
@IsString()
nickname: string

@ApiProperty({
example: AdditionalInformation,
description: 'List of additional key-value attributes with additional information',
})
@ValidateNested()
@Type(() => AdditionalInformation)
additionalInformation: AdditionalInformation
}
39 changes: 1 addition & 38 deletions src/user-profiles/dto/get-user-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ import {
ValidateNested,
} from 'class-validator'
import { Type } from 'class-transformer'
import { PaymentMethodsAccepted, State } from '../../common/type'
import { State } from '../../common/type'
import { AdditionalInformation } from './additional-information.dto'
import { SearchHit } from '@elastic/elasticsearch/lib/api/types'
import { UserProfile } from '../user-profile.entity'
import { Stripe } from '../user-profile.interface'
import { StripeDto } from './stripe.dto'

export class GetUserProfileDto {
static fromSource(userProfileSource: SearchHit<UserProfile>): GetUserProfileDto {
Expand All @@ -29,9 +27,6 @@ export class GetUserProfileDto {
userProfileSource._source.creationDate,
userProfileSource._source.updateDate,
userProfileSource._source.additionalInformation,
userProfileSource._source.isPublisherEnabled,
userProfileSource._source.paymentMethodsAccepted,
userProfileSource._source.stripe,
)
}

Expand Down Expand Up @@ -113,32 +108,6 @@ export class GetUserProfileDto {
@Type(() => AdditionalInformation)
additionalInformation: AdditionalInformation

@ApiProperty({
example: true,
description:
'Flag identifying if the user is enabled to publish content in the marketplace. Possible values: true or false',
})
@IsBoolean()
@IsOptional()
isPublisherEnabled: boolean

@ApiProperty({
example: PaymentMethodsAccepted,
description: 'Payment methods accepted by the user',
})
@IsOptional()
@IsEnum(PaymentMethodsAccepted)
paymentMethodsAccepted: PaymentMethodsAccepted

@ApiProperty({
example: StripeDto,
description: 'Stripe account information',
})
@ValidateNested()
@IsOptional()
@Type(() => StripeDto)
stripe: Stripe

constructor(
userId: string,
isListed: boolean,
Expand All @@ -150,9 +119,6 @@ export class GetUserProfileDto {
creationDate: Date,
updateDate: Date,
additionalInformation: AdditionalInformation,
isPublisherEnabled: boolean,
paymentMethodsAccepted: PaymentMethodsAccepted,
stripe: Stripe,
) {
this.userId = userId
this.isListed = isListed
Expand All @@ -164,8 +130,5 @@ export class GetUserProfileDto {
this.creationDate = creationDate
this.updateDate = updateDate
this.additionalInformation = additionalInformation
this.isPublisherEnabled = isPublisherEnabled
this.paymentMethodsAccepted = paymentMethodsAccepted
this.stripe = stripe
}
}
39 changes: 1 addition & 38 deletions src/user-profiles/dto/update-user-profile.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import {
ValidateNested,
} from 'class-validator'
import { Type, Transform } from 'class-transformer'
import { PaymentMethodsAccepted, State } from '../../common/type'
import { State } from '../../common/type'
import { AdditionalInformation } from './additional-information.dto'
import { StripeDto } from './stripe.dto'
import { Stripe } from '../user-profile.interface'

export class UpdateUserProfileDto {
static fromPayload(userProfile: UpdateUserProfileDto): UpdateUserProfileDto {
Expand All @@ -25,9 +23,6 @@ export class UpdateUserProfileDto {
userProfile.email,
new Date(),
userProfile.additionalInformation,
userProfile.isPublisherEnabled,
userProfile.paymentMethodsAccepted,
userProfile.stripe,
)
}

Expand Down Expand Up @@ -102,32 +97,6 @@ export class UpdateUserProfileDto {
@IsDate()
updateDate: Date

@ApiProperty({
example: true,
description:
'Flag identifying if the user is enabled to publish content in the marketplace. Possible values: true or false',
})
@IsOptional()
@IsBoolean()
isPublisherEnabled: boolean

@ApiProperty({
example: PaymentMethodsAccepted,
description: 'Payment methods accepted by the user',
})
@IsOptional()
@IsEnum(PaymentMethodsAccepted)
paymentMethodsAccepted: PaymentMethodsAccepted

@ApiProperty({
example: StripeDto,
description: 'Stripe account information',
})
@IsOptional()
@ValidateNested()
@Type(() => StripeDto)
stripe: Stripe

constructor(
isListed: boolean,
state: State,
Expand All @@ -137,9 +106,6 @@ export class UpdateUserProfileDto {
email: string,
updateDate: Date,
additionalInformation: AdditionalInformation,
isPublisherEnabled: boolean,
paymentMethodsAccepted: PaymentMethodsAccepted,
stripe: Stripe,
) {
this.isListed = isListed
this.state = state
Expand All @@ -149,8 +115,5 @@ export class UpdateUserProfileDto {
this.email = email
this.updateDate = updateDate
this.additionalInformation = additionalInformation
this.isPublisherEnabled = isPublisherEnabled
this.paymentMethodsAccepted = paymentMethodsAccepted
this.stripe = stripe
}
}
28 changes: 18 additions & 10 deletions src/user-profiles/user-profile.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ describe('UserProfileController', () => {
userProfile.name = faker.person.fullName()
userProfile.email = faker.internet.email()
userProfile.state = State.Confirmed
userProfile.isPublisherEnabled = false
userProfile.paymentMethodsAccepted = PaymentMethodsAccepted.NotSelected
userProfile.stripe = {
accountId: faker.string.uuid(),
isAccountValidated: false,
accountCreatedAt: faker.date.past().toDateString(),
accountUpdatedAt: faker.date.recent().toDateString(),
additionalInformation: {},
} as Stripe
userProfile.additionalInformation = {
linkedinProfile: faker.internet.url(),
profilePicture: faker.internet.url(),
isPublisherEnabled: false,
paymentMethodsAccepted: PaymentMethodsAccepted.NotSelected,
stripe: {
accountId: faker.string.uuid(),
isAccountValidated: false,
accountCreatedAt: faker.date.past().toDateString(),
accountUpdatedAt: faker.date.recent().toDateString(),
additionalInformation: {},
} as Stripe,
}

const req = {
url: '/api/v1/ugc/bookmarks',
Expand Down Expand Up @@ -116,7 +120,11 @@ describe('UserProfileController', () => {

expect(
await userProfileController.getUserProfileByAddress(userProfile.addresses[0]),
).toStrictEqual({ userId: userProfile.userId, nickname: userProfile.nickname })
).toStrictEqual({
userId: userProfile.userId,
nickname: userProfile.nickname,
additionalInformation: userProfile.additionalInformation,
})
})

it('should thorw error when no user profile is found by the address given', async () => {
Expand Down
6 changes: 5 additions & 1 deletion src/user-profiles/user-profile.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ export class UserProfileController {

const userProfile = GetUserProfileDto.fromSource(userProfileSource)

return { userId: userProfile.userId, nickname: userProfile.nickname }
return {
userId: userProfile.userId,
nickname: userProfile.nickname,
additionalInformation: userProfile.additionalInformation,
}
}

@Put(':userId')
Expand Down
7 changes: 2 additions & 5 deletions src/user-profiles/user-profile.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PaymentMethodsAccepted, State } from '../common/type'
import { AdditionalInformation, Stripe } from './user-profile.interface'
import { State } from '../common/type'
import { AdditionalInformation } from './user-profile.interface'
import { v4 as uuidv4 } from 'uuid'

export class UserProfile {
Expand All @@ -13,9 +13,6 @@ export class UserProfile {
creationDate: Date
updateDate: Date
additionalInformation: AdditionalInformation
isPublisherEnabled: boolean
paymentMethodsAccepted: PaymentMethodsAccepted
stripe: Stripe

constructor() {
this.creationDate = new Date()
Expand Down
Loading

0 comments on commit 879da3d

Please sign in to comment.