Added U and D endpoints.
This commit is contained in:
@@ -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);
|
Reference in New Issue
Block a user