flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.65 kB
JavaScript
'use strict';const sodiemthuongSchema=new global.Schema({id_app:{type:String,required:!0,maxlength:1024},id_ct:{type:String,required:!0,maxlength:1024},ma_dvcs:{type:String,required:!0,maxlength:1024},ma_ct:{type:String,required:!0,uppercase:!0,maxlength:32,trim:!0},so_ct:{type:String,required:!0,uppercase:!0,trim:!0,maxlength:32},ngay_ct:{type:Date,default:Date.now,required:!0},ma_kh:{type:String,maxlength:32,trim:!0},sl_nhan:{type:Number,default:0},sl_dung:{type:Number,default:0},dien_giai:{type:String,
default:"",maxlength:1024},exfields:global.Schema.Types.Mixed,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],update_right:[String],delete_right:[String]});
(global.configs||{}).createIndexes&&(sodiemthuongSchema.index({id_app:1,ma_dvcs:1,so_ct:-1,ngay_ct:-1}),sodiemthuongSchema.index({ma_ct:1}),sodiemthuongSchema.index({trang_thai:1}),sodiemthuongSchema.index({ma_kh:1}),sodiemthuongSchema.index({user_created:1,date_created:-1}),sodiemthuongSchema.index({date_updated:-1}),sodiemthuongSchema.index({status:1}),sodiemthuongSchema.index({user_created:1,visible_to:1,visible_to_users:1}));
const model=global.mongoose.models.sodiemthuong||global.mongoose.model("sodiemthuong",sodiemthuongSchema);model.getBalance=async($id_app$$,$ma_kh$$)=>(await model.find({id_app:$id_app$$,ma_kh:$ma_kh$$})).map($s$$=>($s$$.sl_nhan||0)-($s$$.sl_dung||0)).reduce(($a$$,$b$$)=>$a$$+$b$$,0);module.exports=model;