fixed: se aggiungo una Provincia sul frontend non si aggiungeva

This commit is contained in:
Surya Paolo
2023-11-24 17:52:17 +01:00
parent 7b14c09fd5
commit c92dc8f216
4 changed files with 29 additions and 7 deletions

View File

@@ -35,11 +35,32 @@ const ProvinceSchema = new Schema({
link_grp: {
type: String,
},
card : {
type: String,
},
link_telegram: {
type: String,
},
}, { _id : false });
ProvinceSchema.pre('save', async function (next) {
if (this.isNew) {
const myrec = await Province.findOne().limit(1).sort({_id:-1});
if (!!myrec) {
if (myrec._doc._id === 0)
this._id = 1;
else
this._id = myrec._doc._id + 1;
} else {
this._id = 1;
}
}
next();
});
ProvinceSchema.statics.getRegionByStrProvince = async function(strprovince) {
const myrec = await Province.findOne({prov: strprovince}).lean();
if (myrec) {