UNPKG

flexbiz-server

Version:

Flexible Server

6 lines (5 loc) 1.92 kB
const model=global.getModel("mailaccount"),controller=require("../../controllers/controller"),dns=require("dns"),invoiceFetcher=require("../../services/invoiceFetcher"); module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"mailaccount",{sort:{username:1},notNeedRight:!0,onFinding:function($user$$,$condition$$,$next$$){$next$$(null,$condition$$)},onCreating:function($user$$,$obj$$,$next$$){$obj$$.imap&&$obj$$.imap.host?dns.lookup($obj$$.imap.host,function($error$$){$error$$?$next$$("Kh\u00f4ng th\u1ec3 k\u1ebft n\u1ed1i v\u1edbi m\u00e1y ch\u1ee7 IMAP: "+$obj$$.imap.host):($obj$$.id_link||($obj$$.id_link=$user$$.email),$next$$(null, $obj$$))}):$next$$(null,$obj$$)},onUpdating:function($user$$,$data$$,$obj$$,$next$$){$data$$.imap&&$data$$.imap.host?dns.lookup($data$$.imap.host,function($error$$){$error$$?$next$$("Kh\u00f4ng th\u1ec3 k\u1ebft n\u1ed1i v\u1edbi m\u00e1y ch\u1ee7 IMAP: "+$data$$.imap.host+"\n"+$error$$.toString()):$next$$(null,$data$$,$obj$$)}):$next$$(null,$data$$,$obj$$)},onCreated:function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)},onUpdated:function($user$$,$obj$$,$next$$){$next$$(null,$obj$$)},onDeleted:function($user$$, $obj$$,$next$$){$next$$(null,$obj$$)}});$contr_router$$.route();$contr_router$$.createRoute("invoice-fetching/:id_config",async($req$$,$next$$)=>{try{let $config$$=await model.findOne({id_app:$req$$.current_id_app,_id:$req$$.params.id_config});if(!$config$$||!$config$$.imap?.host)return $next$$("T\u00e0i kho\u1ea3n imap kh\u00f4ng t\u1ed3n t\u1ea1i ho\u1eb7c kh\u00f4ng h\u1ee3p l\u1ec7");let $from_date$$=$req$$.query.from_date;$from_date$$&&=new Date($from_date$$);await invoiceFetcher.fetchInvoicesFromEmailConfig($config$$, $from_date$$)}catch($e$$){return $next$$($e$$.message||$e$$.errror||$e$$)}$next$$(null,{message:"Ch\u01b0\u01a1ng tr\u00ecnh \u0111\u00e3 th\u1ef1c hi\u1ec7n xong"})},{method:"GET"})};