Can anyone help me with this error message "TypeError: PartyModel is not a constructor"?
I've tried some solutions, but now I'm getting another error as well.
After using const { ... } = require("./model/..."), I'm seeing "TypeError: Cannot read properties of undefined (reading 'findOne')"
app.ts
import express, { Request, Response } from "express";
const cors = require("cors")
import mongoose from "mongoose"
const configModel = require("./model/ConfigSchema")
const PartyModel = require("./model/PartySchema")
const app = express()
...
app.post('/createParty', cors(), async function (req: CustomRequest<partyModelInterface>, res: Response) {
const input = req.body
const today = new Date()
await reloadConfig()
const party = new PartyModel({
id: partyNumber,
game: input.game,
master: input.master,
description: input.description,
players: input.players,
time: today
})
partyNumber++
saveToDb(party)
res.send("A party has been created")
})
PartySchema.ts
import mongoose from "mongoose";
const partySchema = new mongoose.Schema({
id: {
type: Number,
required: true,
unique: true
},
game: {
type: String,
required: true,
},
master: {
type: String,
required: true
},
description: {
type: String,
required: true
},
players: {
type: Number,
required: true
},
time: {
type: Date,
required: true
}
}, {
versionKey: false,
collection: 'parties'
})
module.exports = mongoose.model('Party', partySchema)