fakingoose
fakingoose copied to clipboard
Enum validator for number schema type transpiled from Typescript
I have a problem with the generation of random value of enum (I created an enum in typescript) if I set an enum validator on the mongoose schema, where the enum is this:
export enum TicketStatus {
CLOSED = 0,
OPEN = 1
}
I have a mongoose schema like this:
const schema = new Schema(
{
status: {
type: Number,
default: TicketStatus.OPEN,
enum: TicketStatus
},
...
})
I expect that the value generated was into [0, 1] but it use a random numeric value.
I saw that mongoose add an enumValidator
to the schema with the values { 0: "CLOSED", 1: "OPEN", CLOSED: 0, OPEN: 1 }
.
I'm using:
- Typescript ^4.2.4
- Mongoose ^5.9.7
Sorry about the late response. I hope u found a workaround. I will eventually fix this bug, but for now, you can use an enum array like below
const schema = new Schema(
{
status: {
type: Number,
default: 0,
enum: [0, 1]
},
...
})