-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: main
Are you sure you want to change the base?
refactor(condo): DOMA-10610 remove moneyToWords and renderMoney #5688
Conversation
style: 'currency', | ||
currency: currencyCode, | ||
currencyDisplay: 'code', | ||
}).format(price * row.count).replace(/[A-Z]{3}/, '').trim() : '', |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this 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.
- 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.
- Why do you need this strange import? Especially globally defined...Also seems strange to me. Please explain, what exactly is happening
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 |
42ce141
to
352bdaa
Compare
style: 'currency', | ||
currency: currencyCode, | ||
currencyDisplay: 'code', | ||
}).format(price).replace(/[A-Z]{3}/, '').trim() : '', |
There was a problem hiding this comment.
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
price: !Number.isNaN(parseFloat(price)) ? new Intl.NumberFormat(locale, { | ||
style: 'currency', | ||
currency: currencyCode, | ||
currencyDisplay: 'code', | ||
}).format(price).replace(/[A-Z]{3}/, '').trim() : '', |
There was a problem hiding this comment.
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, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseFloat ^^
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 }), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
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 }), |
There was a problem hiding this comment.
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
352bdaa
to
4721fa6
Compare
3f417fb
to
8c18fba
Compare
Quality Gate passedIssues Measures |
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:
CompWorks
PaidWorks1
PaidWorks2