huridocs/uwazi

View on GitHub
app/api/migrations/logger.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import model from 'api/activitylog/activitylogModel';

export const logTypes = {
  FIELD_PARSE_ERROR: 'fieldParseError',
};

function log(body) {
  const time = Date.now();
  const entry = {
    url: '',
    method: 'MIGRATE',
    params: '',
    query: '',
    body: JSON.stringify(body),
    user: null,
    username: 'System',
    time,
  };
  model.save(entry);
}

function logFieldParseError(
  { template, sharedId, title, propertyName, value },
  migrationName = 'unknown migration'
) {
  log({
    type: logTypes.FIELD_PARSE_ERROR,
    migrationName,
    template,
    sharedId,
    title,
    propertyName,
    value,
  });
}

export default {
  logFieldParseError,
};