forked from Yara724/api
YARA-739, YARA-740, YARA-741
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user