flexbiz-server
Version:
Flexible Server
14 lines (13 loc) • 5.41 kB
JavaScript
const validator=require("../libs/validator"),nhadatSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},stt:{type:Number,default:0},ma_nd:{type:String,required:!0,uppercase:!0},ten_nd:{type:String,required:!0},ten_nd_en:{type:String},nh_nd:{type:String},phan_loai:String,nh_bds:{type:String,default:"",trim:!0,maxlength:1024},ten_nh_bds:String,nh_bds2:[String],nh_bds3:[String],ma_dt:{type:String,uppercase:!0},building_code:{type:String,uppercase:!0},dia_chi:{type:String},dia_chi_en:{type:String},
xa_phuong:{type:String},quan_huyen:{type:String},tinh_thanh:{type:String},so_to:{type:String},so_thua:{type:String},location:Schema.Types.Mixed,chieu_ngang:{type:Number,default:0},chieu_dai:{type:Number,default:0},dien_tich:{type:Number,default:0},gia_ban:{type:Number,default:0},gia_ban_m2:{type:Number,default:0},so_phong:Number,so_wc:Number,noi_that:String,noi_that_en:String,can_ho_so:String,dien_tich_phong_thuy:Number,dien_tich_tim_tuong:Number,huong_ban_cong:String,huong_ban_cong_en:String,huong_cua_chinh:String,
huong_cua_chinh_en:String,mieu_ta:String,mieu_ta_en:String,picture:String,ky_gui:Boolean,ten_chu_so_huu:String,dien_thoai_chu_so_huu:String,dia_chi_chu_so_huu:String,anh_cmnd:String,anh_giay_to:String,chap_nhan_dieu_khoan:{type:Boolean},so_ct:String,id_kh:{type:String},exfields:Schema.Types.Mixed,phu_trach:{type:String,lowercase:!0},ngay_cap_nhat:{type:Date,default:Date.now},progress:{type:Number,default:0},trang_thai:{type:String,maxlength:32},ngay_het_han:Date,da_nhac_nho:{type:Number,default:0},
status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""},visible_to:{type:Number,default:0},visible_to_users:[String],visible_to_usergroups:[String],update_right:[String],delete_right:[String],shared:Boolean});nhadatSchema.validate={ma_nt:validator.existsNt};
(global.configs||{}).createIndexes&&(nhadatSchema.index({id_app:1,trang_thai:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,ma_nd:1,ten_nd:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,phan_loai:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,ma_dt:1,building_code:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,nh_nd:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,nh_bds:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,nh_bds2:1,stt:1,date_created:-1}),
nhadatSchema.index({id_app:1,nh_bds3:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,ngay_het_han:1,da_nhac_nho:1}),nhadatSchema.index({id_app:1,tinh_thanh:1,stt:1}),nhadatSchema.index({id_app:1,tinh_thanh:1,quan_huyen:1,xa_phuong:1,dia_chi:1,dia_chi_en:1,location:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,so_to:1,so_thua:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,so_phong:1,so_wc:1,noi_that:1,noi_that_en:1,can_ho_so:1,dien_tich_phong_thuy:1,dien_tich_tim_tuong:1,stt:1,
date_created:-1}),nhadatSchema.index({id_app:1,huong_ban_cong:1,huong_ban_cong_en:1,huong_cua_chinh:1,huong_cua_chinh_en:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,chieu_ngang:1,chieu_dai:1,gia_ban:1,dien_tich:1,gia_ban_m2:1,stt:1,date_created:-1,status:1}),nhadatSchema.index({id_app:1,ma_nd:"text",ten_nd:"text",phu_trach:"text",mieu_ta:"text",mieu_ta_en:"text",stt:1,date_created:-1,status:1}),nhadatSchema.index({id_app:1,phu_trach:1,user_created:1,visible_to:1,visible_to_users:1,status:1,
phan_loai:1,ten_nd:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,phu_trach:1,user_created:1,visible_to:1,visible_to_users:1,status:1,ma_dt:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,phu_trach:1,user_created:1,visible_to:1,visible_to_users:1,status:1,tinh_thanh:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,phu_trach:1,user_created:1,visible_to:1,visible_to_users:1,status:1,tinh_thanh:1,phan_loai:1,stt:1,date_created:-1}),nhadatSchema.index({id_app:1,phu_trach:1,user_created:1,
visible_to:1,visible_to_users:1,status:1,tinh_thanh:1,chieu_ngang:1,chieu_dai:1,gia_ban:1,dien_tich:1,gia_ban_m2:1,ma_dt:1,stt:1,date_created:-1}));const model=mongoose.models.nhadat||mongoose.model("nhadat",nhadatSchema);
model.createCode=function($id_app$$,$ma_nd$$,$lanthu$$,$callback$$){$ma_nd$$=$ma_nd$$.replace(/[^\w\s]/gi,"").split(" ").join("").toUpperCase();model.findOne({ma_nd:$ma_nd$$,id_app:$id_app$$},function($e$$,$rs$$){if($e$$)return $callback$$($e$$);if($rs$$)$lanthu$$+=1,$ma_nd$$=$ma_nd$$.substring(0,$ma_nd$$.length-$lanthu$$.toString().length)+$lanthu$$.toString(),model.createCode($id_app$$,$ma_nd$$,$lanthu$$,$callback$$);else return $callback$$(null,$ma_nd$$)})};
model.asyncCreateCode=async($id_app$$,$ma_nd$$,$lanthu$$)=>{$lanthu$$||=0;$ma_nd$$.length>32&&($ma_nd$$=$ma_nd$$.substring(0,32));return new Promise($resolve$$=>{model.createCode($id_app$$,$ma_nd$$,$lanthu$$,($e$$,$rs$$)=>{$resolve$$($rs$$||"")})})};
model.tinhtylehh=async($cs_id_app$$,$user_email$$,$chinhsachhoahong$$=[],$cap$$="1")=>{let $par$$=await global.getModel("participant").findOne({id_app:$cs_id_app$$,email:$user_email$$}).lean();if(!$par$$)throw"Ng\u01b0\u1eddi s\u1eed d\u1ee5ng kh\u00f4ng h\u1ee3p l\u1ec7";($cs_id_app$$=$chinhsachhoahong$$.find($c$$=>$c$$.cap==$cap$$&&$par$$.group_id==$c$$.user_group))||($cs_id_app$$=$chinhsachhoahong$$.find($c$$=>$c$$.cap==$cap$$&&!$c$$.user_group));return $cs_id_app$$?.ty_le_hh||0};
module.exports=model;