diff --git a/lib/helpers/montaineRequest.js b/lib/helpers/montaineRequest.js index 453632c42..70a044443 100644 --- a/lib/helpers/montaineRequest.js +++ b/lib/helpers/montaineRequest.js @@ -102,7 +102,8 @@ exports.setApiHistory = (result, start, user, api) => ({ status: !!((result.request && result.request.type === 'success')), data: JSON.stringify(result, null, 2) || null, time: new Date() - start, - user: user.id || null, + user: user.id || api.user || null, + username: user.id ? `${user.firstName} ${user.lastName}` : String(user), api: api.id || null, }); diff --git a/modules/history/models/historys.model.mongoose.js b/modules/history/models/historys.model.mongoose.js index 61f569cdc..cdc2a1e29 100644 --- a/modules/history/models/historys.model.mongoose.js +++ b/modules/history/models/historys.model.mongoose.js @@ -12,6 +12,7 @@ const HistoryMongoose = new Schema({ status: Boolean, data: String, time: Number, + username: String, user: { type: Schema.ObjectId, ref: 'User', diff --git a/modules/history/models/historys.schema.js b/modules/history/models/historys.schema.js index 0970ee3f5..5edb0e873 100644 --- a/modules/history/models/historys.schema.js +++ b/modules/history/models/historys.schema.js @@ -10,7 +10,8 @@ const HistorySchema = Joi.object().keys({ status: Joi.boolean().default(false).required(), data: Joi.string().optional(), time: Joi.number().default(0).required(), - user: Joi.string().trim().default(''), + user: Joi.string().trim().default('').optional(), + username: Joi.string().trim().required(), api: Joi.string().trim().default(''), });