UNPKG

flexbiz-server

Version:

Flexible Server

9 lines (8 loc) 3.17 kB
'use strict';const dmnvtSchema=new Schema({id_app:{type:String,required:!0,maxlength:1024},stt:{type:Number,default:0},ten_nvt:{type:String,required:!0,maxlength:1024},nh_me:{type:String,maxlength:1024},ma_nganh_hang:String,ds_nganh_hang:[String],group_kind:{type:Number,default:1},loai_nh:{type:Number,default:1},bac:Number,sysorder:String,quan_trong:Boolean,la_nhom_hang_hoa:Boolean,ban_tai_quay:Boolean,description:String,logo:{type:String,maxlength:1024},banner1:{type:String,maxlength:1024},banner2:{type:String, maxlength:1024},cac_thuoc_tinh:[],exfields:Schema.Types.Mixed,status:{type:Boolean,default:!0},shared:{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:""}},{toJSON:{virtuals:!0}}); (global.configs||{}).createIndexes&&(dmnvtSchema.index({id_app:1,ten_nvt:1}),dmnvtSchema.index({nh_me:1}),dmnvtSchema.index({sysorder:1}),dmnvtSchema.index({loai_nh:1}),dmnvtSchema.index({group_kind:1}),dmnvtSchema.index({bac:1}),dmnvtSchema.index({"cac_thuoc_tinh.id_tt":1}),dmnvtSchema.index({"cac_thuoc_tinh.ma_vt":1}),dmnvtSchema.index({"cac_thuoc_tinh.ma_tt":1}),dmnvtSchema.index({"cac_thuoc_tinh.loai_tt":1}),dmnvtSchema.index({ma_nganh_hang:1}),dmnvtSchema.index({ds_nganh_hang:1}),dmnvtSchema.index({la_nhom_hang_hoa:1}), dmnvtSchema.index({ban_tai_quay:1}),dmnvtSchema.index({description:1}),dmnvtSchema.index({ten_nvt:"text",nh_me:"text",description:"text"},{name:"dmnvt_index_text"}),dmnvtSchema.index({status:1}),dmnvtSchema.index({user_created:1,visible_to:1,visible_to_users:1}));const model=mongoose.models.dmnvt||mongoose.model("dmnvt",dmnvtSchema);model.referenceKeys={_id:[{model:"dmvt",key:"ma_nvt",error:"Nh\u00f3m v\u1eadt t\u01b0 ${obj.ten_nvt} \u0111\u00e3 ph\u00e1t sinh d\u1eef li\u1ec7u trong danh m\u1ee5c v\u1eadt t\u01b0"}]}; const _=require("lodash"); model.getAllChildrenGroup=async($id_app$$,$chil_ma_nvt_nh_vt_cons$$,$la_nhom_hang_hoa$$,$ma_nganh_hang$$,$condition_query$$={group_kind:1})=>{let $rs$$=[];$condition_query$$={id_app:$id_app$$,status:!0,...$condition_query$$};$ma_nganh_hang$$&&($condition_query$$.ds_nganh_hang=$ma_nganh_hang$$);void 0!=$la_nhom_hang_hoa$$&&($condition_query$$.la_nhom_hang_hoa=$la_nhom_hang_hoa$$);$chil_ma_nvt_nh_vt_cons$$&&(_.isArray($chil_ma_nvt_nh_vt_cons$$)?($rs$$=[...$rs$$,...$chil_ma_nvt_nh_vt_cons$$],$condition_query$$.nh_me= {$in:$chil_ma_nvt_nh_vt_cons$$}):($condition_query$$.nh_me=$chil_ma_nvt_nh_vt_cons$$,$chil_ma_nvt_nh_vt_cons$$.$in?$rs$$=[...$rs$$,...$chil_ma_nvt_nh_vt_cons$$.$in]:$rs$$.push($chil_ma_nvt_nh_vt_cons$$)));$chil_ma_nvt_nh_vt_cons$$=(await model.find($condition_query$$,{_id:1,nh_me:1}).lean()).filter($n$$=>$n$$._id.toString()!=$n$$.nh_me).map($d$$=>$d$$._id);0<$chil_ma_nvt_nh_vt_cons$$.length&&($chil_ma_nvt_nh_vt_cons$$=await Promise.all($chil_ma_nvt_nh_vt_cons$$.map($nh$$=>model.getAllChildrenGroup($id_app$$, $nh$$,$la_nhom_hang_hoa$$,$ma_nganh_hang$$))),$chil_ma_nvt_nh_vt_cons$$=$chil_ma_nvt_nh_vt_cons$$.reduce(($a$$,$b$$)=>$a$$.concat($b$$),[]),$rs$$=[...$chil_ma_nvt_nh_vt_cons$$,...$rs$$]);return $rs$$};module.exports=model;