Harrison Deng
8f96a2e5c9
All responses are now in their own object with context name. Added limit to user based recent results for matches. Moved all code in endpoints inside try and catch. Renamed authentication guard function.
23 lines
835 B
JavaScript
23 lines
835 B
JavaScript
import mongoose from "mongoose";
|
|
import modelNameRegister from "./modelNameRegister";
|
|
|
|
const Types = mongoose.Schema.Types;
|
|
|
|
const rentalSchema = new mongoose.Schema({
|
|
title: { type: String, required: true, trim: true },
|
|
rate: { type: String, required: true, trim: true },
|
|
description: { type: String, required: true },
|
|
contact: { type: String, required: true },
|
|
createDate: { type: Date, required: true, default: Date.now },
|
|
creator: { type: Types.ObjectId, ref: modelNameRegister.User }
|
|
});
|
|
|
|
rentalSchema.pre("remove", async function (next) {
|
|
const rental = this;
|
|
const rentalInd = rental.creator.createdRentals.indexOf(rental._id);
|
|
rental.creator.createdRentals.splice(rentalInd, 1);
|
|
await rental.save();
|
|
next();
|
|
});
|
|
|
|
export default mongoose.model(modelNameRegister.Rental, rentalSchema); |