UNPKG

flexbiz-server

Version:

Flexible Server

15 lines (14 loc) 6.02 kB
'use strict';const User=require("./user"),Participant=require("./participant"),_=require("lodash"),appScheam=new global.Schema({menu_code:{type:String,uppercase:!0,trim:!0,maxlength:32},app_code:{type:String,uppercase:!0,trim:!0,maxlength:32},name:{type:String,required:!0,maxlength:1024},name_en:{type:String,maxlength:1024},short_name:{type:String,maxlength:1024},address:{type:String,maxlength:1024},address_en:{type:String,maxlength:1024},factory_address:{type:String,maxlength:1024},factory_address_en:{type:String, maxlength:1024},city:{type:String,maxlength:1024},province:{type:String,maxlength:1024},country:{type:String,maxlength:1024},phone:{type:String,maxlength:1024},fax:{type:String,maxlength:1024},email:{type:String,maxlength:1024},website:{type:String,maxlength:1024},sale_online:{type:Boolean,default:!1},facebook:{type:String,maxlength:2024},zalo:{type:String,maxlength:2024},messager:{type:String,maxlength:2024},bao_hanh:{type:String},van_chuyen:{type:String},dieu_khoan_su_dung:{type:String},dieu_khoan_su_dung_en:{type:String}, dieu_khoan_kygui:{type:String},dieu_khoan_kygui_en:{type:String},dieu_khoan_congtacvien:{type:String},dieu_khoan_congtacvien_en:{type:String},chinh_sach_dau_tu:{type:String},chinh_sach_dau_tu_en:{type:String},gioi_thieu:{type:String},nganh_nghe:{type:String},keywords:{type:String},site_name:{type:String},ngay_dn:{type:Date,required:!0},ngay_ks:{type:Date,required:!0},nam_bd:{type:Number,required:!0},ngay_ky1:{type:Date,required:!0},ma_so_thue:{type:String,maxlength:1024},dia_chi_xuat_hoa_don:String, nguoi_nop_thue:{type:String,maxlength:1024},giam_doc:{type:String,maxlength:1024},ke_toan_truong:{type:String,maxlength:1024},wallet_address:{type:String,maxlength:2024},wallet_token:{type:String,maxlength:2024},exchange_fee:Number,wallet_network:{type:String,maxlength:2024},tang_duoc_gioi_thieu:Number,tang_gioi_thieu:Number,ty_le_hoa_hong:Number,tang_gioi_thieu_denom:String,ten_chu_tai_khoan:String,tai_khoan_ngan_hang:String,ten_ngan_hang:String,chi_nhanh_ngan_hang:String,so_bin:String,so_ngay_lam_mot_thang:{type:Number, default:24},logo:{type:String,maxlength:1024},logo_watermark:{type:String,maxlength:1024},account_types_accept:[],options:{},allow_modules:[String],partner:String,server:String,owner:String,default_password:String,google_credentials:String,email_host:String,email_port:Number,email_secure:{type:Boolean,default:!0},email_authMethod:{type:String,default:"LOGIN"},email_user:String,email_pass:String,email_name:String,viettel_version:{type:String,maxlength:1024},viettel_user:{type:String,maxlength:1024}, viettel_password:{type:String,maxlength:1024},viettel_token:{type:String},viettel_url_service:{type:String,maxlength:1024},viettel_direct_issue:Boolean,vnpt_user:{type:String,maxlength:1024},vnpt_password:{type:String,maxlength:1024},vnpt_url_service:{type:String,maxlength:1024},ma_hoa_don:String,ky_hieu_hoa_don:String,so_serial:String,sip_uri:String,sip_password:String,sip_websocket:String,voiip_access_token:String,voiip_webhook:String,zalo_app_id:String,zalo_secret_key:String,zalo_code:String,zalo_oa_id:String, zalo_code_verifier:String,zalo_code_challenge:String,zalo_access_token:String,zalo_refresh_token:String,zalo_expires_in:Number,zalo_updated:Date,zalo_otp_template_id:String,exfields:global.Schema.Types.Mixed,domain:String,ssl_key:String,ssl_cert:String,ssl_ca:String,expire_date:Date,trang_thai:{type:String,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:""}});(global.configs||{}).createIndexes&&(appScheam.index({app_code:1},{unique:!0}),appScheam.index({name:1,province:1}),appScheam.index({menu_code:1}),appScheam.index({trang_thai:1}),appScheam.index({sale_online:1}),appScheam.index({date_created:1}),appScheam.index({date_updated:1}),appScheam.index({user_created:"text"},{name:"app_index_created"}),appScheam.index({name:"text",province:"text",name_en:"text",address:"text",phone:"text",email:"text",ma_so_thue:"text"},{name:"app_index"})); const App=global.mongoose.models.app||global.mongoose.model("app",appScheam); App.participants=async $app$$=>{_.isString($app$$)&&($app$$=await App.getInfo($app$$));let $participants$$=await Participant.find({id_app:$app$$._id});if($app$$.user_created&&!$participants$$.find($p$$=>$p$$.email===$app$$.user_created)){let $_p$$={email:$app$$.user_created,name:$app$$.user_created.split("@")[0],admin:!0,active:!0,cancel:!1,id_app:$app$$._id};$participants$$.push($_p$$);Participant.createParticipant($_p$$,$e$$=>{$e$$&&console.error("create participant for user owner",$e$$)})}return $participants$$}; App.getInfo=async function($id_app$$,$field$$){return new Promise(($resolve$$,$reject$$)=>{App.findOne({_id:$id_app$$}).lean().exec(($e$$,$rs$$)=>{if($e$$||!$rs$$)return $reject$$(Error($e$$?$e$$.message:"App is not exists"));$resolve$$($field$$?$rs$$[$field$$]:$rs$$)})})}; App.emitEvent=function($id_app$$,$event$$,$_data$$,$c_token$$=null,$users$$=null,$_createNotify$$=!1,$_push$$=!0){App.findOne({_id:$id_app$$}).lean().exec(async($e$jscomp$0$$,$app$$)=>{$app$$&&($_data$$.company=$app$$.name,$_data$$.app_info=$app$$,$_data$$.id_app=$id_app$$,$users$$?$users$$=$users$$.map($u$$=>({email:$u$$,name:$u$$})):($users$$=await App.participants($app$$),$users$$.find($u$$=>$app$$.user_created===$u$$.email)||$users$$.push({email:$app$$.user_created,name:$app$$.user_created})), $users$$.forEach(function($user$$){let $data$$=_.cloneDeep($_data$$);!$data$$.title||!$_createNotify$$&&$event$$?$event$$&&User.emitEvent($user$$.email,$event$$,$data$$,$_push$$,$c_token$$):global.createNotification($data$$.user_updated||"SYSTEM",$user$$.email,$data$$.title,$data$$.body,($e$$,$notify$$)=>{$e$$?console.error($e$$):$event$$&&($notify$$&&($data$$.notify_id=$notify$$._id.toString()),User.emitEvent($user$$.email,$event$$,$data$$,$_push$$,$c_token$$))},$data$$,!$event$$,$c_token$$)}))})}; module.exports=App;