UNPKG

flexbiz-server

Version:

Flexible Server

5 lines (4 loc) 1.43 kB
'use strict';const logSchema=new Schema({id_app:{type:String},id_func:{type:String},action:{type:String},description:{type:String},data:{},result:Schema.Types.Mixed,ip:{type:String},user_agent:{type:String},status:{type:Boolean,default:!0},date_created:{type:Date,default:Date.now},date_updated:{type:Date,default:Date.now},user_created:{type:String,default:""},user_updated:{type:String,default:""}}); (global.configs||{}).createIndexes&&(logSchema.index({id_app:1,id_func:1,action:1}),logSchema.index({"data.id":1}),logSchema.index({ip:1}),logSchema.index({user_created:1}),logSchema.index({date_created:1}),logSchema.index({id_func:"text",action:"text",user_created:"text",description:"text"}),logSchema.index({status:1}),logSchema.index({user_created:1,visible_to:1,visible_to_users:1}));const Log=mongoose.models.log||mongoose.model("log",logSchema); Log.create=async function($ip_log$$,$user_created$$,$user_agent$$,$req$$){const $l$$=new Log;$l$$.id_app=$ip_log$$.id_app;$l$$.id_func=$ip_log$$.id_func;$l$$.action=$ip_log$$.action;$l$$.description=$ip_log$$.description;$l$$.data=$ip_log$$.data;$l$$.user_agent=$user_agent$$;$l$$.user_created=$user_created$$;$req$$&&($req$$.headers||$req$$.connection)&&(($ip_log$$=$req$$.ip)||($req$$.headers?$req$$.headers["x-forwarded-for"]:""),$ip_log$$||($ip_log$$=$req$$.connection?$req$$.connection.remoteAddress: ""),$l$$.ip=$ip_log$$);return await $l$$.save()};module.exports=Log;