Added v3 of field-expert

This commit is contained in:
SepehrYahyaee
2026-06-22 13:05:11 +03:30
parent 89e715b0c9
commit 8f29bb564c
15 changed files with 2988 additions and 622 deletions

View File

@@ -46,7 +46,7 @@ import { PartyRole } from "./entities/schema/partyRole.enum";
* Field experts create files via LINK (send link to user) or IN_PERSON (expert fills on-site).
* Only the initiating field expert can see/review these files.
*/
@ApiTags("expert-initiated-blame (v2)")
// @ApiTags("expert-initiated-blame (v2)")
@Controller("v2/expert-initiated-blame")
@ApiBearerAuth()
@UseGuards(LocalActorAuthGuard, RolesGuard)
@@ -59,23 +59,23 @@ export class ExpertInitiatedV2Controller {
) {}
@Get("my-files")
@ApiOperation({
summary: "[V2] List my expert-initiated blame files",
description:
"Returns all BlameRequest (workflow) files created by the current field expert.",
})
@ApiResponse({ status: 200, description: "List of expert-initiated files" })
// @ApiOperation({
// summary: "[V2] List my expert-initiated blame files",
// description:
// "Returns all BlameRequest (workflow) files created by the current field expert.",
// })
// @ApiResponse({ status: 200, description: "List of expert-initiated files" })
async getMyFilesV2(@CurrentUser() expert: any) {
return this.requestManagementService.getMyExpertInitiatedFilesV2(expert);
}
@Get("blame/:requestId")
@ApiOperation({
summary: "[V2] Get one expert-initiated blame request",
description: "Returns a single blame request. Only the initiating field expert can access.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiResponse({ status: 200, description: "Blame request" })
// @ApiOperation({
// summary: "[V2] Get one expert-initiated blame request",
// description: "Returns a single blame request. Only the initiating field expert can access.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiResponse({ status: 200, description: "Blame request" })
async getBlameRequestV2(
@Param("requestId") requestId: string,
@CurrentUser() expert: any,
@@ -84,68 +84,45 @@ export class ExpertInitiatedV2Controller {
}
@Post("create")
@ApiOperation({
summary: "[V2] Create expert-initiated blame file",
description:
"Creates a BlameRequest with workflow. LINK: parties identified by phone, expert sends link. IN_PERSON: expert fills form later.",
})
@ApiBody({
type: CreateExpertInitiatedFileDto,
examples: {
thirdPartyInPerson: {
summary: "Third-party, IN_PERSON (both parties)",
description:
"Expert fills form on-site for both parties.",
value: {
type: "THIRD_PARTY",
creationMethod: "IN_PERSON",
firstPartyPhoneNumber: "09123456789",
secondPartyPhoneNumber: "09187654321",
},
},
thirdPartyLink: {
summary: "Third-party, LINK",
description:
"Expert sends link to first and second party by phone.",
value: {
type: "THIRD_PARTY",
creationMethod: "LINK",
firstPartyPhoneNumber: "09123456789",
},
},
carBodyInPerson: {
summary: "Car-body, IN_PERSON",
description: "Expert fills form on-site for single party (car body).",
value: {
type: "CAR_BODY",
creationMethod: "IN_PERSON",
firstPartyPhoneNumber: "09123456789",
},
},
carBodyLink: {
summary: "Car-body, LINK",
description:
"Expert sends link to party by phone. Only first party phone needed.",
value: {
type: "CAR_BODY",
creationMethod: "LINK",
firstPartyPhoneNumber: "09123456789",
},
},
},
})
@ApiResponse({
status: 201,
description: "File created",
schema: {
type: "object",
properties: {
requestId: { type: "string" },
publicId: { type: "string" },
linkUrl: { type: "string", description: "Present for LINK method" },
},
},
})
// @ApiOperation({
// summary: "[V2] Create expert-initiated blame file",
// description:
// "Creates a BlameRequest with workflow. LINK: parties identified by phone, expert sends link. IN_PERSON: expert fills form later.",
// })
// @ApiBody({
// type: CreateExpertInitiatedFileDto,
// examples: {
// thirdPartyInPerson: {
// summary: "Third-party, IN_PERSON (both parties)",
// description:
// "Expert fills form on-site for both parties.",
// value: {
// type: "THIRD_PARTY",
// creationMethod: "LINK",
// firstPartyPhoneNumber: "09123456789",
// },
// },
// carBodyInPerson: {
// summary: "Car-body, IN_PERSON",
// description: "Expert fills form on-site for single party (car body).",
// value: {
// type: "CAR_BODY",
// creationMethod: "IN_PERSON",
// firstPartyPhoneNumber: "09123456789",
// },
// },
// carBodyLink: {
// summary: "Car-body, LINK",
// description:
// "Expert sends link to party by phone. Only first party phone needed.",
// value: {
// type: "CAR_BODY",
// creationMethod: "LINK",
// firstPartyPhoneNumber: "09123456789",
// },
// },
// },
// })
async createV2(
@CurrentUser() expert: any,
@Body() dto: CreateExpertInitiatedFileDto,
@@ -157,13 +134,13 @@ export class ExpertInitiatedV2Controller {
}
@Post("send-link/:requestId")
@ApiOperation({
summary: "[V2] Send blame link to first party (LINK)",
description:
"For expert-initiated LINK files only. Provide the first party phone number; the service stores it, registers the user if needed, and sends the invite link via SMS.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({ type: SendExpertInitiatedLinkV2Dto })
// @ApiOperation({
// summary: "[V2] Send blame link to first party (LINK)",
// description:
// "For expert-initiated LINK files only. Provide the first party phone number; the service stores it, registers the user if needed, and sends the invite link via SMS.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({ type: SendExpertInitiatedLinkV2Dto })
async sendLinkV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -173,14 +150,14 @@ export class ExpertInitiatedV2Controller {
}
@Post("send-party-otps/:requestId")
@ApiOperation({
summary: "[V2] Send OTP to party/parties (IN_PERSON)",
description:
"Sends OTP via SMS to first party (and second party for THIRD_PARTY) using the same flow as /user/send-otp. Parties receive the code; collect it from them and call verify-party-otps. Call this before filling the blame form.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({ type: SendPartyOtpsDto })
@ApiResponse({ status: 200, description: "OTP(s) sent; collect codes and call verify-party-otps" })
// @ApiOperation({
// summary: "[V2] Send OTP to party/parties (IN_PERSON)",
// description:
// "Sends OTP via SMS to first party (and second party for THIRD_PARTY) using the same flow as /user/send-otp. Parties receive the code; collect it from them and call verify-party-otps. Call this before filling the blame form.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({ type: SendPartyOtpsDto })
// @ApiResponse({ status: 200, description: "OTP(s) sent; collect codes and call verify-party-otps" })
async sendPartyOtpsV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -190,14 +167,14 @@ export class ExpertInitiatedV2Controller {
}
@Post("verify-party-otps/:requestId")
@ApiOperation({
summary: "[V2] Verify party OTPs (IN_PERSON)",
description:
"After send-party-otps, parties receive SMS. They tell you the code; submit it here. Required before complete-blame-data.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({ type: VerifyPartyOtpsDto })
@ApiResponse({ status: 200, description: "OTPs verified; expert can proceed to complete-blame-data" })
// @ApiOperation({
// summary: "[V2] Verify party OTPs (IN_PERSON)",
// description:
// "After send-party-otps, parties receive SMS. They tell you the code; submit it here. Required before complete-blame-data.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({ type: VerifyPartyOtpsDto })
// @ApiResponse({ status: 200, description: "OTPs verified; expert can proceed to complete-blame-data" })
async verifyPartyOtpsV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -207,99 +184,99 @@ export class ExpertInitiatedV2Controller {
}
@Post("complete-blame-data/:requestId")
@ApiOperation({
summary: "[V2] Submit all blame data (IN_PERSON)",
description:
"For IN_PERSON files only. Send THIRD_PARTY or CAR_BODY form EXCEPT location. Use one shared expertDescription (not per-party descriptions). After this, call add-locations once to submit scene lat/lon and move workflow to WAITING_FOR_SIGNATURES.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({
description: "Choose THIRD_PARTY or CAR_BODY example according to the file type. IN_PERSON v2 uses one shared expertDescription for the scene.",
examples: {
THIRD_PARTY: {
summary: "THIRD_PARTY",
description: "Use when the blame file type is THIRD_PARTY",
value: {
firstPartyPhoneNumber: "09123456789",
firstPartyInitialForm: {
expertOpinion: false,
imDamaged: false,
imGuilty: true,
},
firstPartyPlate: {
nationalCodeOfInsurer: "",
nationalCodeOfDriver: "",
insurerLicense: "",
driverLicense: "",
plate: { leftDigits: 12, centerAlphabet: "الف", centerDigits: 345, ir: 22 },
driverIsInsurer: true,
isNewCar: false,
userNoCertificate: false,
insurerBirthday: 13770624,
driverBirthday: "1370-01-01",
},
expertDescription: { desc: "توضیح حادثه کارشناس (مشترک برای صحنه)" },
secondParty: {
phoneNumber: "09187654321",
initialForm: {
expertOpinion: false,
imDamaged: true,
imGuilty: false,
},
plate: {
nationalCodeOfInsurer: "",
nationalCodeOfDriver: "",
insurerLicense: "",
driverLicense: "",
plate: { leftDigits: 91, centerAlphabet: "ن", centerDigits: 174, ir: 79 },
driverIsInsurer: true,
isNewCar: false,
userNoCertificate: false,
insurerBirthday: 13700720,
driverBirthday: "1370-01-01",
},
},
guiltyPartyPhoneNumber: "09123456789",
},
},
CAR_BODY: {
summary: "CAR_BODY",
description: "Use when the blame file type is CAR_BODY",
value: {
firstPartyPhoneNumber: "09123456789",
firstPartyInitialForm: {
expertOpinion: false,
imDamaged: false,
imGuilty: true,
},
carBodyForm: { car: true, object: false },
firstPartyPlate: {
plateId: "",
nationalCodeOfInsurer: "",
nationalCodeOfDriver: "",
insurerLicense: "",
driverLicense: "",
plate: { leftDigits: 12, centerAlphabet: "الف", centerDigits: 345, ir: 22 },
driverIsInsurer: true,
isNewCar: false,
userNoCertificate: false,
insurerBirthday: 1370,
driverBirthday: "1370-01-01",
},
expertDescription: {
desc: "توضیح حادثه",
accidentDate: "2025-01-15",
accidentTime: "14:30",
weatherCondition: "صاف",
roadCondition: "خشک",
lightCondition: "روز",
},
},
},
},
schema: { type: "object" },
})
@ApiResponse({ status: 200, description: "Blame form completed; next: add-locations" })
// @ApiOperation({
// summary: "[V2] Submit all blame data (IN_PERSON)",
// description:
// "For IN_PERSON files only. Send THIRD_PARTY or CAR_BODY form EXCEPT location. Use one shared expertDescription (not per-party descriptions). After this, call add-locations once to submit scene lat/lon and move workflow to WAITING_FOR_SIGNATURES.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({
// description: "Choose THIRD_PARTY or CAR_BODY example according to the file type. IN_PERSON v2 uses one shared expertDescription for the scene.",
// examples: {
// THIRD_PARTY: {
// summary: "THIRD_PARTY",
// description: "Use when the blame file type is THIRD_PARTY",
// value: {
// firstPartyPhoneNumber: "09123456789",
// firstPartyInitialForm: {
// expertOpinion: false,
// imDamaged: false,
// imGuilty: true,
// },
// firstPartyPlate: {
// nationalCodeOfInsurer: "",
// nationalCodeOfDriver: "",
// insurerLicense: "",
// driverLicense: "",
// plate: { leftDigits: 12, centerAlphabet: "الف", centerDigits: 345, ir: 22 },
// driverIsInsurer: true,
// isNewCar: false,
// userNoCertificate: false,
// insurerBirthday: 13770624,
// driverBirthday: "1370-01-01",
// },
// expertDescription: { desc: "توضیح حادثه کارشناس (مشترک برای صحنه)" },
// secondParty: {
// phoneNumber: "09187654321",
// initialForm: {
// expertOpinion: false,
// imDamaged: true,
// imGuilty: false,
// },
// plate: {
// nationalCodeOfInsurer: "",
// nationalCodeOfDriver: "",
// insurerLicense: "",
// driverLicense: "",
// plate: { leftDigits: 91, centerAlphabet: "ن", centerDigits: 174, ir: 79 },
// driverIsInsurer: true,
// isNewCar: false,
// userNoCertificate: false,
// insurerBirthday: 13700720,
// driverBirthday: "1370-01-01",
// },
// },
// guiltyPartyPhoneNumber: "09123456789",
// },
// },
// CAR_BODY: {
// summary: "CAR_BODY",
// description: "Use when the blame file type is CAR_BODY",
// value: {
// firstPartyPhoneNumber: "09123456789",
// firstPartyInitialForm: {
// expertOpinion: false,
// imDamaged: false,
// imGuilty: true,
// },
// carBodyForm: { car: true, object: false },
// firstPartyPlate: {
// plateId: "",
// nationalCodeOfInsurer: "",
// nationalCodeOfDriver: "",
// insurerLicense: "",
// driverLicense: "",
// plate: { leftDigits: 12, centerAlphabet: "الف", centerDigits: 345, ir: 22 },
// driverIsInsurer: true,
// isNewCar: false,
// userNoCertificate: false,
// insurerBirthday: 1370,
// driverBirthday: "1370-01-01",
// },
// expertDescription: {
// desc: "توضیح حادثه",
// accidentDate: "2025-01-15",
// accidentTime: "14:30",
// weatherCondition: "صاف",
// roadCondition: "خشک",
// lightCondition: "روز",
// },
// },
// },
// },
// schema: { type: "object" },
// })
// @ApiResponse({ status: 200, description: "Blame form completed; next: add-locations" })
async completeBlameDataV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -313,24 +290,24 @@ export class ExpertInitiatedV2Controller {
}
@Post("add-locations/:requestId")
@ApiOperation({
summary: "[V2] Submit one scene location for expert-initiated IN_PERSON blame",
description:
"Submit one scene location after complete-blame-data. This transitions workflow to WAITING_FOR_SIGNATURES.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({
type: ExpertCompleteLocationV2Dto,
examples: {
scene: {
summary: "One scene location (all IN_PERSON types)",
value: {
location: { lat: 35.6892, lon: 51.389 },
},
},
},
})
@ApiResponse({ status: 200, description: "Locations saved; next: upload party signature(s)" })
// @ApiOperation({
// summary: "[V2] Submit one scene location for expert-initiated IN_PERSON blame",
// description:
// "Submit one scene location after complete-blame-data. This transitions workflow to WAITING_FOR_SIGNATURES.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({
// type: ExpertCompleteLocationV2Dto,
// examples: {
// scene: {
// summary: "One scene location (all IN_PERSON types)",
// value: {
// location: { lat: 35.6892, lon: 51.389 },
// },
// },
// },
// })
// @ApiResponse({ status: 200, description: "Locations saved; next: upload party signature(s)" })
async addLocationsV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -344,17 +321,17 @@ export class ExpertInitiatedV2Controller {
}
@Post("upload-video/:requestId")
@ApiOperation({
summary: "[V2] Expert uploads video for expert-initiated BlameRequest",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiConsumes("multipart/form-data")
@ApiBody({
schema: {
type: "object",
properties: { file: { type: "string", format: "binary" } },
},
})
// @ApiOperation({
// summary: "[V2] Expert uploads video for expert-initiated BlameRequest",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiConsumes("multipart/form-data")
// @ApiBody({
// schema: {
// type: "object",
// properties: { file: { type: "string", format: "binary" } },
// },
// })
@UseInterceptors(
FileInterceptor("file", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
@@ -368,7 +345,7 @@ export class ExpertInitiatedV2Controller {
}),
}),
)
@ApiResponse({ status: 200, description: "Video uploaded" })
// @ApiResponse({ status: 200, description: "Video uploaded" })
async uploadVideoV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -383,17 +360,17 @@ export class ExpertInitiatedV2Controller {
}
@Post("upload-voice/:requestId")
@ApiOperation({
summary: "[V2] Expert uploads voice for expert-initiated BlameRequest",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiConsumes("multipart/form-data")
@ApiBody({
schema: {
type: "object",
properties: { voice: { type: "string", format: "binary" } },
},
})
// @ApiOperation({
// summary: "[V2] Expert uploads voice for expert-initiated BlameRequest",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiConsumes("multipart/form-data")
// @ApiBody({
// schema: {
// type: "object",
// properties: { voice: { type: "string", format: "binary" } },
// },
// })
@UseInterceptors(
FileInterceptor("voice", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
@@ -408,7 +385,7 @@ export class ExpertInitiatedV2Controller {
}),
}),
)
@ApiResponse({ status: 200, description: "Voice uploaded" })
// @ApiResponse({ status: 200, description: "Voice uploaded" })
async uploadVoiceV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -423,12 +400,12 @@ export class ExpertInitiatedV2Controller {
}
@Post("add-accident-fields/:requestId")
@ApiOperation({
summary: "[V2] Expert adds accident fields to expert-initiated BlameRequest",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiBody({ type: ExpertAccidentFieldsDto })
@ApiResponse({ status: 200, description: "Accident fields added" })
// @ApiOperation({
// summary: "[V2] Expert adds accident fields to expert-initiated BlameRequest",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiBody({ type: ExpertAccidentFieldsDto })
// @ApiResponse({ status: 200, description: "Accident fields added" })
async addAccidentFieldsV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -442,24 +419,24 @@ export class ExpertInitiatedV2Controller {
}
@Post("upload-party-signature/:requestId")
@ApiOperation({
summary: "[V2] Expert uploads party signature (IN_PERSON)",
description:
"For IN_PERSON only. Upload a party's signature collected on-site. CAR_BODY: use partyRole FIRST once. THIRD_PARTY: upload FIRST then SECOND. When all required parties have signed, blame case completes.",
})
@ApiParam({ name: "requestId", description: "Blame request ID" })
@ApiConsumes("multipart/form-data")
@ApiBody({
schema: {
type: "object",
required: ["partyRole", "sign"],
properties: {
partyRole: { type: "string", enum: ["FIRST", "SECOND"] },
isAccept: { type: "boolean", default: true },
sign: { type: "string", format: "binary" },
},
},
})
// @ApiOperation({
// summary: "[V2] Expert uploads party signature (IN_PERSON)",
// description:
// "For IN_PERSON only. Upload a party's signature collected on-site. CAR_BODY: use partyRole FIRST once. THIRD_PARTY: upload FIRST then SECOND. When all required parties have signed, blame case completes.",
// })
// @ApiParam({ name: "requestId", description: "Blame request ID" })
// @ApiConsumes("multipart/form-data")
// @ApiBody({
// schema: {
// type: "object",
// required: ["partyRole", "sign"],
// properties: {
// partyRole: { type: "string", enum: ["FIRST", "SECOND"] },
// isAccept: { type: "boolean", default: true },
// sign: { type: "string", format: "binary" },
// },
// },
// })
@UseInterceptors(
FileInterceptor("sign", {
limits: { fileSize: DEFAULT_MEDIA_MAX_BYTES },
@@ -473,7 +450,7 @@ export class ExpertInitiatedV2Controller {
}),
}),
)
@ApiResponse({ status: 200, description: "Signature recorded" })
// @ApiResponse({ status: 200, description: "Signature recorded" })
async uploadPartySignatureV2(
@CurrentUser() expert: any,
@Param("requestId") requestId: string,
@@ -496,13 +473,13 @@ export class ExpertInitiatedV2Controller {
}
@Post("create-claim-from-blame/:blameRequestId")
@ApiOperation({
summary: "[V2] Create claim from expert-initiated IN_PERSON blame",
description:
"Field expert creates a claim on behalf of the damaged party. Blame must be COMPLETED (signatures collected). Then use claim v2 endpoints to fill parts, documents, and captures.",
})
@ApiParam({ name: "blameRequestId", description: "Completed blame request ID" })
@ApiResponse({ status: 201, description: "Claim created" })
// @ApiOperation({
// summary: "[V2] Create claim from expert-initiated IN_PERSON blame",
// description:
// "Field expert creates a claim on behalf of the damaged party. Blame must be COMPLETED (signatures collected). Then use claim v2 endpoints to fill parts, documents, and captures.",
// })
// @ApiParam({ name: "blameRequestId", description: "Completed blame request ID" })
// @ApiResponse({ status: 201, description: "Claim created" })
async createClaimFromBlame(
@CurrentUser() expert: any,
@Param("blameRequestId") blameRequestId: string,
@@ -514,12 +491,12 @@ export class ExpertInitiatedV2Controller {
}
@Post("complete-claim-data/:claimRequestId")
@ApiOperation({
summary: "Submit claim-needed data (expert-initiated IN_PERSON)",
})
@ApiParam({ name: "claimRequestId", description: "Claim file ID" })
@ApiBody({ type: ExpertCompleteClaimDataDto })
@ApiResponse({ status: 200, description: "Claim data updated" })
// @ApiOperation({
// summary: "Submit claim-needed data (expert-initiated IN_PERSON)",
// })
// @ApiParam({ name: "claimRequestId", description: "Claim file ID" })
// @ApiBody({ type: ExpertCompleteClaimDataDto })
// @ApiResponse({ status: 200, description: "Claim data updated" })
async completeClaimData(
@CurrentUser() expert: any,
@Param("claimRequestId") claimRequestId: string,