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

YC: clarify prices centavo #1782

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ya-comiste-backoffice/pages/products/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ProductsCreatePage(): React.Node {
productCreate(
productMultilingualInput: {
images: $productImagesNames
price: { unitAmount: $productPriceUnitAmount }
price: { unitAmount: $productPriceUnitAmount, unitAmountCurrency: MXN }
translations: $translations
}
) {
Expand All @@ -44,7 +44,7 @@ export default function ProductsCreatePage(): React.Node {
uploadables: files,
variables: {
productImagesNames: ['TODO'], // TODO
productPriceUnitAmount: values.price,
productPriceUnitAmount: values.price * 100, // adjusting for centavo
translations: [
{
locale: 'en_US',
Expand Down
10 changes: 7 additions & 3 deletions src/ya-comiste-meta/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @generated SignedSource<<e24bcabb32aca564438c4fa32fb78afe>>
# @generated SignedSource<<99e5904c7c136df5c3dbc8bf820f740e>>

enum PriceSortDirection {
LOW_TO_HIGH
Expand Down Expand Up @@ -98,7 +98,11 @@ input ProductMultilingualInput {
}

input ProductPriceInput {
unitAmount: Int!
"""
The unit amount in centavo to be charged, represented as a whole integer.
Centavo equals ¹⁄₁₀₀ of the basic monetary unit.
""" unitAmount: Int!
"Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html)." unitAmountCurrency: SupportedCurrency!
Copy link
Member Author

Choose a reason for hiding this comment

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

What a strange formatting here. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

}

input ProductMultilingualInputTranslations {
Expand Down Expand Up @@ -152,7 +156,7 @@ type Product {

type ProductPrice {
"""
The unit amount in centavo to be charged, represented as a whole integer if possible.
The unit amount in centavo to be charged, represented as a whole integer.
Centavo equals ¹⁄₁₀₀ of the basic monetary unit.
"""
unitAmount: Int!
Expand Down
27 changes: 21 additions & 6 deletions src/ya-comiste-rust/server/src/commerce/dal/products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ mod tests {
use super::*;
use crate::arangodb::{cleanup_test_database, prepare_empty_test_database};
use crate::commerce::model::products::{
ProductMultilingualInputTranslations, ProductPriceInput,
ProductMultilingualInputTranslations, ProductPriceInput, SupportedCurrency,
};

#[ignore]
Expand All @@ -293,7 +293,10 @@ mod tests {
&pool,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN,
},
translations: vec![ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
name: Some("Product name in english".to_string()),
Expand Down Expand Up @@ -332,7 +335,10 @@ mod tests {
&pool,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN,
},
translations: vec![ProductMultilingualInputTranslations {
locale: SupportedLocale::EsMX,
name: Some("Product name in SPANISH".to_string()),
Expand Down Expand Up @@ -373,7 +379,10 @@ mod tests {
&pool,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN,
},
translations: vec![
ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
Expand Down Expand Up @@ -432,7 +441,10 @@ mod tests {
&pool,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN,
},
translations: vec![
ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
Expand Down Expand Up @@ -493,7 +505,10 @@ mod tests {
&pool,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN,
},
translations: vec![ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
name: Some("Product name in english".to_string()),
Expand Down
23 changes: 18 additions & 5 deletions src/ya-comiste-rust/server/src/commerce/model/products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub enum SupportedCurrency {

#[derive(juniper::GraphQLObject, Clone, Deserialize, Debug)]
struct ProductPrice {
/// The unit amount in centavo to be charged, represented as a whole integer if possible.
/// The unit amount in centavo to be charged, represented as a whole integer.
/// Centavo equals ¹⁄₁₀₀ of the basic monetary unit.
unit_amount: i32,

Expand Down Expand Up @@ -146,8 +146,12 @@ pub struct ProductMultilingualInput {

#[derive(juniper::GraphQLInputObject)]
pub struct ProductPriceInput {
// currency: String, // TODO: always "MXN" at this moment
/// The unit amount in centavo to be charged, represented as a whole integer.
/// Centavo equals ¹⁄₁₀₀ of the basic monetary unit.
pub(in crate::commerce) unit_amount: i32,

/// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html).
pub(in crate::commerce) unit_amount_currency: SupportedCurrency,
}

/// Takes care of the business logic and forwards the call lower to the DAL layer when everything
Expand Down Expand Up @@ -318,7 +322,10 @@ mod tests {
&context,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN
},
translations: vec![]
}
)
Expand All @@ -340,7 +347,10 @@ mod tests {
&context,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN
},
translations: vec![ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
name: None,
Expand All @@ -366,7 +376,10 @@ mod tests {
&context,
&ProductMultilingualInput {
images: vec![],
price: ProductPriceInput { unit_amount: -1 },
price: ProductPriceInput {
unit_amount: -1,
unit_amount_currency: SupportedCurrency::MXN
},
translations: vec![ProductMultilingualInputTranslations {
locale: SupportedLocale::EnUS,
name: Some("EN name".to_string()),
Expand Down