UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.59 kB
'use strict';const model=global.getModel("bds_area"),App=global.getModel("app"),Participant=global.getModel("participant"),Usergroup=global.getModel("usergroup"),Customer=global.getModel("customer"),controller=require("../../controllers/controller"),async=require("async"),area=function($router$$){(new controller($router$$,model,"area",{sort:{stt:1,area_name:1},unique:["area_code"],notNeedRight:($user$$,$options$$={})=>"view"==($options$$.action||"").toLowerCase()?!0:!1,onView:($user$$,$items$$,$next$$)=> {async.series({add_user_to_company:$callback$jscomp$0$$=>{let $id_apps$$=[...(new Set($items$$.map($i$$=>$i$$.id_app)))];async.mapSeries($id_apps$$,($id_app$$,$callback$$)=>{(async()=>{let $group_id$$;try{$group_id$$=await Usergroup.getInfo($id_app$$,{status:!0,is_customer_group:!0},"_id")}catch($e$$){console.log($e$$.message)}if(!$group_id$$)return $callback$$();Participant.createParticipant({id_app:$id_app$$,email:$user$$.email,group_id:$group_id$$,active:!0},async $cust_e$$=>{if($cust_e$$)return $callback$$(); $cust_e$$={ten_kh:$user$$.name,email:$user$$.email,id_app:$id_app$$,user_created:$user$$.email,user_updated:$user$$.email,kh_yn:!0,of_user:$user$$.email};try{await Customer.asyncCreateCustomer($cust_e$$)}catch($e$$){console.log("Auto create new customer with error:",$e$$.message)}$callback$$()})})()},()=>{$callback$jscomp$0$$()})},get_logo:$callback$$=>{$items$$.joinModel2(null,App,[{where:{id_app:"_id"},fields:[{logo:"logo"},{ten_cty:"name"}]}],function(){$callback$$(null,$items$$)})}},()=>{$next$$(null, $items$$)})}})).route()};module.exports=area;