Enforce claim beneficiary access and retire unused legacy APIs

This commit is contained in:
SepehrYahyaee
2026-10-05 14:39:51 +03:30
parent 0735333467
commit a3f9aab8fb
104 changed files with 6864 additions and 13223 deletions
@@ -1,35 +0,0 @@
import { InjectModel } from "@nestjs/mongoose";
import { Model, Types, UpdateQuery } from "mongoose";
import { SandHubInterface, SandHubModel } from "../schema/sand-hub.schema";
export class SandHubDbService {
constructor(
@InjectModel(SandHubModel.name)
private readonly sandHubModel: Model<SandHubModel>,
) {}
async create(sandHubData: any): Promise<SandHubModel> {
return await this.sandHubModel.create(sandHubData);
}
async findOneByRequestId(requestId: string, userId): Promise<SandHubModel> {
return await this.sandHubModel.findOne({ requestId, userId });
}
async findOneBySandHubId(requestId: string): Promise<SandHubModel> {
return await this.sandHubModel.findOne({
_id: new Types.ObjectId(requestId),
});
}
async findOneByRequestIdAndUpdate(
requestId: string,
userId: string,
update: UpdateQuery<SandHubInterface>,
): Promise<any> {
return await this.sandHubModel.findOneAndUpdate(
{ requestId, userId },
update,
);
}
}
+2 -3
View File
@@ -8,7 +8,6 @@ import { SystemSettingsModule } from "src/system-settings/system-settings.module
import { PlateNormalizerModule } from "src/utils/plate-normalizer/plate-normalizer.module";
import { OfflineInquiryModule } from "src/offline-inquiry/offline-inquiry.module";
import { LookupsModule } from "src/lookups/lookups.module";
import { SandHubDbService } from "src/sand-hub/entity/db-service/sand-hub.db.service";
import { SandHubModel, SandHubSchema } from "./entity/schema/sand-hub.schema";
import { SandHubService } from "./sand-hub.service";
@@ -28,8 +27,8 @@ import { SandHubService } from "./sand-hub.service";
{ name: SandHubModel.name, schema: SandHubSchema },
]),
],
providers: [SandHubService, SandHubDbService],
exports: [SandHubService, SandHubDbService],
providers: [SandHubService],
exports: [SandHubService],
controllers: [],
})
export class SandHubModule {}
-2
View File
@@ -10,7 +10,6 @@ import { isMappedPolicyCurrent } from "src/request-management/inquiry-participan
describe("SandHubService inquiry mocks", () => {
const httpService = { post: jest.fn() };
const sandHubDbService = { findOneBySandHubId: jest.fn() };
const externalInquirySettings = {
isInquiryLive: jest.fn(),
getMockCompanyContext: jest.fn(),
@@ -44,7 +43,6 @@ describe("SandHubService inquiry mocks", () => {
delete process.env.FANAVARAN_CLIENT;
service = new SandHubService(
httpService as any,
sandHubDbService as any,
externalInquirySettings as unknown as ExternalInquirySettingsService,
plateNormalizer as any,
offlineInquiryService as any,
+14 -38
View File
@@ -10,20 +10,13 @@ import {
ServiceUnavailableException,
UnauthorizedException,
} from "@nestjs/common";
import { SandHubDbService } from "src/sand-hub/entity/db-service/sand-hub.db.service";
import { SandHubModel } from "src/sand-hub/entity/schema/sand-hub.schema";
import { ExternalInquirySettingsService } from "src/client/external-inquiry-settings.service";
import { PlateNormalizerService } from "src/utils/plate-normalizer/plate-normalizer.service";
import type { ExternalInquiryType } from "src/common/types/external-inquiry.types";
import type { MockInquiryCompanyContext } from "src/common/types/external-inquiry.types";
import { OfflineInquiryService } from "src/offline-inquiry/offline-inquiry.service";
import { LookupsService } from "src/lookups/lookups.service";
import { resolveFanavaranClientKey } from "src/core/config/fanavaran-client.config";
import { SandHubDetailDto, SandHubInquiryOptions } from "./dto/sand-hub.dto";
import { jalaliToGregorianDate } from "src/helpers/date-jalali";
import { firstValueFrom } from "rxjs";
import { mapEsgCarBodyPolicyToInquiry } from "./esg-car-body-inquiry.mapper";
import type { Plates } from "src/Types&Enums/plate.interface";
import { ExternalInquirySettingsService } from "src/client/external-inquiry-settings.service";
import type {
ExternalInquiryType,
MockInquiryCompanyContext,
} from "src/common/types/external-inquiry.types";
import {
getInquiryErrorMessage,
inquiryErrorStatus,
@@ -31,6 +24,14 @@ import {
isInquiryTimeout,
type InquiryErrorContext,
} from "src/common/utils/inquiry-error";
import { resolveFanavaranClientKey } from "src/core/config/fanavaran-client.config";
import { jalaliToGregorianDate } from "src/helpers/date-jalali";
import { LookupsService } from "src/lookups/lookups.service";
import { OfflineInquiryService } from "src/offline-inquiry/offline-inquiry.service";
import { PlateNormalizerService } from "src/utils/plate-normalizer/plate-normalizer.service";
import { SandHubDetailDto, SandHubInquiryOptions } from "./dto/sand-hub.dto";
import { mapEsgCarBodyPolicyToInquiry } from "./esg-car-body-inquiry.mapper";
type CarBodyInquiryDetail = Omit<SandHubDetailDto, "plate"> & {
plate: Plates | string;
@@ -52,7 +53,7 @@ export class SandHubService {
constructor(
private readonly httpService: HttpService,
private readonly sandHubDbService: SandHubDbService,
private readonly externalInquirySettings: ExternalInquirySettingsService,
private readonly plateNormalizer: PlateNormalizerService,
private readonly offlineInquiryService: OfflineInquiryService,
@@ -977,10 +978,6 @@ export class SandHubService {
return { raw, mapped };
}
async getSandHubDataFromId(sandHubId) {
return await this.sandHubDbService.findOneBySandHubId(sandHubId);
}
/**
* CAR_BODY is the only ESG product that uses the processed Fanavaran lookup.
* THIRD_PARTY remains on its established provider-specific inquiry path.
@@ -1781,25 +1778,4 @@ export class SandHubService {
);
}
}
async sandHubDocumentCreator(
userId: string,
requestId: string,
doc: Partial<SandHubModel>,
) {
const existingDoc = await this.sandHubDbService.findOneByRequestId(
requestId,
userId,
);
if (!existingDoc) {
return await this.sandHubDbService.create({ ...doc, userId, requestId });
} else {
const updatePayload = { ...existingDoc, ...doc };
return await this.sandHubDbService.findOneByRequestIdAndUpdate(
requestId,
userId,
updatePayload,
);
}
}
}