UNPKG

flexbiz-server

Version:

Flexible Server

408 lines (404 loc) 22.1 kB
'use strict';const types=[{code:"String",ten:"String"},{code:"Number",ten:"Number"},{code:"Boolean",ten:"Boolean"},{code:"Date",ten:"Date"},{code:"DateTime",ten:"DateTime",type_data:"Date"},{code:"Time",ten:"Time",type_data:"Date"},{code:"Array",ten:"Array"},{code:"Mixed",ten:"Mixed",type_data:"Json"},{code:"File",ten:"Excel",type_data:"String"},{code:"Pdf",ten:"PDF",type_data:"String"},{code:"Image",ten:"Image",type_data:"String"}],form=function($fields$$,$id_app$$,$import_yn$$=0){let $server_url$$= configs.api_url||configs.domain;return`<table style='margin-top:10px'> <tr> <th>T\u00ean tr\u01b0\u1eddng</th> <th>Ki\u1ec3u d\u1eef li\u1ec7u</th> <th>B\u1eaft bu\u1ed9c nh\u1eadp</th> <th>S\u1ed1 k\u00fd t\u1ef1 t\u1ed1i \u0111a</th> <th>Di\u1ec5n gi\u1ea3i</th> <th>Ch\u1ecdn t\u1eeb danh s\u00e1ch</th> <th>C\u00e1c tr\u01b0\u1eddng chi ti\u1ebft</th> </tr> ${$fields$$.filter($f$$=>0<=["ten_vt","ten_kh","ten_kho"].indexOf($f$$.name)||"true"!=$f$$.not_input&&1!=$f$$.not_input&&0>($f$$.grid_configs||"").indexOf("readOnly")&&"Button"!=$f$$.type&&"Link"!=$f$$.type&&types.find($t$$=>$t$$.code==$f$$.type)).map($field$$=>{var $h_type$$=types.find($t$$=>$t$$.code==$field$$.type);let $ref_model$$=$field$$.ref_model||"";$ref_model$$&&0>$ref_model$$.indexOf("[")&&0>$ref_model$$.indexOf(",")&&($detail_url_model$$=`${$server_url$$}/api-docs-input/${$ref_model$$}`, $id_app$$&&($detail_url_model$$=$detail_url_model$$+"?id_app="+$id_app$$),$ref_model$$=`<a href='${$detail_url_model$$}'>${$ref_model$$}</a>`);var $detail_url_model$$=$field$$.form||"";"0"==$detail_url_model$$&&($detail_url_model$$="");$detail_url_model$$&&($description_url_fields$$=`${$server_url$$}/api-docs-fields/${$detail_url_model$$}?import_yn=${$import_yn$$?1:0}`,$id_app$$&&($description_url_fields$$=$description_url_fields$$+"&id_app="+$id_app$$),$detail_url_model$$=`<a href='${$description_url_fields$$}'>${$detail_url_model$$}</a>`); var $description_url_fields$$=$field$$.api_description||$field$$.header;0<=["ten_vt","ten_kh","ten_kho"].indexOf($field$$.name)&&($description_url_fields$$=`${$description_url_fields$$}. N\u1ebfu \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0y kh\u00f4ng t\u1ed3n t\u1ea1i trong danh m\u1ee5c th\u00ec h\u1ec7 th\u1ed1ng s\u1ebd s\u1eed d\u1ee5ng th\u00f4ng tin n\u00e0y \u0111\u1ec3 t\u1ea1o`);$h_type$$=`<tr> <td>${$field$$.name}</td> <td>${$h_type$$.type_data||$h_type$$.code}</td> <td>${1==$field$$.required||"true"==$field$$.required?"Yes":"No"}</td> <td>${"String"==$field$$.type?$field$$.maxlength||4E3:""}</td> <td> ${$description_url_fields$$} <div><i>${$field$$.help_text||""}</i></div> </td> <td>${$ref_model$$}</td> <td>${$detail_url_model$$}</td> </tr> `;1!=$import_yn$$||"ma_vt"!=$field$$.name||$fields$$.find($f$$=>"ten_vt"==$f$$.name)||($h_type$$=`${$h_type$$} <tr> <td>ten_vt</td> <td>String</td> <td>No</td> <td>256</td> <td> T\u00ean s\u1ea3n ph\u1ea9m/h\u00e0ng ho\u00e1/v\u1eadt t\u01b0. N\u1ebfu ch\u01b0a t\u1ed3n t\u1ea1i s\u1ea3n ph\u1ea9m n\u00e0y trong danh m\u1ee5c v\u1eadt t\u01b0 th\u00ec h\u1ec7 th\u1ed1ng s\u1ebd s\u1eed d\u1ee5ng th\u00f4ng tin n\u00e0y \u0111\u1ec3 t\u1ea1o. </td> <td></td> <td></td> </tr>`);1!=$import_yn$$||"ma_kh"!=$field$$.name||$fields$$.find($f$$=>"ten_kh"==$f$$.name)||($h_type$$=`${$h_type$$} <tr> <td>ten_kh</td> <td>String</td> <td>No</td> <td>256</td> <td> T\u00ean kh\u00e1ch h\u00e0ng. N\u1ebfu ch\u01b0a t\u1ed3n t\u1ea1i kh\u00e1ch h\u00e0ng n\u00e0y trong danh m\u1ee5c kh\u00e1ch h\u00e0ng th\u00ec h\u1ec7 th\u1ed1ng s\u1ebd s\u1eed d\u1ee5ng th\u00f4ng tin n\u00e0y \u0111\u1ec3 t\u1ea1o. </td> <td></td> <td></td> </tr>`);1!=$import_yn$$||"ma_kho"!=$field$$.name||$fields$$.find($f$$=>"ten_kho"==$f$$.name)||($h_type$$=`${$h_type$$} <tr> <td>ten_kho</td> <td>String</td> <td>No</td> <td>256</td> <td> T\u00ean kho. N\u1ebfu ch\u01b0a t\u1ed3n t\u1ea1i kho n\u00e0y trong danh m\u1ee5c kho th\u00ec h\u1ec7 th\u1ed1ng s\u1ebd s\u1eed d\u1ee5ng th\u00f4ng tin n\u00e0y \u0111\u1ec3 t\u1ea1o. </td> <td></td> <td></td> </tr>`);return $h_type$$}).join("")} </table>`},apiFields=async function($code$$,$id_app$$,$import_yn$$){return($code$$=await global.getModel("listinfo").findOne({code:$code$$}).lean())?`<!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid; } td, th { padding: 10px; } table { width: 100%; border-collapse: collapse; } </style> </head> <body style='padding:20px'> <h2>C\u00e1c field c\u1ee7a: ${$code$$.title}</h2> ${form($code$$.fields,$id_app$$,$import_yn$$)} </body> </html> `:"Kh\u00f4ng c\u00f3 t\u00e0i li\u1ec7u cho api n\u00e0y"},apiDocs=async function($code$$,$id_app$$){let $server_url$$=configs.api_url||configs.domain,$listinfo$$=await global.getModel("listinfo").findOne({code:$code$$}).lean();$listinfo$$||($listinfo$$=await global.getModel("listinfo").findOne({api_code:$code$$}).lean());if(!$listinfo$$)return"Kh\u00f4ng c\u00f3 t\u00e0i li\u1ec7u cho api n\u00e0y";$code$$=global.controllers[($listinfo$$.api_code||$listinfo$$.code).toUpperCase()];if(!$code$$)return"Kh\u00f4ng c\u00f3 t\u00e0i li\u1ec7u cho api n\u00e0y"; $code$$=$code$$.route_name;$id_app$$&&($code$$=$code$$.replace(":id_app",$id_app$$));let $doc$$=` <h3>Truy xu\u1ea5t d\u1eef li\u1ec7u</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api/search${$code$$}</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} </ul> </li> <li> Method: <span style='font-weight:450'>POST</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> <li>Content-Type: application/json</li> </ul> </li> <li> Body (row json): <ul> <li> page: <b>Number</b>. trang c\u1ea7n truy xu\u1ea5t. m\u1eb7c \u0111\u1ecbnh l\u00e0 trang 1 </li> <li> limit: <b>Number</b>. S\u1ed1 d\u00f2ng m\u1ed9t trang. M\u1eb7c \u0111\u1ecbnh 20 d\u00f2ng </li> <li> fields: <b>String</b>. C\u00e1c tr\u01b0\u1eddng c\u1ea7n l\u1ea5y d\u1eef li\u1ec7u, m\u1ed7i tr\u01b0\u1eddng c\u00e1ch nhau b\u1eb1ng d\u1ea5u ph\u1ea9y. M\u1eb7c \u0111\u1ecbnh s\u1ebd l\u1ea5y t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng </li> <li> count: <b>Number</b>. Ch\u1ec9 nh\u1eadn gi\u00e1 tr\u1ecb 1 ho\u1eb7c 0. N\u1ebfu count=1 th\u00ec s\u1ebd \u0111\u1ebfm c\u00e1c k\u1ebft qu\u1ea3 t\u00ecm \u0111\u01b0\u1ee3c. M\u1eb7c \u0111\u1ecbnh count=0 </li> <li> <div> <div> q: <b>Json</b>. \u0110i\u1ec1u ki\u1ec7n truy xu\u1ea5t d\u1eef li\u1ec7u. s\u1eed d\u1ee5ng mongodb query. Danh s\u00e1ch c\u00e1c tr\u01b0\u1eddng d\u1eef li\u1ec7u c\u00f3 th\u1ec3 query </div> <table style='margin-top:10px'> <tr> <th>T\u00ean tr\u01b0\u1eddng</th> <th>Ki\u1ec3u d\u1eef li\u1ec7u</th> <th>Di\u1ec5n gi\u1ea3i</th> </tr> ${$listinfo$$.fields.filter($f$$=>"true"!=$f$$.not_input&&1!=$f$$.not_input&&0>($f$$.grid_configs||"").indexOf("readOnly")&&"Button"!=$f$$.type&&"Link"!=$f$$.type&&types.find($t$$=>$t$$.code==$f$$.type)).map($field$$=>{let $type$$=types.find($t$$=>$t$$.code==$field$$.type);return`<tr> <td>${$field$$.name}</td> <td>${$type$$.type_data||$type$$.code}</td> <td>${$field$$.api_description||$field$$.header}</td> </tr> `}).join("")} </table> </div> </li> </ul> </li> </ul> `;$doc$$=`${$doc$$} <h3>L\u1ea5y d\u1eef li\u1ec7u c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}/:_id</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} <li>_id: id c\u1ee7a ph\u1ea7n t\u1eed c\u1ea7n l\u1ea5y d\u1eef li\u1ec7u</li> </ul> </li> <li> Method: <span style='font-weight:450'>GET</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> </ul> </li> </ul> `;1!=$listinfo$$.not_add&&$listinfo$$.fields&&0<$listinfo$$.fields.length&&($doc$$=`${$doc$$} <h3>Th\u00eam m\u1edbi</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} </ul> </li> <li> Method: <span style='font-weight:450'>POST</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> <li>Content-Type: application/json</li> </ul> </li> <li> <div> <div> Body (row json). Danh s\u00e1ch c\u00e1c tr\u01b0\u1eddng d\u1eef li\u1ec7u </div> ${form($listinfo$$.fields,$id_app$$)} </div> </li> </ul> `);1!=$listinfo$$.not_add&&$listinfo$$.fields&&0<$listinfo$$.fields.length&&($doc$$=`${$doc$$} <h3>Import Data</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}/import/json</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} </ul> </li> <li> Method: <span style='font-weight:450'>POST</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> <li>Content-Type: application/json</li> </ul> </li> <li> <div> <div> Body (row json): L\u00e0 m\u1ed9t m\u1ea3ng ch\u1ee9a danh s\u00e1ch c\u00e1c phi\u1ebfu c\u1ea7n import. M\u1ed7i phi\u1ebfu s\u1ebd c\u00f3 c\u00e1c tr\u01b0\u1eddng sau: </div> ${form($listinfo$$.fields,$id_app$$,1)} </div> </li> </ul> `);1!=$listinfo$$.not_update&&$listinfo$$.fields&&0<$listinfo$$.fields.length&&($doc$$=`${$doc$$} <h3>C\u1eadp nh\u1eadt d\u1eef li\u1ec7u</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}/:_id</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} <li>_id: id c\u1ee7a ph\u1ea7n t\u1eed c\u1ea7n c\u1eadp nh\u1eadt</li> </ul> </li> <li> Method: <span style='font-weight:450'>PUT</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> <li>Content-Type: application/json</li> </ul> </li> <li> <div> <div>Body (row json). C\u00f3 th\u1ec3 c\u1eadp nh\u1eadt 1 ho\u1eb7c t\u1ea5t c\u1ea3 c\u00e1c tr\u01b0\u1eddng d\u1eef li\u1ec7u. Danh s\u00e1ch c\u00e1c tr\u01b0\u1eddng d\u1eef li\u1ec7u</div> ${form($listinfo$$.fields,$id_app$$)} </div> </li> </ul> `);1!=$listinfo$$.not_delete&&$listinfo$$.fields&&0<$listinfo$$.fields.length&&($doc$$=`${$doc$$} <h3>Xo\u00e1 d\u1eef li\u1ec7u</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}/:_id</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} <li>_id: id c\u1ee7a ph\u1ea7n t\u1eed c\u1ea7n xo\u00e1</li> </ul> </li> <li> Method: <span style='font-weight:450'>DELETE</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> </ul> </li> </ul> `);1!=$listinfo$$.not_delete&&$listinfo$$.fields&&0<$listinfo$$.fields.length&&($doc$$=`${$doc$$} <h3>Xo\u00e1 d\u1eef li\u1ec7u theo \u0111i\u1ec1u ki\u1ec7n l\u1ecdc</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$code$$}/action/delete</span> <ul style='margin-top:5px'> ${0<=$code$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} </ul> </li> <li> Method: <span style='font-weight:450'>DELETE</span> </li> <li> Body (row json): <ul> <li> <div> <div> q: <b>Json</b>. \u0110i\u1ec1u ki\u1ec7n xo\u00e1 d\u1eef li\u1ec7u. s\u1eed d\u1ee5ng mongodb query. Danh s\u00e1ch c\u00e1c tr\u01b0\u1eddng d\u1eef li\u1ec7u c\u00f3 th\u1ec3 query </div> <table style='margin-top:10px'> <tr> <th>T\u00ean tr\u01b0\u1eddng</th> <th>Ki\u1ec3u d\u1eef li\u1ec7u</th> <th>Di\u1ec5n gi\u1ea3i</th> </tr> ${$listinfo$$.fields.filter($f$$=>"true"!=$f$$.not_input&&1!=$f$$.not_input&&0>($f$$.grid_configs||"").indexOf("readOnly")&&"Button"!=$f$$.type&&"Link"!=$f$$.type&&types.find($t$$=>$t$$.code==$f$$.type)).map($field$$=>{let $type$$=types.find($t$$=>$t$$.code==$field$$.type);return`<tr> <td>${$field$$.name}</td> <td>${$type$$.type_data||$type$$.code}</td> <td>${$field$$.api_description||$field$$.header}</td> </tr> `}).join("")} </table> </div> </li> </ul> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> </ul> </li> </ul> `);return`<!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid; } td, th { padding: 10px; } table { width: 100%; border-collapse: collapse; } </style> </head> <body style='padding:20px'> <h2>API: ${$listinfo$$.title}</h2> ${$doc$$} </body> </html> `},apiReport=async function($code$$,$doc$jscomp$1_id_app$$){let $server_url$$=configs.api_url||configs.domain;$code$$=await global.getModel("reportinfo").findOne({code:$code$$}).lean();if(!$code$$)return"Kh\u00f4ng c\u00f3 t\u00e0i li\u1ec7u cho api n\u00e0y";let $listinfo$$;$code$$.form_condition_info&&($listinfo$$=await global.getModel("listinfo").findOne({code:$code$$.form_condition_info}).lean());$listinfo$$=$listinfo$$||{};var $controller$jscomp$1_route_name$$=global.report_controllers[($code$$.api_code|| $code$$.code).toUpperCase()];if(!$controller$jscomp$1_route_name$$)return"Kh\u00f4ng c\u00f3 t\u00e0i li\u1ec7u cho api n\u00e0y";$controller$jscomp$1_route_name$$=`${$controller$jscomp$1_route_name$$.base_path+$controller$jscomp$1_route_name$$.module}`.replace(":id_app",$doc$jscomp$1_id_app$$);$doc$jscomp$1_id_app$$&&($controller$jscomp$1_route_name$$=$controller$jscomp$1_route_name$$.replace(":id_app",$doc$jscomp$1_id_app$$));$doc$jscomp$1_id_app$$=` <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${$server_url$$||""}/api${$controller$jscomp$1_route_name$$}</span> <ul style='margin-top:5px'> ${0<=$controller$jscomp$1_route_name$$.indexOf("id_app")?"<li>id_app: id c\u1ee7a c\u00f4ng ty \u0111ang thao t\u00e1c</li>":""} </ul> </li> <li> Method: <span style='font-weight:450'>POST</span> </li> <li> Headers: <ul> <li>access-token: <a href=${`${$server_url$$}/api-docs-auth`}>Token</a> \u0111\u1ec3 truy c\u1eadp h\u1ec7 th\u1ed1ng.</li> <li>Content-Type: application/json</li> </ul> </li> <li> Body (row json). \u0110i\u1ec1u ki\u1ec7n l\u1ecdc: ${form($listinfo$$.fields||[],$doc$jscomp$1_id_app$$)} </li> </ul> `;return`<!DOCTYPE html> <html lang="vi"> <head> <style> table, td, th { border: 1px solid; } td, th { padding: 10px; } table { width: 100%; border-collapse: collapse; } </style> </head> <body style='padding:20px'> <h2>API: ${$code$$.title}</h2> ${$doc$jscomp$1_id_app$$} </body> </html> `},apiAuth=function(){return`<!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid; } td, th { padding: 10px; } table { width: 100%; border-collapse: collapse; } </style> </head> <body style='padding:20px'> <h2>H\u1ec7 th\u1ed1ng</h2> <h3>\u0110\u0103ng nh\u1eadp</h3> <ul> <li> Url: <span style='font-weight:450;background-color:#ddd;padding:5px;border-radius:3px;border:1px solid silver;'>${configs.api_url||configs.domain||""}/auth/local</span> </li> <li> Method: <span style='font-weight:450'>GET</span> </li> <li> Headers: <ul> <li>Authorization: <span style='font-size:18px;color:gray;margin-left:10px'>Basic Auth</span></li> </ul> </li> </ul> </body> </html> `};module.exports={apiDocs,apiFields,apiReport,apiAuth};