<commit_before>const Offer = require('./Offer');
const OfferMapper = require('./OfferMapper');
const UniqueChecker = require('./UniqueChecker');

class OffersAPI {
    /**
     * @param {import('./OfferRepository')} repository
     */
    constructor(repository) {
        this.repository = repository;
    }

    /**
     * @param {object} data
     *
     * @returns {Promise<OfferMapper.OfferDTO>}
     */
    async createOffer(data) {
        return this.repository.createTransaction(async (transaction) => {
            const options = {transacting: transaction};
            const uniqueChecker = new UniqueChecker(this.repository, transaction);

            const offer = await Offer.create(data, uniqueChecker);

            await this.repository.save(offer, options);

            return OfferMapper.toDTO(offer);<commit_msg>Added getOffer method to OffersAPI<commit_after>const Offer = require('./Offer');
const OfferMapper = require('./OfferMapper');
const UniqueChecker = require('./UniqueChecker');

class OffersAPI {
    /**
     * @param {import('./OfferRepository')} repository
     */
    constructor(repository) {
        this.repository = repository;
    }

    /**
     * @param {object} data
     * @param {string} data.id
     *
     * @returns {Promise<OfferMapper.OfferDTO>}
     */
    async getOffer(data) {
        return this.repository.createTransaction(async (transaction) => {
            const options = {transacting: transaction};

            const offer = await this.repository.getById(data.id, options);

            return OfferMapper.toDTO(offer);
        });
    }

    /**
     * @param {object} data
     *
     * @returns {Promise<OfferMapper.OfferDTO>}
     */
    async createOffer(data) {
        return this.repository.createTransaction(async (transaction) => {
            const options = {transacting: transaction};
            const uniqueChecker = new UniqueChecker(this.repository, transaction);

            const offer = await Offer.create(data, uniqueChecker);

            await this.repository.save(offer, options);

            return OfferMapper.toDTO(offer);
{'fraction_non_alphanumeric': 0.12470477090222012, 'fraction_numerical': 0.0, 'mean_word_length': 2.6517241379310343, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6933531', 'n_tokens_mistral': 578, 'n_tokens_neox': 563, 'n_words': 119}