Files
overleaf-cep/services/web/app/src/Features/Project/ProjectAuditLogHandler.js
Miguel Serrano d2845d9a38 Merge pull request #3074 from overleaf/msm-update-oerror-logger-v3
Update o-error to v3 and logger-sharelatex to v3

GitOrigin-RevId: 5e6386f65b7893949336aa4ff021212aebd98f4a
2020-08-12 02:06:58 +00:00

41 lines
915 B
JavaScript

const OError = require('@overleaf/o-error')
const { Project } = require('../../models/Project')
const MAX_AUDIT_LOG_ENTRIES = 200
module.exports = {
promises: {
addEntry
}
}
/**
* Add an audit log entry
*
* The entry should include at least the following fields:
*
* - operation: a string identifying the type of operation
* - userId: the user on behalf of whom the operation was performed
* - message: a string detailing what happened
*/
async function addEntry(projectId, operation, initiatorId, info = {}) {
const timestamp = new Date()
const entry = {
operation,
initiatorId,
timestamp,
info
}
const result = await Project.updateOne(
{ _id: projectId },
{
$push: {
auditLog: { $each: [entry], $slice: -MAX_AUDIT_LOG_ENTRIES }
}
}
).exec()
if (result.nModified === 0) {
throw new OError('project not found', { projectId })
}
}