first
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import mongoose, { Schema, model } from "mongoose";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
||||
const AutoIncrement = require("mongoose-sequence")(mongoose);
|
||||
|
||||
export interface ICity {
|
||||
_id: number;
|
||||
name: string;
|
||||
province: number;
|
||||
}
|
||||
|
||||
const citySchema = new Schema<ICity>(
|
||||
{
|
||||
_id: Number,
|
||||
name: { type: String, required: true, index: true },
|
||||
province: { type: Number, ref: "Province", required: true },
|
||||
},
|
||||
{ timestamps: true, toJSON: { versionKey: false, virtuals: true }, _id: false, id: false },
|
||||
);
|
||||
|
||||
citySchema.plugin(AutoIncrement, { id: "city_id", inc_field: "_id" });
|
||||
const CityModel = model<ICity>("City", citySchema);
|
||||
|
||||
export { CityModel };
|
||||
Reference in New Issue
Block a user