almeira-web/transporte-cali-buenaventura/backend/src/models/Review.ts

51 lines
1.7 KiB
TypeScript

import mongoose, { Schema, Document, Model } from 'mongoose';
export type ReviewType = 'PASAJERO_A_CONDUCTOR' | 'CONDUCTOR_A_PASAJERO';
export interface IReview extends Document {
tripId?: string;
autorId: string;
autorNombre: string;
autorRol: 'PASAJERO' | 'CONDUCTOR';
destinatarioId?: string;
destinatarioNombre: string;
tipo: ReviewType;
puntuacion: number; // 1 a 5 estrellas
comentario: string;
etiquetas: string[]; // ['PUNTUALIDAD', 'VEHICULO_LIMPIO', 'MANEJO_SEGURO', 'AMABILIDAD', 'COMUNICACION']
ruta: string; // ej: "Cali ➔ Buenaventura"
esPublico: boolean;
createdAt: Date;
updatedAt: Date;
}
const ReviewSchema = new Schema<IReview>(
{
tripId: { type: String, trim: true },
autorId: { type: String, required: true },
autorNombre: { type: String, required: true, trim: true },
autorRol: { type: String, enum: ['PASAJERO', 'CONDUCTOR'], required: true },
destinatarioId: { type: String },
destinatarioNombre: { type: String, required: true, trim: true },
tipo: {
type: String,
enum: ['PASAJERO_A_CONDUCTOR', 'CONDUCTOR_A_PASAJERO'],
default: 'PASAJERO_A_CONDUCTOR',
},
puntuacion: { type: Number, required: true, min: 1, max: 5 },
comentario: { type: String, required: true, trim: true, maxlength: 600 },
etiquetas: [{ type: String }],
ruta: { type: String, default: 'Cali ➔ Buenaventura' },
esPublico: { type: Boolean, default: true },
},
{
timestamps: true,
}
);
ReviewSchema.index({ createdAt: -1 });
ReviewSchema.index({ destinatarioNombre: 1 });
export const Review: Model<IReview> =
mongoose.models.Review || mongoose.model<IReview>('Review', ReviewSchema);