Added U and D endpoints.

This commit is contained in:
2022-04-04 22:50:26 -05:00
parent ba566040b1
commit 7dd862e134
4 changed files with 176 additions and 69 deletions

View File

@@ -24,4 +24,17 @@ const matchSchema = new mongoose.Schema({
createDate: { type: Date, required: true, default: Date.now }
});
matchSchema.pre("remove", function (next) {
const match = this;
match.populate("creator").populate("participants");
match.participants.forEach(participant => {
const index = participant.participatingMatches.indexOf(match._id);
participant.participatingMatches.splice(index, 1);
});
match.creator.createdMatches.splice(match.creator.createdMatches.indexOf(match._id), 1);
next();
});
export default mongoose.model(ModelNameRegister.Match, matchSchema);