diff --git a/src/config/config.ts b/src/config/config.ts index df5b25d5bb..c401fc2a74 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -402,7 +402,7 @@ export class Configuration { { id: 12, name: 'Vollmacht', - ignore: (userData: UserData) => userData.accountOpenerAuthorization !== 'Vollmacht', + ignore: (userData: UserData) => userData.organization?.accountOpenerAuthorization !== 'Vollmacht', files: [ { prefixes: (userData: UserData) => [`user/${userData.id}/Authority`], diff --git a/src/shared/services/process.service.ts b/src/shared/services/process.service.ts index 3eb3f89fc4..a4ddeb2afe 100644 --- a/src/shared/services/process.service.ts +++ b/src/shared/services/process.service.ts @@ -57,7 +57,6 @@ export enum Process { BLOCKCHAIN_FEE_UPDATE = 'BlockchainFeeUpdate', TX_REQUEST_STATUS_SYNC = 'TxRequestStatusSync', TX_REQUEST_WAITING_EXPIRY = 'TxRequestWaitingExpiry', - ORGANIZATION_SYNC = 'OrganizationSync', BANK_TX_RETURN = 'BankTxReturn', CUSTODY = 'Custody', EXCHANGE_WITHDRAWAL = 'ExchangeWithdrawal', diff --git a/src/subdomains/generic/kyc/entities/kyc-step.entity.ts b/src/subdomains/generic/kyc/entities/kyc-step.entity.ts index e520647550..001178648e 100644 --- a/src/subdomains/generic/kyc/entities/kyc-step.entity.ts +++ b/src/subdomains/generic/kyc/entities/kyc-step.entity.ts @@ -387,7 +387,7 @@ export class KycStep extends IEntity { get identDocumentId(): string { const data = this.resultData; - return data ? `${this.userData.organizationName?.split(' ')?.join('') ?? ''}${data.documentNumber}` : undefined; + return data ? `${this.userData.organization.name?.split(' ')?.join('') ?? ''}${data.documentNumber}` : undefined; } get isValidCreatingBankData(): boolean { diff --git a/src/subdomains/generic/kyc/enums/kyc.enum.ts b/src/subdomains/generic/kyc/enums/kyc.enum.ts index bf7ce1aefb..059a7b5101 100644 --- a/src/subdomains/generic/kyc/enums/kyc.enum.ts +++ b/src/subdomains/generic/kyc/enums/kyc.enum.ts @@ -17,14 +17,16 @@ export function requiredKycSteps(userData: UserData): KycStepName[] { KycStepName.NATIONALITY_DATA, userData.accountType === AccountType.ORGANIZATION ? KycStepName.LEGAL_ENTITY : null, userData.accountType === AccountType.ORGANIZATION && - !(userData.legalEntity === LegalEntity.GMBH && userData.organizationCountry?.symbol === 'CH') + !(userData.organization?.legalEntity === LegalEntity.GMBH && userData.organization?.country?.symbol === 'CH') ? KycStepName.OWNER_DIRECTORY : null, [AccountType.ORGANIZATION, AccountType.SOLE_PROPRIETORSHIP].includes(userData.accountType) ? KycStepName.COMMERCIAL_REGISTER : null, userData.accountType === AccountType.ORGANIZATION ? KycStepName.SIGNATORY_POWER : null, - [SignatoryPower.DOUBLE, SignatoryPower.NONE].includes(userData.signatoryPower) ? KycStepName.AUTHORITY : null, + [SignatoryPower.DOUBLE, SignatoryPower.NONE].includes(userData.organization?.signatoryPower) + ? KycStepName.AUTHORITY + : null, userData.accountType === AccountType.ORGANIZATION ? [KycStepName.BENEFICIAL_OWNER, KycStepName.OPERATIONAL_ACTIVITY] : null, diff --git a/src/subdomains/generic/kyc/services/kyc.service.ts b/src/subdomains/generic/kyc/services/kyc.service.ts index 83dfb874c0..364d3344d9 100644 --- a/src/subdomains/generic/kyc/services/kyc.service.ts +++ b/src/subdomains/generic/kyc/services/kyc.service.ts @@ -26,6 +26,7 @@ import { MergeReason } from '../../user/models/account-merge/account-merge.entit import { AccountMergeService } from '../../user/models/account-merge/account-merge.service'; import { BankDataType } from '../../user/models/bank-data/bank-data.entity'; import { BankDataService } from '../../user/models/bank-data/bank-data.service'; +import { OrganizationService } from '../../user/models/organization/organization.service'; import { UserDataRelationState } from '../../user/models/user-data-relation/dto/user-data-relation.enum'; import { UserDataRelationService } from '../../user/models/user-data-relation/user-data-relation.service'; import { AccountType } from '../../user/models/user-data/account-type.enum'; @@ -48,10 +49,12 @@ import { KycBeneficialData, KycContactData, KycFileData, + KycLegalEntityData, KycManualIdentData, KycNationalityData, KycOperationalData, KycPersonalData, + KycSignatoryPowerData, PaymentDataDto, } from '../dto/input/kyc-data.dto'; import { KycFinancialInData, KycFinancialResponse } from '../dto/input/kyc-financial-in.dto'; @@ -115,6 +118,7 @@ export class KycService { private readonly mailFactory: MailFactory, @Inject(forwardRef(() => UserDataRelationService)) private readonly userDataRelationService: UserDataRelationService, + private readonly organizationService: OrganizationService, ) { this.webhookQueue = new QueueHandler(); } @@ -422,17 +426,17 @@ export class KycService { async updateKycStep( kycHash: string, stepId: number, - data: Partial, + data: KycLegalEntityData | KycNationalityData | KycSignatoryPowerData, reviewStatus: KycStepStatus, ): Promise { - let user = await this.getUser(kycHash); + const user = await this.getUser(kycHash); const kycStep = user.getPendingStepOrThrow(stepId); - if (data.nationality) { + if (data instanceof KycNationalityData) { const nationality = await this.countryService.getCountry(data.nationality.id); if (!nationality) throw new BadRequestException('Nationality not found'); } else { - user = await this.userDataService.updateUserDataInternal(user, data); + user.organization = await this.organizationService.updateOrganizationInternal(user.organization, data); } return this.updateKycStepAndLog(kycStep, user, data, reviewStatus); @@ -463,7 +467,7 @@ export class KycService { allBeneficialOwnersDomicile.push(beneficialOwner.country.name); } - await this.userDataService.updateUserDataInternal(user, { + await this.organizationService.updateOrganizationInternal(user.organization, { allBeneficialOwnersName: allBeneficialOwnersName.join('\n'), allBeneficialOwnersDomicile: allBeneficialOwnersDomicile.join('\n'), }); @@ -1005,11 +1009,11 @@ export class KycService { async completeCommercialRegister(userData: UserData): Promise { if ( - (!userData.verifiedName && userData.organizationName) || + (!userData.verifiedName && userData.organization.name) || (userData.kycLevel > KycLevel.LEVEL_30 && userData.highRisk == null && userData.hasValidNameCheckDate) ) return this.userDataService.updateUserDataInternal(userData, { - verifiedName: !userData.verifiedName && userData.organizationName ? userData.organizationName : undefined, + verifiedName: !userData.verifiedName && userData.organization.name ? userData.organization.name : undefined, pep: userData.kycLevel > KycLevel.LEVEL_30 && userData.highRisk == null && userData.hasValidNameCheckDate ? false @@ -1135,7 +1139,7 @@ export class KycService { if (!data.success) errors.push(KycError.INVALID_RESULT); const userCountry = - identStep.userData.organizationCountry ?? identStep.userData.verifiedCountry ?? identStep.userData.country; + identStep.userData.organization.country ?? identStep.userData.verifiedCountry ?? identStep.userData.country; if (identStep.userData.accountType === AccountType.PERSONAL) { if (userCountry && !userCountry.dfxEnable) errors.push(KycError.COUNTRY_NOT_ALLOWED); diff --git a/src/subdomains/generic/kyc/services/name-check.service.ts b/src/subdomains/generic/kyc/services/name-check.service.ts index cd319487b8..da0b93f122 100644 --- a/src/subdomains/generic/kyc/services/name-check.service.ts +++ b/src/subdomains/generic/kyc/services/name-check.service.ts @@ -72,7 +72,7 @@ export class NameCheckService implements OnModuleInit { const { data: businessSanctionData, file: businessSanctionFile } = await this.getRiskDataAndUploadPdf( bankData.userData, true, - bankData.userData.organizationName, + bankData.userData.organization.name, ); const riskStatus = [ diff --git a/src/subdomains/generic/user/models/account-merge/account-merge.service.ts b/src/subdomains/generic/user/models/account-merge/account-merge.service.ts index 98372a28a2..6fb8841a1f 100644 --- a/src/subdomains/generic/user/models/account-merge/account-merge.service.ts +++ b/src/subdomains/generic/user/models/account-merge/account-merge.service.ts @@ -53,7 +53,7 @@ export class AccountMergeService { const [receiver, mentioned] = sendToSlave ? [request.slave, request.master] : [request.master, request.slave]; if (!receiver.mail) return false; - const name = mentioned.organizationName ?? mentioned.firstname ?? receiver.organizationName ?? receiver.firstname; + const name = mentioned.organization.name ?? mentioned.firstname ?? receiver.organization.name ?? receiver.firstname; const url = this.buildConfirmationUrl(request.code); await this.notificationService.sendMail({ diff --git a/src/subdomains/generic/user/models/organization/organization.entity.ts b/src/subdomains/generic/user/models/organization/organization.entity.ts index 90b4745d07..b7e674cd7c 100644 --- a/src/subdomains/generic/user/models/organization/organization.entity.ts +++ b/src/subdomains/generic/user/models/organization/organization.entity.ts @@ -54,4 +54,19 @@ export class Organization extends IEntity { @OneToMany(() => UserData, (userData) => userData.organization) userDatas: UserData[]; + + // --- ENTITY METHODS --- // + + setAccountOpenerAuthorization(signatoryPower: SignatoryPower): Partial { + const update: Partial = { + accountOpenerAuthorization: + signatoryPower === SignatoryPower.SINGLE + ? AccountOpenerAuthorization.SINGLE_SIGNATURE + : AccountOpenerAuthorization.AUTHORIZATION, + }; + + Object.assign(this, update); + + return update; + } } diff --git a/src/subdomains/generic/user/models/organization/organization.service.ts b/src/subdomains/generic/user/models/organization/organization.service.ts index 97d4fa2d9c..7958cb8c49 100644 --- a/src/subdomains/generic/user/models/organization/organization.service.ts +++ b/src/subdomains/generic/user/models/organization/organization.service.ts @@ -1,60 +1,16 @@ import { BadRequestException, Injectable } from '@nestjs/common'; -import { CronExpression } from '@nestjs/schedule'; import { CountryService } from 'src/shared/models/country/country.service'; -import { DfxLogger } from 'src/shared/services/dfx-logger'; -import { Process } from 'src/shared/services/process.service'; -import { DfxCron } from 'src/shared/utils/cron'; -import { In, IsNull } from 'typeorm'; -import { AccountType } from '../user-data/account-type.enum'; -import { UserDataRepository } from '../user-data/user-data.repository'; import { OrganizationDto } from './dto/organization.dto'; import { Organization } from './organization.entity'; import { OrganizationRepository } from './organization.repository'; @Injectable() export class OrganizationService { - private readonly logger = new DfxLogger(OrganizationService); - constructor( private readonly organizationRepo: OrganizationRepository, private readonly countryService: CountryService, - private readonly userDataRepo: UserDataRepository, ) {} - @DfxCron(CronExpression.EVERY_MINUTE, { process: Process.ORGANIZATION_SYNC, timeout: 1800 }) - async syncOrganization() { - const entities = await this.userDataRepo.findBy({ - organization: { id: IsNull() }, - accountType: In([AccountType.ORGANIZATION, AccountType.SOLE_PROPRIETORSHIP]), - }); - - for (const entity of entities) { - try { - const organization = - (await this.getOrganizationByName(entity.organizationName, entity.organizationZip)) ?? - (await this.createOrganization({ - name: entity.organizationName, - street: entity.organizationStreet, - houseNumber: entity.organizationHouseNumber, - location: entity.organizationLocation, - zip: entity.organizationZip, - country: entity.organizationCountry, - allBeneficialOwnersName: entity.allBeneficialOwnersName, - allBeneficialOwnersDomicile: entity.allBeneficialOwnersDomicile, - accountOpenerAuthorization: entity.accountOpenerAuthorization, - complexOrgStructure: entity.complexOrgStructure, - accountOpener: entity.accountOpener, - legalEntity: entity.legalEntity, - signatoryPower: entity.signatoryPower, - })); - - await this.userDataRepo.update(entity.id, { organization }); - } catch (e) { - this.logger.error(`Error in organization sync ${entity.id}: `, e); - } - } - } - async createOrganization(dto: OrganizationDto): Promise { const organization = this.organizationRepo.create(dto); diff --git a/src/subdomains/generic/user/models/user-data/user-data-job.service.ts b/src/subdomains/generic/user/models/user-data/user-data-job.service.ts index f8830a3908..c1c7cc66ee 100644 --- a/src/subdomains/generic/user/models/user-data/user-data-job.service.ts +++ b/src/subdomains/generic/user/models/user-data/user-data-job.service.ts @@ -7,13 +7,17 @@ import { FileType } from 'src/subdomains/generic/kyc/dto/kyc-file.dto'; import { KycStepName } from 'src/subdomains/generic/kyc/enums/kyc-step-name.enum'; import { KycStepStatus } from 'src/subdomains/generic/kyc/enums/kyc.enum'; import { IsNull, Like, MoreThan, Not } from 'typeorm'; +import { OrganizationService } from '../organization/organization.service'; import { AccountType } from './account-type.enum'; import { KycLevel, KycType, SignatoryPower, UserDataStatus } from './user-data.entity'; import { UserDataRepository } from './user-data.repository'; @Injectable() export class UserDataJobService { - constructor(private readonly userDataRepo: UserDataRepository) {} + constructor( + private readonly userDataRepo: UserDataRepository, + private readonly organizationService: OrganizationService, + ) {} @DfxCron(CronExpression.EVERY_MINUTE, { process: Process.USER_DATA, timeout: 1800 }) async fillUserData() { @@ -41,7 +45,7 @@ export class UserDataJobService { where: { kycLevel: MoreThan(KycLevel.LEVEL_30), accountType: AccountType.ORGANIZATION, - accountOpenerAuthorization: IsNull(), + organization: { accountOpenerAuthorization: IsNull() }, kycSteps: { name: KycStepName.SIGNATORY_POWER, status: KycStepStatus.COMPLETED }, }, relations: { kycSteps: true }, @@ -50,9 +54,12 @@ export class UserDataJobService { for (const entity of entities) { const signatoryResult = entity.kycSteps .find((k) => k.name === KycStepName.SIGNATORY_POWER && k.status === KycStepStatus.COMPLETED) - .getResult<{signatoryPower: SignatoryPower}>(); + .getResult<{ signatoryPower: SignatoryPower }>(); - await this.userDataRepo.update(...entity.setAccountOpenerAuthorization(signatoryResult.signatoryPower)); + await this.organizationService.updateOrganizationInternal( + entity.organization, + entity.organization.setAccountOpenerAuthorization(signatoryResult.signatoryPower), + ); } } diff --git a/src/subdomains/generic/user/models/user-data/user-data-notification.service.ts b/src/subdomains/generic/user/models/user-data/user-data-notification.service.ts index 5b354b7780..5e9d3abb84 100644 --- a/src/subdomains/generic/user/models/user-data/user-data-notification.service.ts +++ b/src/subdomains/generic/user/models/user-data/user-data-notification.service.ts @@ -41,7 +41,7 @@ export class UserDataNotificationService { { key: MailKey.SPACE, params: { value: '3' } }, { key: `${MailTranslationKey.GENERAL}.welcome`, - params: { name: master.organizationName ?? master.firstname }, + params: { name: master.organization.name ?? master.firstname }, }, { key: MailKey.SPACE, params: { value: '2' } }, { @@ -80,7 +80,7 @@ export class UserDataNotificationService { { key: MailKey.SPACE, params: { value: '3' } }, { key: `${MailTranslationKey.GENERAL}.welcome`, - params: { name: master.organizationName ?? master.firstname }, + params: { name: master.organization.name ?? master.firstname }, }, { key: MailKey.SPACE, params: { value: '2' } }, { @@ -105,7 +105,7 @@ export class UserDataNotificationService { { key: MailKey.SPACE, params: { value: '3' } }, { key: `${MailTranslationKey.GENERAL}.welcome`, - params: { name: slave.organizationName ?? slave.firstname }, + params: { name: slave.organization.name ?? slave.firstname }, }, { key: MailKey.SPACE, params: { value: '2' } }, { diff --git a/src/subdomains/generic/user/models/user-data/user-data.entity.ts b/src/subdomains/generic/user/models/user-data/user-data.entity.ts index f1dfa61e42..65abee3a9d 100644 --- a/src/subdomains/generic/user/models/user-data/user-data.entity.ts +++ b/src/subdomains/generic/user/models/user-data/user-data.entity.ts @@ -18,8 +18,8 @@ import { User, UserStatus } from 'src/subdomains/generic/user/models/user/user.e import { BankTxReturn } from 'src/subdomains/supporting/bank-tx/bank-tx-return/bank-tx-return.entity'; import { Transaction } from 'src/subdomains/supporting/payment/entities/transaction.entity'; import { SupportIssue } from 'src/subdomains/supporting/support-issue/entities/support-issue.entity'; -import { Column, Entity, Generated, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm'; -import { AccountOpenerAuthorization, Organization } from '../organization/organization.entity'; +import { Column, Entity, Generated, Index, ManyToOne, OneToMany } from 'typeorm'; +import { Organization } from '../organization/organization.entity'; import { UserDataRelation } from '../user-data-relation/user-data-relation.entity'; import { UpdateUserDto } from '../user/dto/update-user.dto'; import { TradingLimit } from '../user/dto/user.dto'; @@ -165,46 +165,9 @@ export class UserData extends IEntity { @Column({ type: 'datetime2', nullable: true }) birthday?: Date; - // --- ORGANIZATION DATA --- // - // TODO remove after sync - @Column({ length: 256, nullable: true }) - organizationName?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - organizationStreet?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - organizationHouseNumber?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - organizationLocation?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - organizationZip?: string; - - // TODO remove - @ManyToOne(() => Country, { eager: true }) - organizationCountry: Country; - @Column({ type: 'float', nullable: true }) totalVolumeChfAuditPeriod?: number; - // TODO remove - @Column({ length: 256, nullable: true }) - allBeneficialOwnersName?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - allBeneficialOwnersDomicile?: string; - - // TODO remove - @Column({ length: 256, nullable: true }) - accountOpenerAuthorization?: AccountOpenerAuthorization; - @Column({ length: 256, nullable: true }) phone?: string; @@ -216,24 +179,12 @@ export class UserData extends IEntity { // --- KYC --- // - // TODO remove - @Column({ length: 256, nullable: true }) - legalEntity?: LegalEntity; - - // TODO remove - @Column({ length: 256, nullable: true }) - signatoryPower?: SignatoryPower; - @Column({ nullable: true }) highRisk?: boolean; @Column({ nullable: true }) olkypayAllowed?: boolean; - // TODO remove - @Column({ nullable: true }) - complexOrgStructure?: boolean; - @Column({ length: 256, default: KycStatus.NA }) kycStatus: KycStatus; @@ -368,11 +319,6 @@ export class UserData extends IEntity { @OneToMany(() => Transaction, (tx) => tx.userData) transactions: Transaction[]; - // TODO remove - @ManyToOne(() => UserData, { nullable: true }) - @JoinColumn() - accountOpener?: UserData; - @ManyToOne(() => Organization, { nullable: true, eager: true }) organization: Organization; @@ -405,19 +351,6 @@ export class UserData extends IEntity { ]; } - setAccountOpenerAuthorization(signatoryPower: SignatoryPower): UpdateResult { - const update: Partial = { - accountOpenerAuthorization: - signatoryPower === SignatoryPower.SINGLE - ? AccountOpenerAuthorization.SINGLE_SIGNATURE - : AccountOpenerAuthorization.AUTHORIZATION, - }; - - Object.assign(this, update); - - return [this.id, update]; - } - deactivateUserData(): UpdateResult { const update: Partial = { status: UserDataStatus.DEACTIVATED, @@ -577,7 +510,7 @@ export class UserData extends IEntity { } get completeName(): string { - return this.organizationName ?? this.naturalPersonName; + return this.organization.name ?? this.naturalPersonName; } get naturalPersonName(): string { @@ -599,11 +532,11 @@ export class UserData extends IEntity { get address() { return [AccountType.ORGANIZATION, AccountType.SOLE_PROPRIETORSHIP].includes(this.accountType) ? { - street: this.organizationStreet, - houseNumber: this.organizationHouseNumber, - city: this.organizationLocation, - zip: this.organizationZip, - country: this.organizationCountry, + street: this.organization.street, + houseNumber: this.organization.houseNumber, + city: this.organization.location, + zip: this.organization.zip, + country: this.organization.country, } : { street: this.street, @@ -716,12 +649,20 @@ export class UserData extends IEntity { return ['accountType', 'mail', 'phone', 'firstname', 'surname', 'street', 'location', 'zip', 'country'].concat( !this.accountType || this.accountType === AccountType.PERSONAL ? [] - : ['organizationName', 'organizationStreet', 'organizationLocation', 'organizationZip', 'organizationCountry'], + : [ + 'organization.name', + 'organization.street', + 'organization.location', + 'organization.zip', + 'organization.country', + ], ); } get isDataComplete(): boolean { - return this.requiredKycFields.every((f) => this[f]); + return this.requiredKycFields.every((f) => + f.includes('organization') ? this.organization[f.split('.')[1]] : this[f], + ); } get hasBankTxVerification(): boolean { diff --git a/src/subdomains/generic/user/models/user-data/user-data.service.ts b/src/subdomains/generic/user/models/user-data/user-data.service.ts index 7f3740cb2f..419841290a 100644 --- a/src/subdomains/generic/user/models/user-data/user-data.service.ts +++ b/src/subdomains/generic/user/models/user-data/user-data.service.ts @@ -346,26 +346,6 @@ export class UserDataService { if (kycChanged) await this.kycNotificationService.kycChanged(userData, userData.kycLevel); - if ( - [AccountType.ORGANIZATION, AccountType.SOLE_PROPRIETORSHIP].includes(dto.accountType ?? userData.accountType) && - userData.organization - ) - await this.organizationService.updateOrganizationInternal(userData.organization, { - name: dto.organizationName, - street: dto.organizationStreet, - location: dto.organizationLocation, - houseNumber: dto.organizationHouseNumber, - zip: dto.organizationZip, - country: dto.organizationCountry, - allBeneficialOwnersName: dto.allBeneficialOwnersName, - allBeneficialOwnersDomicile: dto.allBeneficialOwnersDomicile, - accountOpenerAuthorization: dto.accountOpenerAuthorization, - complexOrgStructure: dto.complexOrgStructure, - accountOpener: dto.accountOpener, - legalEntity: dto.legalEntity, - signatoryPower: dto.signatoryPower, - }); - return userData; } @@ -384,12 +364,6 @@ export class UserDataService { zip: transliterate(data.address.zip), country: data.address.country, phone: data.phone, - organizationName: data.organizationName, - organizationStreet: data.organizationAddress?.street, - organizationHouseNumber: data.organizationAddress?.houseNumber, - organizationLocation: data.organizationAddress?.city, - organizationZip: data.organizationAddress?.zip, - organizationCountry: data.organizationAddress?.country, }; const isPersonalAccount = @@ -398,7 +372,7 @@ export class UserDataService { // check countries const [country, organizationCountry] = await Promise.all([ this.countryService.getCountry(update.country?.id ?? userData.country?.id), - this.countryService.getCountry(update.organizationCountry?.id ?? userData.organizationCountry?.id), + this.countryService.getCountry(update.organization.country?.id ?? userData.organization.country?.id), ]); if (!country || (!isPersonalAccount && !organizationCountry)) throw new BadRequestException('Country not found'); if ( @@ -408,20 +382,20 @@ export class UserDataService { throw new BadRequestException(`Country not allowed for ${userData.kycType}`); if (isPersonalAccount) { - update.organizationName = null; - update.organizationStreet = null; - update.organizationHouseNumber = null; - update.organizationLocation = null; - update.organizationZip = null; - update.organizationCountry = null; + update.organization.name = null; + update.organization.street = null; + update.organization.houseNumber = null; + update.organization.location = null; + update.organization.zip = null; + update.organization.country = null; } else { const organizationData = { - name: update.organizationName, - street: update.organizationStreet, - location: update.organizationLocation, - houseNumber: update.organizationHouseNumber, - zip: update.organizationZip, - country: organizationCountry, + name: data.organizationName, + street: data.organizationAddress?.street, + location: data.organizationAddress?.city, + houseNumber: data.organizationAddress?.houseNumber, + zip: data.organizationAddress?.zip, + countryId: data.organizationAddress?.country?.id, }; update.organization = !userData.organization @@ -694,8 +668,8 @@ export class UserDataService { } if (dto.organizationCountryId) { - userData.organizationCountry = await this.countryService.getCountry(dto.organizationCountryId); - if (!userData.organizationCountry) throw new BadRequestException('Country not found'); + userData.organization.country = await this.countryService.getCountry(dto.organizationCountryId); + if (!userData.organization.country) throw new BadRequestException('Country not found'); } if (dto.verifiedCountry) { @@ -714,8 +688,8 @@ export class UserDataService { } if (dto.accountOpener) { - userData.accountOpener = await this.userDataRepo.findOneBy({ id: dto.accountOpener.id }); - if (!userData.accountOpener) throw new BadRequestException('AccountOpener not found'); + userData.organization.accountOpener = await this.userDataRepo.findOneBy({ id: dto.accountOpener.id }); + if (!userData.organization.accountOpener) throw new BadRequestException('AccountOpener not found'); } if (dto.verifiedName) { diff --git a/src/subdomains/generic/user/user.module.ts b/src/subdomains/generic/user/user.module.ts index c394bb08f1..3e40aca872 100644 --- a/src/subdomains/generic/user/user.module.ts +++ b/src/subdomains/generic/user/user.module.ts @@ -119,6 +119,7 @@ import { WebhookService } from './services/webhook/webhook.service'; CustodyProviderService, UserDataRelationService, AuthService, + OrganizationService, ], }) export class UserModule {}