contract.model.ts111 lines, 3.1 KB
| 1 | import mongoose, { Schema } from "mongoose"; |
| 2 | import { IUser } from "./user.model"; |
| 3 | |
| 4 | interface IRisk { |
| 5 | risk: string; |
| 6 | explanation: string; |
| 7 | severity: "low" | "medium" | "high"; |
| 8 | } |
| 9 | |
| 10 | interface IOpportunity { |
| 11 | opportunity: string; |
| 12 | explanation: string; |
| 13 | impact: "low" | "medium" | "high"; |
| 14 | } |
| 15 | |
| 16 | interface ICompensationStructure { |
| 17 | baseSalary: string; |
| 18 | bonuses: string; |
| 19 | equity: string; |
| 20 | otherBenefits: string; |
| 21 | } |
| 22 | |
| 23 | export interface IContractAnalysis extends Document { |
| 24 | userId: IUser["_id"]; |
| 25 | contractText: string; |
| 26 | risks: IRisk[]; |
| 27 | opportunities: IOpportunity[]; |
| 28 | summary: string; |
| 29 | recommendations: string[]; |
| 30 | keyClauses: string[]; |
| 31 | legalCompliance: string; |
| 32 | negotiationPoints: string[]; |
| 33 | contractDuration: string; |
| 34 | terminationConditions: string; |
| 35 | overallScore: number; |
| 36 | compensationStructure: ICompensationStructure; |
| 37 | performanceMetrics: string[]; |
| 38 | intellectualPropertyClauses: string | string[]; |
| 39 | createdAt: Date; |
| 40 | version: number; |
| 41 | userFeedback: { |
| 42 | rating: number; |
| 43 | comments: string; |
| 44 | }; |
| 45 | customFields: { [key: string]: string }; |
| 46 | expirationDate: Date; |
| 47 | language: string; |
| 48 | aiModel: string; |
| 49 | contractType: string; |
| 50 | financialTerms?: { |
| 51 | description: string; |
| 52 | details: string[]; |
| 53 | }; |
| 54 | // projectId: IProject["_id"]; |
| 55 | } |
| 56 | |
| 57 | const ContractAnalysisSchema: Schema = new Schema({ |
| 58 | userId: { type: Schema.Types.ObjectId, ref: "User", required: true }, |
| 59 | contractText: { type: String, required: true }, |
| 60 | risks: [{ risk: String, explanation: String, severity: String }], |
| 61 | opportunities: [{ opportunity: String, explanation: String, impact: String }], |
| 62 | summary: { type: String, required: true }, |
| 63 | recommendations: [{ type: String }], |
| 64 | keyClauses: [{ type: String }], |
| 65 | legalCompliance: { type: String }, |
| 66 | negotiationPoints: [{ type: String }], |
| 67 | contractDuration: { type: String }, |
| 68 | terminationConditions: { type: String }, |
| 69 | overallScore: { type: Number, min: 0, max: 100 }, |
| 70 | compensationStructure: { |
| 71 | baseSalary: String, |
| 72 | bonuses: String, |
| 73 | equity: String, |
| 74 | otherBenefits: String, |
| 75 | }, |
| 76 | performanceMetrics: [{ type: String }], |
| 77 | intellectualPropertyClauses: { |
| 78 | type: Schema.Types.Mixed, |
| 79 | validate: { |
| 80 | validator: function (v: any) { |
| 81 | return ( |
| 82 | typeof v === "string" || |
| 83 | (Array.isArray(v) && v.every((item) => typeof item === "string")) |
| 84 | ); |
| 85 | }, |
| 86 | message: (props: { value: any }) => |
| 87 | `${props.value} is not a valid string or array of strings!`, |
| 88 | }, |
| 89 | }, |
| 90 | createdAt: { type: Date, default: Date.now }, |
| 91 | version: { type: Number, default: 1 }, |
| 92 | userFeedback: { |
| 93 | rating: { type: Number, min: 1, max: 5 }, |
| 94 | comments: String, |
| 95 | }, |
| 96 | customFields: { type: Map, of: String }, |
| 97 | expirationDate: { type: Date, required: false }, |
| 98 | language: { type: String, default: "en" }, |
| 99 | aiModel: { type: String, default: "gemini-pro" }, |
| 100 | contractType: { type: String, required: true }, |
| 101 | financialTerms: { |
| 102 | description: String, |
| 103 | details: [String], |
| 104 | }, |
| 105 | // projectId: { type: Schema.Types.ObjectId, ref: "Project", required: true }, |
| 106 | }); |
| 107 | |
| 108 | export default mongoose.model<IContractAnalysis>( |
| 109 | "ContractAnalysis", |
| 110 | ContractAnalysisSchema |
| 111 | ); |