forked from Yara724/api
blame and claim refactored
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
|
||||
import { HydratedDocument, Schema as MongooseSchema, Types } from "mongoose";
|
||||
import { ClaimRequiredDocumentType } from "src/Types&Enums/claim-request-management/required-document-type.enum";
|
||||
import { ClaimStatus } from "src/Types&Enums/claim-request-management/claimStatus.enum";
|
||||
import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-case-status.enum";
|
||||
import { HistoryEvent, HistoryEventSchema } from "src/request-management/entities/schema/historyEvent.type";
|
||||
import {
|
||||
ClaimDamageSelection,
|
||||
ClaimDamageSelectionSchema,
|
||||
} from "./claim-case.damage.schema";
|
||||
import {
|
||||
ClaimMoney,
|
||||
ClaimMoneySchema,
|
||||
ClaimOwner,
|
||||
ClaimOwnerSchema,
|
||||
ClaimVehicleSnapshot,
|
||||
ClaimVehicleSnapshotSchema,
|
||||
} from "./claim-case.identity.schema";
|
||||
import { ClaimMedia, ClaimMediaSchema } from "./claim-case.media.schema";
|
||||
import {
|
||||
ClaimEvaluation,
|
||||
ClaimEvaluationSchema,
|
||||
} from "./claim-case.evaluation.schema";
|
||||
import {
|
||||
ClaimCaseSnapshot,
|
||||
ClaimCaseSnapshotSchema,
|
||||
} from "./claim-case.snapshot.schema";
|
||||
import { ClaimWorkflow, ClaimWorkflowSchema } from "./claim-case.workflow.schema";
|
||||
|
||||
@Schema({ _id: false })
|
||||
export class RequiredDocumentRef {
|
||||
@Prop({ type: Types.ObjectId })
|
||||
fileId?: Types.ObjectId;
|
||||
|
||||
@Prop({ type: String })
|
||||
filePath?: string;
|
||||
|
||||
@Prop({ type: String })
|
||||
fileName?: string;
|
||||
|
||||
@Prop({ type: Boolean, default: true })
|
||||
uploaded?: boolean;
|
||||
|
||||
@Prop({ type: Date })
|
||||
uploadedAt?: Date;
|
||||
}
|
||||
export const RequiredDocumentRefSchema = SchemaFactory.createForClass(RequiredDocumentRef);
|
||||
|
||||
@Schema({
|
||||
collection: "claimCases",
|
||||
timestamps: true,
|
||||
id: true,
|
||||
versionKey: false,
|
||||
})
|
||||
export class ClaimCase {
|
||||
@Prop({ required: true, unique: true, index: true, trim: true })
|
||||
requestNo: string;
|
||||
|
||||
/**
|
||||
* Human-friendly shared id across blame+claim (e.g. A14235).
|
||||
* Generated once on blame creation and copied into claim.
|
||||
*/
|
||||
@Prop({ required: true, unique: true, index: true, trim: true })
|
||||
publicId: string;
|
||||
|
||||
/**
|
||||
* Overall case status (user flow + expert flow progression)
|
||||
*/
|
||||
@Prop({ required: true, type: String, enum: ClaimCaseStatus, default: ClaimCaseStatus.CREATED })
|
||||
status: ClaimCaseStatus;
|
||||
|
||||
/**
|
||||
* Claim damage determination status (expert assessment)
|
||||
*/
|
||||
@Prop({ type: String, enum: ClaimStatus, default: ClaimStatus.PENDING })
|
||||
claimStatus: ClaimStatus;
|
||||
|
||||
/**
|
||||
* Link to the blame case that originated this claim.
|
||||
* IMPORTANT: this is intentionally ONLY an id reference (no embedded blame file).
|
||||
*/
|
||||
@Prop({ type: Types.ObjectId, index: true })
|
||||
blameRequestId?: Types.ObjectId;
|
||||
|
||||
@Prop({ type: String, index: true })
|
||||
blameRequestNo?: string;
|
||||
|
||||
@Prop({ type: ClaimWorkflowSchema, default: () => ({}) })
|
||||
workflow?: ClaimWorkflow;
|
||||
|
||||
@Prop({ type: ClaimOwnerSchema, default: () => ({}) })
|
||||
owner?: ClaimOwner;
|
||||
|
||||
@Prop({ type: ClaimVehicleSnapshotSchema, default: () => ({}) })
|
||||
vehicle?: ClaimVehicleSnapshot;
|
||||
|
||||
@Prop({ type: ClaimMoneySchema })
|
||||
money?: ClaimMoney;
|
||||
|
||||
@Prop({ type: Number })
|
||||
claimNo?: number;
|
||||
|
||||
@Prop({ type: Number })
|
||||
claimId?: number;
|
||||
|
||||
@Prop({ type: ClaimDamageSelectionSchema, default: () => ({}) })
|
||||
damage?: ClaimDamageSelection;
|
||||
|
||||
@Prop({ type: ClaimMediaSchema, default: () => ({}) })
|
||||
media?: ClaimMedia;
|
||||
|
||||
@Prop({ type: ClaimEvaluationSchema, default: () => ({}) })
|
||||
evaluation?: ClaimEvaluation;
|
||||
|
||||
/**
|
||||
* Optional “read-optimized” copy of fields from blame/request side.
|
||||
* Source of truth remains `blameRequestId`.
|
||||
*/
|
||||
@Prop({ type: ClaimCaseSnapshotSchema })
|
||||
snapshot?: ClaimCaseSnapshot;
|
||||
|
||||
/**
|
||||
* For quick “has user uploaded X?” checks. Values point to docs in the
|
||||
* `claim-required-documents` collection.
|
||||
*/
|
||||
@Prop({
|
||||
type: Map,
|
||||
of: RequiredDocumentRefSchema,
|
||||
default: () => ({}),
|
||||
})
|
||||
requiredDocuments?: Map<string, RequiredDocumentRef>;
|
||||
|
||||
@Prop({ type: [HistoryEventSchema], default: [] })
|
||||
history?: HistoryEvent[];
|
||||
|
||||
/**
|
||||
* Legacy fields kept optional to simplify progressive migration.
|
||||
* If you choose to migrate later, we can remove these.
|
||||
*/
|
||||
@Prop({ type: MongooseSchema.Types.Mixed })
|
||||
legacy?: any;
|
||||
}
|
||||
|
||||
export type ClaimCaseDocument = HydratedDocument<ClaimCase>;
|
||||
export const ClaimCaseSchema = SchemaFactory.createForClass(ClaimCase);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user