Multiple changes, basic rental CRUD backend implemented.
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.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export default {
|
||||
Match: "match",
|
||||
User: "user",
|
||||
Sport: "sport"
|
||||
Sport: "sport",
|
||||
Rental: "rental",
|
||||
};
|
23
sports-matcher/server/schemas/rentalModel.js
Normal file
23
sports-matcher/server/schemas/rentalModel.js
Normal file
@@ -0,0 +1,23 @@
|
||||
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);
|
@@ -29,6 +29,7 @@ const userSchema = new mongoose.Schema({
|
||||
},
|
||||
createdMatches: { type: [{ type: Types.ObjectId, ref: modelNameRegister.Match }], required: true, default: [] },
|
||||
participatingMatches: { type: [{ type: Types.ObjectId, ref: modelNameRegister.Match }], required: true, default: [] },
|
||||
createdRentals: { type: [{ type: Types.ObjectId, ref: modelNameRegister.Rental }], required: true, default: [] },
|
||||
emailPublicity: { type: Number, required: true, default: 0 },
|
||||
bioPublicity: { type: Boolean, required: true, default: false },
|
||||
phonePublicity: { type: Boolean, required: true, default: false },
|
||||
|
Reference in New Issue
Block a user