flexbiz-server
Version:
Flexible Server
6 lines (5 loc) • 2.61 kB
JavaScript
'use strict';const model=global.getModel("note"),controller=require("../../controllers/controller"),redisCache=require("../../libs/redis-cache"),note=function($router$$){(new controller($router$$,model,"note",{sort:{date_created:-1},notNeedRight:!0,onCreated:async($customer_user$$,$obj$$,$next$$)=>{if($obj$$.content&&$obj$$.id_link&&($customer_user$$=await global.getModel("customer").findOne({id_app:$obj$$.id_app,_id:$obj$$.id_link}))){if(!$customer_user$$.ngay_tuong_tac_gan_nhat||(new Date($customer_user$$.ngay_tuong_tac_gan_nhat)).getTime()<
(new Date($obj$$.date_created)).getTime())$customer_user$$.ngay_tuong_tac_gan_nhat=$obj$$.date_created,"3"==$customer_user$$.trang_thai&&($customer_user$$.trang_thai="5");$customer_user$$.latest_note=$obj$$;await $customer_user$$.save();redisCache.set("customer",$customer_user$$.toObject(),function($e$$){if($e$$)return console.error($e$$);console.log("cache customer data")})}$next$$(null,$obj$$)},onUpdated:async($latest_note_user$$,$obj$$,$next$$)=>{if(($latest_note_user$$=await global.getModel("note").findOne({id_app:$obj$$.id_app},
{content:1,date_created:1,user_created:1}).sort({date_created:-1}).lean())&&$latest_note_user$$.content&&$latest_note_user$$.id_link){const $customer$$=await global.getModel("customer").findOne({id_app:$latest_note_user$$.id_app,_id:$latest_note_user$$.id_link});!$customer$$||$customer$$.latest_note&&$customer$$.latest_note._id==$latest_note_user$$._id.toString()||($customer$$.latest_note=$latest_note_user$$,await global.getModel("customer").updateOne({_id:$customer$$._id},{latest_note:$latest_note_user$$}),
redisCache.set("customer",$customer$$,function($e$$){console.log("cache customer data",$e$$)}))}$next$$(null,$obj$$)},onDeleted:async($latest_note$jscomp$1_user$$,$obj$$,$next$$)=>{if(($latest_note$jscomp$1_user$$=await global.getModel("note").findOne({id_app:$obj$$.id_app},{content:1,date_created:1,user_created:1}).sort({date_created:-1}).lean())&&$latest_note$jscomp$1_user$$.content&&$latest_note$jscomp$1_user$$.id_link){const $customer$$=await global.getModel("customer").findOne({id_app:$latest_note$jscomp$1_user$$.id_app,
_id:$latest_note$jscomp$1_user$$.id_link});!$customer$$||$customer$$.latest_note&&$customer$$.latest_note._id==$latest_note$jscomp$1_user$$._id.toString()||($customer$$.latest_note=$latest_note$jscomp$1_user$$,await global.getModel("customer").updateOne({_id:$customer$$._id},{latest_note:$latest_note$jscomp$1_user$$}),redisCache.set("customer",$customer$$,function($e$$){console.log("cache customer data",$e$$)}))}$next$$(null,$obj$$)}})).route()};module.exports=note;