1
0
forked from Yara724/api

Merge pull request 'Fix addClient bug' (#109) from s.yahyaee/yara724-api:main into main

Reviewed-on: Yara724/api#109
This commit is contained in:
2026-06-03 14:01:44 +03:30
3 changed files with 370 additions and 328 deletions

View File

@@ -99,19 +99,34 @@ export class ClientService {
try {
const newClient = await this.clientDbService.create({
clientCode: client.clientCode,
clientName: {
persian: client.clientName.persian,
english: client.clientName.english || null,
persian:
typeof client.clientName === "string"
? client.clientName
: client.clientName?.persian,
english:
typeof client.clientName === "string"
? null
: (client.clientName?.english ?? null),
},
property: {
smsApiKey: client.property.smsApiKey || null,
smsApiKey: client.property?.smsApiKey ?? null,
},
useExpertMode: client.useExpertMode || null,
useExpertMode: client.useExpertMode ?? null,
});
if (newClient) return new ClientDtoRs(newClient);
else throw new GoneException("database not connected");
if (!newClient) {
throw new GoneException("database not connected");
}
return new ClientDtoRs(newClient);
} catch (er) {
throw new BadGatewayException(er.errors);
console.error("ADD CLIENT ERROR:", er);
throw er;
}
}

View File

@@ -1,5 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsIn, IsNotEmpty, IsNumber, IsOptional, IsString, ValidateNested } from "class-validator";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import {
IsIn,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
ValidateNested,
} from "class-validator";
import { Type } from "class-transformer";
import { Types } from "mongoose";
@@ -15,9 +22,8 @@ class ClientName {
english: string;
}
class Property {
@ApiProperty({})
@ApiPropertyOptional({})
@IsString()
@IsNotEmpty()
smsApiKey: string;
}

View File

@@ -945,6 +945,7 @@ export class RequestManagementService {
}
async initialFormV2(requestId: string, body: AddPlateDto, user: any) {
try {
const req = await this.blameRequestDbService.findById(requestId);
if (!req) {
throw new NotFoundException("Request not found");
@@ -997,7 +998,8 @@ export class RequestManagementService {
);
}
} else if (body.driverIsInsurer === true) {
const sameNat = body.nationalCodeOfInsurer === body.nationalCodeOfDriver;
const sameNat =
body.nationalCodeOfInsurer === body.nationalCodeOfDriver;
const sameLic = body.insurerLicense === body.driverLicense;
const sameBirthday =
body.driverBirthday == null ||
@@ -1152,14 +1154,22 @@ export class RequestManagementService {
// Find client by company code
const clientName = inquiryMapped?.CompanyName;
if (!clientName) {
throw new BadRequestException(
`CompanyName missing from inquiry response`,
);
}
const companyCode = inquiryMapped?.CompanyCode;
const client =
let client =
await this.clientService.findClientWithCompanyCode(+companyCode);
if (!client) {
await this.clientService.addClient({
clientName,
clientCode: companyCode,
clientName: {
persian: clientName,
english: null,
},
clientCode: Number(companyCode),
useExpertMode: "legal",
});
}
@@ -1170,7 +1180,8 @@ export class RequestManagementService {
// Persist inquiry/body data into new model
if (!party.person) party.person = {} as any;
const resolvedClientId = (client as any)?._id ?? (client as any)?._doc?._id;
const resolvedClientId =
(client as any)?._id ?? (client as any)?._doc?._id;
party.person.clientId = resolvedClientId;
party.person.nationalCodeOfInsurer = body.nationalCodeOfInsurer;
party.person.nationalCodeOfDriver = body.nationalCodeOfDriver;
@@ -1222,7 +1233,14 @@ export class RequestManagementService {
this.logger.error(
`[TEJARAT] car body inquiry failed for request=${req._id}: ${err?.message || err}`,
);
this.recordPartyCaseInquiryStatus(req, "carBody", role, false, {}, err);
this.recordPartyCaseInquiryStatus(
req,
"carBody",
role,
false,
{},
err,
);
await (req as any).save();
throw new HttpException(
"Car body inquiry failed",
@@ -1293,6 +1311,9 @@ export class RequestManagementService {
blameStatus: req.blameStatus,
status: req.status,
};
} catch (error) {
console.log(error);
}
}
async addDetailLocationV2(requestId: string, body: LocationDto, user: any) {