diff --git a/package.json b/package.json index 868f25b..4520b3d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/user-profiles/dto/additional-information.dto.ts b/src/user-profiles/dto/additional-information.dto.ts index a4f6525..0f7f3c3 100644 --- a/src/user-profiles/dto/additional-information.dto.ts +++ b/src/user-profiles/dto/additional-information.dto.ts @@ -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({ @@ -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 } diff --git a/src/user-profiles/dto/create-user-profile.dto.ts b/src/user-profiles/dto/create-user-profile.dto.ts index aa7b9a7..55344dc 100644 --- a/src/user-profiles/dto/create-user-profile.dto.ts +++ b/src/user-profiles/dto/create-user-profile.dto.ts @@ -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({ @@ -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 } diff --git a/src/user-profiles/dto/get-user-profile-restricted.dto.ts b/src/user-profiles/dto/get-user-profile-restricted.dto.ts index cfa6bf4..274ecd1 100644 --- a/src/user-profiles/dto/get-user-profile-restricted.dto.ts +++ b/src/user-profiles/dto/get-user-profile-restricted.dto.ts @@ -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({ @@ -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 } diff --git a/src/user-profiles/dto/get-user-profile.dto.ts b/src/user-profiles/dto/get-user-profile.dto.ts index 3c2d828..5ff8f9b 100644 --- a/src/user-profiles/dto/get-user-profile.dto.ts +++ b/src/user-profiles/dto/get-user-profile.dto.ts @@ -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): GetUserProfileDto { @@ -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, ) } @@ -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, @@ -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 @@ -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 } } diff --git a/src/user-profiles/dto/update-user-profile.dto.ts b/src/user-profiles/dto/update-user-profile.dto.ts index 447be5f..b8c5e9e 100644 --- a/src/user-profiles/dto/update-user-profile.dto.ts +++ b/src/user-profiles/dto/update-user-profile.dto.ts @@ -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 { @@ -25,9 +23,6 @@ export class UpdateUserProfileDto { userProfile.email, new Date(), userProfile.additionalInformation, - userProfile.isPublisherEnabled, - userProfile.paymentMethodsAccepted, - userProfile.stripe, ) } @@ -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, @@ -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 @@ -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 } } diff --git a/src/user-profiles/user-profile.controller.spec.ts b/src/user-profiles/user-profile.controller.spec.ts index 5b22b7c..eb80dd5 100644 --- a/src/user-profiles/user-profile.controller.spec.ts +++ b/src/user-profiles/user-profile.controller.spec.ts @@ -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', @@ -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 () => { diff --git a/src/user-profiles/user-profile.controller.ts b/src/user-profiles/user-profile.controller.ts index afd0d26..b3f7446 100644 --- a/src/user-profiles/user-profile.controller.ts +++ b/src/user-profiles/user-profile.controller.ts @@ -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') diff --git a/src/user-profiles/user-profile.entity.ts b/src/user-profiles/user-profile.entity.ts index bdab7c1..745b44f 100644 --- a/src/user-profiles/user-profile.entity.ts +++ b/src/user-profiles/user-profile.entity.ts @@ -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 { @@ -13,9 +13,6 @@ export class UserProfile { creationDate: Date updateDate: Date additionalInformation: AdditionalInformation - isPublisherEnabled: boolean - paymentMethodsAccepted: PaymentMethodsAccepted - stripe: Stripe constructor() { this.creationDate = new Date() diff --git a/src/user-profiles/user-profile.integration.spec.ts b/src/user-profiles/user-profile.integration.spec.ts index 91667e3..d1cfced 100644 --- a/src/user-profiles/user-profile.integration.spec.ts +++ b/src/user-profiles/user-profile.integration.spec.ts @@ -37,15 +37,19 @@ describe('User Profile', () => { 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 userProfileTwo = { ...userProfile, @@ -143,13 +147,6 @@ describe('User Profile', () => { expect(response.statusCode).toBe(201) expect(response.body).toStrictEqual({ ...userProfile, - stripe: { - accountCreatedAt: userProfile.stripe.accountCreatedAt, - accountUpdatedAt: userProfile.stripe.accountUpdatedAt, - additionalInformation: {}, - accountId: userProfile.stripe.accountId, - isAccountValidated: userProfile.stripe.isAccountValidated, - }, creationDate: userProfile.creationDate.toISOString(), updateDate: userProfile.updateDate.toISOString(), }) @@ -163,13 +160,6 @@ describe('User Profile', () => { expect(response.statusCode).toBe(200) expect(response.body).toStrictEqual({ ...userProfile, - stripe: { - accountCreatedAt: userProfile.stripe.accountCreatedAt, - accountUpdatedAt: userProfile.stripe.accountUpdatedAt, - additionalInformation: {}, - accountId: userProfile.stripe.accountId, - isAccountValidated: userProfile.stripe.isAccountValidated, - }, creationDate: userProfile.creationDate.toISOString(), updateDate: userProfile.updateDate.toISOString(), }) @@ -198,7 +188,8 @@ describe('User Profile', () => { expect(response.statusCode).toBe(200) expect(response.body).toStrictEqual({ userId: userProfileTwo.userId, - name: userProfileTwo.name, + nickname: userProfileTwo.nickname, + additionalInformation: userProfileTwo.additionalInformation, }) }) @@ -229,13 +220,6 @@ describe('User Profile', () => { expect(response.body).toStrictEqual({ ...disbledUserProfile, - stripe: { - accountCreatedAt: disbledUserProfile.stripe.accountCreatedAt, - accountUpdatedAt: disbledUserProfile.stripe.accountUpdatedAt, - additionalInformation: {}, - accountId: disbledUserProfile.stripe.accountId, - isAccountValidated: disbledUserProfile.stripe.isAccountValidated, - }, creationDate: disbledUserProfile.creationDate.toISOString(), updateDate: disbledUserProfile.updateDate.toISOString(), }) diff --git a/src/user-profiles/user-profile.interface.ts b/src/user-profiles/user-profile.interface.ts index aada4be..f01bf9e 100644 --- a/src/user-profiles/user-profile.interface.ts +++ b/src/user-profiles/user-profile.interface.ts @@ -1,6 +1,11 @@ +import { PaymentMethodsAccepted } from '../common/type' + export interface AdditionalInformation { profilePicture: string linkedinProfile: string + isPublisherEnabled: boolean + paymentMethodsAccepted: PaymentMethodsAccepted + stripe: Stripe } export interface Stripe { diff --git a/src/user-profiles/user-profile.mappings.ts b/src/user-profiles/user-profile.mappings.ts index 4d2cc5a..17639f6 100644 --- a/src/user-profiles/user-profile.mappings.ts +++ b/src/user-profiles/user-profile.mappings.ts @@ -1,25 +1,5 @@ import { MappingProperty } from '@elastic/elasticsearch/lib/api/types' -const stripe: MappingProperty = { - properties: { - accountId: { - type: 'keyword', - }, - isAccountValidated: { - type: 'boolean', - }, - accountCreatedAt: { - type: 'date', - }, - accountUpdatedAt: { - type: 'date', - }, - additionalInformation: { - type: 'object', - }, - }, -} - export const UserProfileMappings: MappingProperty = { properties: { userId: { @@ -48,12 +28,5 @@ export const UserProfileMappings: MappingProperty = { updateDate: { type: 'date', }, - isPublisherEnabled: { - type: 'boolean', - }, - paymentMethodsAccepted: { - type: 'keyword', - }, - stripe, }, }