2021-10-05 12:15:57 +03:00
|
|
|
/**
|
2021-10-08 13:27:17 +03:00
|
|
|
* @typedef {import('../domain/models/Offer')} Offer
|
2021-10-05 12:15:57 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} OfferDTO
|
|
|
|
* @prop {string} id
|
|
|
|
* @prop {string} name
|
|
|
|
* @prop {string} code
|
|
|
|
*
|
|
|
|
* @prop {string} display_title
|
|
|
|
* @prop {string} display_description
|
|
|
|
*
|
2022-08-09 12:09:27 +03:00
|
|
|
* @prop {'percent'|'fixed'|'trial'} type
|
2021-10-05 12:15:57 +03:00
|
|
|
*
|
|
|
|
* @prop {'month'|'year'} cadence
|
|
|
|
* @prop {number} amount
|
|
|
|
*
|
|
|
|
* @prop {boolean} currency_restriction
|
|
|
|
* @prop {string} currency
|
|
|
|
*
|
2022-08-09 12:09:27 +03:00
|
|
|
* @prop {'once'|'repeating'|'forever'|'trial'} duration
|
2021-10-08 13:10:36 +03:00
|
|
|
* @prop {null|number} duration_in_months
|
2021-10-07 18:10:44 +03:00
|
|
|
*
|
2021-10-12 18:11:52 +03:00
|
|
|
* @prop {'active'|'archived'} status
|
2021-10-18 18:29:30 +03:00
|
|
|
* @prop {number} redemption_count
|
2021-10-12 18:11:52 +03:00
|
|
|
*
|
2021-10-05 12:15:57 +03:00
|
|
|
* @prop {object} tier
|
|
|
|
* @prop {string} tier.id
|
|
|
|
* @prop {string} tier.name
|
|
|
|
*/
|
|
|
|
|
|
|
|
class OfferMapper {
|
|
|
|
/**
|
|
|
|
* @param {Offer} offer
|
|
|
|
* @returns {OfferDTO}
|
|
|
|
*/
|
|
|
|
static toDTO(offer) {
|
|
|
|
return {
|
|
|
|
id: offer.id,
|
2021-10-07 17:42:56 +03:00
|
|
|
name: offer.name.value,
|
|
|
|
code: offer.code.value,
|
|
|
|
display_title: offer.displayTitle.value,
|
|
|
|
display_description: offer.displayDescription.value,
|
|
|
|
type: offer.type.value,
|
|
|
|
cadence: offer.cadence.value,
|
|
|
|
amount: offer.amount.value,
|
2021-10-08 13:10:36 +03:00
|
|
|
duration: offer.duration.value.type,
|
|
|
|
duration_in_months: offer.duration.value.type === 'repeating' ? offer.duration.value.months : null,
|
2021-10-08 12:38:47 +03:00
|
|
|
currency_restriction: offer.type.value === 'fixed',
|
|
|
|
currency: offer.type.value === 'fixed' ? offer.currency.value : null,
|
2021-10-12 18:11:52 +03:00
|
|
|
status: offer.status.value,
|
2021-10-18 18:29:30 +03:00
|
|
|
redemption_count: offer.redemptionCount,
|
2021-10-05 12:15:57 +03:00
|
|
|
tier: {
|
|
|
|
id: offer.tier.id,
|
|
|
|
name: offer.tier.name
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OfferMapper;
|