forked from Yara724/api
YARA-739, YARA-740, YARA-741
This commit is contained in:
@@ -35,6 +35,7 @@ import { CarDamagePartDto, OtherCarDamagePartDto } from "./dto/car-part.dto";
|
||||
import { UserCommentDto } from "./dto/user-comment.dto";
|
||||
import { UserObjectionDto } from "./dto/user-objection.dto";
|
||||
import { InPersonVisitDto } from "./dto/in-person-visit.dto";
|
||||
import { UserRatingDto } from "./dto/user-rating.dto";
|
||||
|
||||
@Controller("claim-request-management")
|
||||
@ApiTags("claim-request-management")
|
||||
@@ -400,6 +401,25 @@ export class ClaimRequestManagementController {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* User satisfaction rating for a completed claim file.
|
||||
* Only the damaged user (claim owner) can rate their claim after it is closed.
|
||||
*/
|
||||
@Put("request/:claimRequestId/user-rating")
|
||||
@ApiParam({ name: "claimRequestId" })
|
||||
@ApiBody({ type: UserRatingDto })
|
||||
async addUserRating(
|
||||
@Param("claimRequestId") claimRequestId: string,
|
||||
@Body() ratingDto: UserRatingDto,
|
||||
@CurrentUser() user,
|
||||
) {
|
||||
return await this.claimRequestManagementService.addUserRating(
|
||||
claimRequestId,
|
||||
user,
|
||||
ratingDto,
|
||||
);
|
||||
}
|
||||
|
||||
@Patch("request/reply/:claimRequestId/:partId/upload-factor")
|
||||
@ApiConsumes("multipart/form-data")
|
||||
@ApiParam({ name: "claimRequestId" })
|
||||
|
||||
@@ -37,13 +37,17 @@ import { DamageImageDbService } from "./entites/db-service/damage-image.db.servi
|
||||
import { ClaimFactorsImageDbService } from "./entites/db-service/factor-image.db.service";
|
||||
import { VideoCaptureDbService } from "./entites/db-service/video-capture.db.service";
|
||||
import { ClaimRequiredDocumentDbService } from "./entites/db-service/claim-required-document.db.service";
|
||||
import { ClaimRequestManagementModel } from "./entites/schema/claim-request-management.schema";
|
||||
import {
|
||||
ClaimRequestManagementModel,
|
||||
UserClaimRating,
|
||||
} from "./entites/schema/claim-request-management.schema";
|
||||
import { ImageRequiredModel } from "./entites/schema/image-required.schema";
|
||||
import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service";
|
||||
import { FactorStatus } from "src/Types&Enums/claim-request-management/factor-status.enum";
|
||||
import { BranchDbService } from "src/client/entities/db-service/branch.db.service";
|
||||
import { ClaimRequiredDocumentType } from "src/Types&Enums/claim-request-management/required-document-type.enum";
|
||||
import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { UserRatingDto } from "./dto/user-rating.dto";
|
||||
|
||||
@Injectable()
|
||||
export class ClaimRequestManagementService {
|
||||
@@ -1568,6 +1572,52 @@ export class ClaimRequestManagementService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the damaged user to rate their claim file after completion.
|
||||
* Only the claim owner (damaged user) can submit this rating and only
|
||||
* when the claim is in CloseRequest status.
|
||||
*/
|
||||
async addUserRating(
|
||||
claimRequestId: string,
|
||||
actor: any,
|
||||
ratingDto: UserRatingDto,
|
||||
): Promise<UserClaimRating> {
|
||||
const claim = await this.claimDbService.findOne(claimRequestId);
|
||||
|
||||
if (!claim) {
|
||||
throw new NotFoundException("Claim file not found");
|
||||
}
|
||||
|
||||
// Only the damaged user (claim owner) can rate the claim
|
||||
const actorId = actor?.sub;
|
||||
if (!actorId || String(claim.userId) !== actorId) {
|
||||
throw new ForbiddenException(
|
||||
"Only the claim owner can submit a satisfaction rating.",
|
||||
);
|
||||
}
|
||||
|
||||
// Rating is only allowed after the claim is fully closed
|
||||
if (claim.claimStatus !== ReqClaimStatus.CloseRequest) {
|
||||
throw new BadRequestException(
|
||||
"You can only rate a claim after it has been closed.",
|
||||
);
|
||||
}
|
||||
|
||||
const userRating: UserClaimRating = {
|
||||
progressSpeed: ratingDto.progressSpeed,
|
||||
registrationEase: ratingDto.registrationEase,
|
||||
overallEvaluation: ratingDto.overallEvaluation,
|
||||
comment: ratingDto.comment,
|
||||
createdAt: new Date(),
|
||||
};
|
||||
|
||||
await this.claimDbService.findAndUpdate(claimRequestId, {
|
||||
$set: { userRating },
|
||||
});
|
||||
|
||||
return userRating;
|
||||
}
|
||||
|
||||
async uploadClaimFactor(
|
||||
claimId: string,
|
||||
partId: string,
|
||||
|
||||
39
src/claim-request-management/dto/user-rating.dto.ts
Normal file
39
src/claim-request-management/dto/user-rating.dto.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
|
||||
export class UserRatingDto {
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
minimum: 0,
|
||||
maximum: 5,
|
||||
description: "سرعت پیشرفت پرونده",
|
||||
example: 4,
|
||||
})
|
||||
progressSpeed: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
minimum: 0,
|
||||
maximum: 5,
|
||||
description: "سهولت ثبت پرونده",
|
||||
example: 4,
|
||||
})
|
||||
registrationEase: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: Number,
|
||||
minimum: 0,
|
||||
maximum: 5,
|
||||
description: "ارزیابی کلی",
|
||||
example: 5,
|
||||
})
|
||||
overallEvaluation: number;
|
||||
|
||||
@ApiProperty({
|
||||
type: String,
|
||||
required: false,
|
||||
description: "متن رضایت یا عدم آن",
|
||||
})
|
||||
comment?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,28 @@ export class UserObjection {
|
||||
typeOfDamage: string;
|
||||
}
|
||||
|
||||
@Schema({ _id: false })
|
||||
export class UserClaimRating {
|
||||
// 1. سرعت پیشرفت پرونده (speed of progress)
|
||||
@Prop({ type: Number, min: 0, max: 5, required: true })
|
||||
progressSpeed: number;
|
||||
|
||||
// 2. سهولت ثبت پرونده (ease of registration)
|
||||
@Prop({ type: Number, min: 0, max: 5, required: true })
|
||||
registrationEase: number;
|
||||
|
||||
// 3. ارزیابی کلی (overall evaluation)
|
||||
@Prop({ type: Number, min: 0, max: 5, required: true })
|
||||
overallEvaluation: number;
|
||||
|
||||
// 4. متن رضایت یا عدم آن (optional text feedback)
|
||||
@Prop({ type: String, required: false })
|
||||
comment?: string;
|
||||
|
||||
@Prop({ type: Date, default: () => new Date() })
|
||||
createdAt?: Date;
|
||||
}
|
||||
|
||||
@Schema({ _id: false })
|
||||
export class FileRating {
|
||||
@Prop({ type: Number, min: 0, max: 5 })
|
||||
@@ -315,6 +337,10 @@ export class ClaimRequestManagementModel {
|
||||
@Prop({ type: FileRating, required: false })
|
||||
rating?: FileRating;
|
||||
|
||||
// User-facing satisfaction rating for this claim
|
||||
@Prop({ type: UserClaimRating, required: false })
|
||||
userRating?: UserClaimRating;
|
||||
|
||||
@Prop({ type: String, required: false })
|
||||
visitLocation?: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user