UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.56 kB
'use strict';const model=global.getModel("dmchietkhauhd"),newsfeed=global.getModel("newsfeed"),controller=require("../../controllers/controller"); module.exports=function($contr_router$$){$contr_router$$=new controller($contr_router$$,model,"dmchietkhauhd",{sort:{hieu_luc_tu:-1},unique:["ma_chietkhau"],onCreated:async($user$$,$obj$$,$next$$)=>{if($obj$$.newsfeed)try{await newsfeed.add("dmchietkhauhd",$obj$$),$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}else $next$$(null,$obj$$)},onUpdated:async($user$$,$obj$$,$next$$)=>{if($obj$$.newsfeed)try{await newsfeed.add("dmchietkhauhd",$obj$$),$next$$(null,$obj$$)}catch($e$$){$next$$($e$$.message)}else{try{await newsfeed.delete($obj$$._id)}catch($e$$){console.error($e$$)}$next$$(null, $obj$$)}},onDeleted:async($user$$,$obj$$,$next$$)=>{try{await newsfeed.delete($obj$$._id)}catch($e$$){console.error($e$$)}$next$$(null,$obj$$)}});$contr_router$$.route();$contr_router$$.createRoute("tinhchietkhau/:t_tien_nt",async($req$$,$next$$)=>{let $t_tien_nt$$=$req$$.params.t_tien_nt;try{$t_tien_nt$$=Number($t_tien_nt$$);if(isNaN($t_tien_nt$$)||!$t_tien_nt$$)return $next$$(`T\u1ed5ng ti\u1ec1n t\u00ednh chi\u1ebft kh\u1ea5u '${$t_tien_nt$$}' kh\u00f4ng h\u1ee3p l\u1ec7`);let $obj$$=$req$$.body|| {};$obj$$.details=$obj$$.details||[];let $ck$$=await model.tinhChietKhau($req$$.user.email,$req$$.user.current_id_app,$obj$$,$t_tien_nt$$);$next$$(null,$ck$$)}catch($e$$){return $next$$(`T\u1ed5ng ti\u1ec1n t\u00ednh chi\u1ebft kh\u1ea5u '${$t_tien_nt$$}' kh\u00f4ng h\u1ee3p l\u1ec7`)}},{method:"POST"})};