{"size": 599, "ext": "js", "max_stars_repo_path": "src/graphql/mutations/transactions/delete-transaction.js", "max_stars_repo_name": "perfectmak/udacity-devops-capstone", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/graphql/mutations/transactions/delete-transaction.js", "max_issues_repo_name": "perfectmak/udacity-devops-capstone", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/graphql/mutations/transactions/delete-transaction.js", "max_forks_repo_name": "perfectmak/udacity-devops-capstone", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.0434782609, "max_line_length": 87, "alphanum_fraction": 0.6343906511}
import { ValidationError } from 'apollo-server';

export const deleteTransaction = async (_parent, args, { services, logger, user }) => {
  const { id } = args;

  const transaction = await services.transactions.deleteTransactionById(id);
  if (!transaction) {
    throw new ValidationError(`Unknown transaction ${id} to be deleted.`);
  }

  logger.info({
    event: {
      type: 'delete',
      objectType: 'transaction',
      objectId: id,
      actorType: 'user',
      actorId: user.id,
    },
  }, `User [${user.id}(${user.email})] deleting transaction [${id}].`);

  return transaction;
};
