Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,31 @@ export class RecommendationService {
return this.updateRecommendationInternal(entity, { isConfirmed: true, confirmationDate: new Date() });
}

async blockUserDataRoot(userDataId: number): Promise<void> {
const userData = await this.userDataService.getUserData(userDataId);

const recommendations = await this.getAllRecommendationForUserData(userData.id);
let sourceRecommendation = await this.recommendationRepo.findOne({
where: { recommended: { id: userData.id } },
relations: { recommender: true },
});

await this.userDataService.blockUserData(userData, 'manual root block');

Comment on lines +284 to +286
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

root is a bit difficult 🤣 maybe just use recommendation, associates, linked, circle 🤔

for (const recommendation of recommendations) {
await this.userDataService.blockUserData(recommendation.recommender, 'manual root block - recommended');
}
Comment on lines +287 to +289
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block the same user data multiple times?


while (sourceRecommendation) {
await this.userDataService.blockUserData(sourceRecommendation.recommender, 'manual root block - recommender');

sourceRecommendation = await this.recommendationRepo.findOne({
where: { recommended: { id: sourceRecommendation.recommender.id } },
relations: { recommender: true },
});
}
}

// --- NOTIFICATIONS --- //
private async sendInvitationMail(entity: Recommendation): Promise<void> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { BankDataService } from 'src/subdomains/generic/user/models/bank-data/ba
import { CreateBankDataDto } from 'src/subdomains/generic/user/models/bank-data/dto/create-bank-data.dto';
import { UploadFileDto } from 'src/subdomains/generic/user/models/user-data/dto/upload-file.dto';
import { FeeService } from 'src/subdomains/supporting/payment/services/fee.service';
import { RecommendationService } from '../recommendation/recommendation.service';
import { DownloadUserDataDto } from '../user/dto/download-user-data.dto';
import { CreateUserDataDto } from './dto/create-user-data.dto';
import { UpdateUserDataDto } from './dto/update-user-data.dto';
Expand All @@ -44,6 +45,7 @@ export class UserDataController {
private readonly feeService: FeeService,
private readonly documentService: KycDocumentService,
private readonly kycLogService: KycLogService,
private readonly recommendationService: RecommendationService,
) {}

@Get()
Expand Down Expand Up @@ -115,6 +117,14 @@ export class UserDataController {
return this.userDataService.createUserData({ ...dto, status: UserDataStatus.KYC_ONLY });
}

@Delete(':id/root')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
async blockUserDataRoot(@Param('id') id: string): Promise<void> {
return this.recommendationService.blockUserDataRoot(+id);
}

// --- DISCOUNT CODES --- //

@Put(':id/fee')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ export class UserData extends IEntity {
return [this.id, update];
}

blockUserData(): UpdateResult<UserData> {
const update: Partial<UserData> = { status: UserDataStatus.BLOCKED };

Object.assign(this, update);

return [this.id, update];
}

deactivateUserData(): UpdateResult<UserData> {
const update: Partial<UserData> = {
status: UserDataStatus.DEACTIVATED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ export class UserDataService {
await this.userDataNotificationService.deactivateAccountMail(userData);
}

async blockUserData(userData: UserData, reason: string): Promise<void> {
await this.userDataRepo.update(...userData.blockUserData());
await this.kycLogService.createLogInternal(userData, KycLogType.RISK_STATUS, `UserData blocked: ${reason}`);
}

async refreshLastNameCheckDate(userData: UserData): Promise<void> {
await this.userDataRepo.update(...userData.refreshLastCheckedTimestamp());
}
Expand Down
Loading