flexbiz-server
Version:
Flexible Server
11 lines (10 loc) • 4.28 kB
JavaScript
'use strict';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},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}),nhadatSchema.index({ma_nd:1}),nhadatSchema.index({phan_loai:1}),nhadatSchema.index({building_code:1}),nhadatSchema.index({ma_dt:1}),nhadatSchema.index({ten_nd:1}),nhadatSchema.index({nh_nd:1}),nhadatSchema.index({nh_bds:1}),nhadatSchema.index({nh_bds2:1}),nhadatSchema.index({nh_bds3:1}),nhadatSchema.index({dia_chi:1}),nhadatSchema.index({dia_chi_en:1}),nhadatSchema.index({xa_phuong:1}),nhadatSchema.index({quan_huyen:1}),nhadatSchema.index({tinh_thanh:1}),
nhadatSchema.index({location:1}),nhadatSchema.index({mieu_ta:1}),nhadatSchema.index({mieu_ta_en:1}),nhadatSchema.index({so_to:1}),nhadatSchema.index({so_thua:1}),nhadatSchema.index({so_phong:1}),nhadatSchema.index({so_wc:1}),nhadatSchema.index({noi_that:1}),nhadatSchema.index({noi_that_en:1}),nhadatSchema.index({can_ho_so:1}),nhadatSchema.index({dien_tich_phong_thuy:1}),nhadatSchema.index({dien_tich_tim_tuong:1}),nhadatSchema.index({huong_ban_cong:1}),nhadatSchema.index({huong_ban_cong_en:1}),nhadatSchema.index({huong_cua_chinh:1}),
nhadatSchema.index({huong_cua_chinh_en:1}),nhadatSchema.index({chieu_ngang:1}),nhadatSchema.index({chieu_dai:1}),nhadatSchema.index({gia_ban:1}),nhadatSchema.index({dien_tich:1}),nhadatSchema.index({gia_ban_m2:1}),nhadatSchema.index({phu_trach:1}),nhadatSchema.index({ma_nd:"text",ten_nd:"text",phu_trach:"text"}),nhadatSchema.index({status:1}),nhadatSchema.index({visible_to_usergroups:1}),nhadatSchema.index({user_created:1,visible_to:1,visible_to_users:1}),nhadatSchema.index({trang_thai: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$$||($lanthu$$=0);32<$ma_nd$$.length&&($ma_nd$$=$ma_nd$$.substring(0,32));return new Promise($resolve$$=>{model.createCode($id_app$$,$ma_nd$$,$lanthu$$,($e$$,$rs$$)=>{$resolve$$($rs$$||"")})})};module.exports=model;