UNPKG

flexbiz-server

Version:

Flexible Server

8 lines (7 loc) 3.5 kB
'use strict';const assperiodSchema=new Schema({id_app:String,creator:{type:String,trim:!0},id:{type:String,trim:!0},ten_ky_han:{type:String},id_product:{type:String,trim:!0},ten_san_pham:{type:String},product_token:{type:String,lowercase:!0,trim:!0},gia:{type:Number,default:0},lai_suat_cam_ket:{type:Number,default:0},lai_suat_truoc_han:{type:Number,default:0},ky_han:{type:Number},ky_tinh_lai:{type:Number},chia_loi_nhuan:Boolean,loi_nhuan_duoc_chia:{type:Number,default:0},ngay_chia_loi_nhuan:Date, lai_suat_thoi_gian_con_lai:{type:Number,default:0},tong_so_token:{type:Number,default:0},da_dau_tu:{type:Number,default:0},da_dao_han:{type:Number,default:0},da_rut_von:{type:Number,default:0},cho_phep_rut_von:{type:Boolean},tg_xu_ly_rut_von:{type:Number,default:0},cho_phep_chuyen_nhuong:{type:Boolean},hoat_dong:{type:Boolean},denom:{type:String,trim:!0},co_phan:Boolean,goi_dau_tu:Boolean,ngay_phat_hanh:Date,id_rpt:String,lai_suat_tang_them_so_huu_token:{type:Number,default:0},token_so_huu:String, so_luong_so_huu:{type:Number,default:0},so_ngay_dau_tu_toi_thieu:{type:Number,default:0},tru_lai_da_tra:Boolean,ty_le_hoa_hong_groups:[],ky_tra_hoa_hong:Number,han_tt:{type:Number,default:1},trang_thai:String,signature:String,visible_to:{type:Number,default:0},visible_to_users:[String],visible_to_usergroups:[String],update_right:[String],delete_right:[String],exfields:Schema.Types.Mixed,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:""}}),thongke=async $p$$=>{let $investments$$=await global.getModel("assinvestment").find({id_app:$p$$.id_app,id_period:$p$$.id,trang_thai:{$nin:["0","2","7"]}},{so_luong:1,da_rut_von:1,trang_thai:1}).lean();$p$$.da_dau_tu=$investments$$.map($ivt$$=>$ivt$$.so_luong).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$p$$.da_rut_von=$investments$$.map($ivt$$=>$ivt$$.da_rut_von||0).reduce(($a$$,$b$$)=>$a$$+$b$$,0);$p$$.da_dao_han=$investments$$.filter($inv$$=> "5"==$inv$$.trang_thai).map($ivt$$=>$ivt$$.so_luong).reduce(($a$$,$b$$)=>$a$$+$b$$,0)-$p$$.da_rut_von};assperiodSchema.post("find",async function($result$$){for(let $i$$=0;$i$$<$result$$.length;$i$$++){const $p$$=$result$$[$i$$];$p$$.id&&$p$$.id_app&&await thongke($p$$)}});assperiodSchema.post("findOne",async function($p$$){$p$$&&$p$$.id&&$p$$.id_app&&await thongke($p$$)});const model=mongoose.models.assperiod||mongoose.model("assperiod",assperiodSchema); (global.configs||{}).createIndexes&&(assperiodSchema.index({id_app:1}),assperiodSchema.index({creator:1}),assperiodSchema.index({id:1}),assperiodSchema.index({ten_ky_han:1}),assperiodSchema.index({id_product:1}),assperiodSchema.index({product_token:1}),assperiodSchema.index({visible_to:1}),assperiodSchema.index({visible_to_users:1}),assperiodSchema.index({ten_san_pham:1}),assperiodSchema.index({co_phan:1}),assperiodSchema.index({ngay_phat_hanh:-1}),assperiodSchema.index({cho_phep_rut_von:1}),assperiodSchema.index({cho_phep_chuyen_nhuong:1}), assperiodSchema.index({hoat_dong:1}),assperiodSchema.index({denom:1}),assperiodSchema.index({trang_thai:1}),assperiodSchema.index({status:1}),assperiodSchema.index({user_created:1}),assperiodSchema.index({creator:"text",ten_san_pham:"text",ten_ky_han:"text",denom:"text"},{name:"assperiod_index2"}),model.on("index",async function($err$$){$err$$?console.error("AssPeriod index error",$err$$):console.info("AssPeriod indexing complete")}));module.exports=model;