Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(condo): DOMA-10610 remove moneyToWords and renderMoney #5688

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tolmachev21
Copy link
Contributor

Small changes, which removed suppord currecy display for different locales. And add lib, which conversation number to words.

How now looks document, u can see here:

style: 'currency',
currency: currencyCode,
currencyDisplay: 'code',
}).format(price * row.count).replace(/[A-Z]{3}/, '').trim() : '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'' is bad default value to store...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is executed on the server because this task. An empty string is the value that will be inserted into the document (for us, an empty string is an empty space in the document that can be filled in manually). This value is not stored in the DB

Copy link
Member

@SavelevMatthew SavelevMatthew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit missing this PR.

  1. Is this code used on server or client?

If on client, why its in serverSchema
And if on server, why do you default values ''. Empty string is not good value to store in DB, consider null / undefined or throw an exception.

  1. Why do you need this strange import? Especially globally defined...Also seems strange to me. Please explain, what exactly is happening

@tolmachev21
Copy link
Contributor Author

  1. Is this code used on server or client?

If on client, why its in serverSchema And if on server, why do you default values ''. Empty string is not good value to store in DB, consider null / undefined or throw an exception.

  1. Is this code used on server or client? - An empty string is a value that will be inserted into the document. It is not saved in the database.
  1. Why do you need this strange import? Especially globally defined...Also seems strange to me. Please explain, what exactly is happening
  1. Why do you need this strange import? - This import is used here because the n2words library does not support СommunJS modules. Since we are currently on 16 node version, we also do not have support for ESM modules.

The solution to this situation is the dynamic import function - import(), which is supported since 12 version node and makes it possible to use ESM modules in files with CommunJS import

@tolmachev21 tolmachev21 force-pushed the refactor/condo/DOMA-10610/remove-support-different-currencies branch from 42ce141 to 352bdaa Compare January 14, 2025 08:01
style: 'currency',
currency: currencyCode,
currencyDisplay: 'code',
}).format(price).replace(/[A-Z]{3}/, '').trim() : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the regular expression to a constant with a clear name

Comment on lines 74 to 78
price: !Number.isNaN(parseFloat(price)) ? new Intl.NumberFormat(locale, {
style: 'currency',
currency: currencyCode,
currencyDisplay: 'code',
}).format(price).replace(/[A-Z]{3}/, '').trim() : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using parseFloat(price) again? You've already called this function before

currency: currencyCode,
currencyDisplay: 'code',
}).format(price).replace(/[A-Z]{3}/, '').trim() : '',
sum: !Number.isNaN(parseFloat(price * row.count)) ? new Intl.NumberFormat(locale, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseFloat ^^

Comment on lines 165 to 180
wholePartTotalSum: n2words(numberFormatByLocale
.formatToParts(totalSum)
.map(p => p.type === 'integer' ? p.value : '')
.join(''), { lang: locale }),
decimalPartTotalSum: n2words(numberFormatByLocale
.formatToParts(totalSum)
.map(p => p.type === 'fraction' ? p.value : '')
.join(''), { lang: locale, feminine: true }),
wholePartTotalVAT: n2words(numberFormatByLocale
.formatToParts(totalVAT)
.map(p => p.type === 'integer' ? p.value : '')
.join(''), { lang: locale }),
decimalPartTotalVAT: n2words(numberFormatByLocale
.formatToParts(totalVAT)
.map(p => p.type === 'fraction' ? p.value : '')
.join(''), { lang: locale, feminine: true }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the need to use the feminine parameter depends on the locale.

Right now it is not very important (since our document is only in Russian), but it is worth keeping in mind

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a if ru -> use feminine

const { TICKET_DOCUMENT_GENERATION_TASK_FORMAT } = require('@condo/domains/ticket/constants/ticketDocument')

const logger = getLogger('generateDocumentOfPaidWorksCompletion')

const n2wordsImport = import('n2words').then(module => module.default)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment describing why this syntax is used

.formatToParts(totalSum)
.map(p => p.type === 'fraction' ? p.value : '')
.join(''), { lang: locale, feminine: true }),
wholePartTotalVAT: n2words(numberFormatByLocale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming-wise its best to specify entity first and then specify the type

TotalWholePart
TotalDecimalPart

VATWholePart
VATDecimalPart

Comment on lines 165 to 180
wholePartTotalSum: n2words(numberFormatByLocale
.formatToParts(totalSum)
.map(p => p.type === 'integer' ? p.value : '')
.join(''), { lang: locale }),
decimalPartTotalSum: n2words(numberFormatByLocale
.formatToParts(totalSum)
.map(p => p.type === 'fraction' ? p.value : '')
.join(''), { lang: locale, feminine: true }),
wholePartTotalVAT: n2words(numberFormatByLocale
.formatToParts(totalVAT)
.map(p => p.type === 'integer' ? p.value : '')
.join(''), { lang: locale }),
decimalPartTotalVAT: n2words(numberFormatByLocale
.formatToParts(totalVAT)
.map(p => p.type === 'fraction' ? p.value : '')
.join(''), { lang: locale, feminine: true }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a if ru -> use feminine

@tolmachev21 tolmachev21 force-pushed the refactor/condo/DOMA-10610/remove-support-different-currencies branch from 352bdaa to 4721fa6 Compare January 17, 2025 13:23
@tolmachev21 tolmachev21 force-pushed the refactor/condo/DOMA-10610/remove-support-different-currencies branch from 3f417fb to 8c18fba Compare January 31, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants