feat: add RMB currency support

This commit is contained in:
Hayden 2022-12-01 16:40:11 -09:00
parent c08acba1ca
commit fe299a6add
No known key found for this signature in database
GPG key ID: 17CF79474E257545
4 changed files with 11 additions and 4 deletions

View file

@ -130,6 +130,7 @@ const (
CurrencySek Currency = "sek" CurrencySek Currency = "sek"
CurrencyDkk Currency = "dkk" CurrencyDkk Currency = "dkk"
CurrencyInr Currency = "inr" CurrencyInr Currency = "inr"
CurrencyRmb Currency = "rmb"
) )
func (c Currency) String() string { func (c Currency) String() string {
@ -139,7 +140,7 @@ func (c Currency) String() string {
// CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save. // CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save.
func CurrencyValidator(c Currency) error { func CurrencyValidator(c Currency) error {
switch c { switch c {
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr: case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb:
return nil return nil
default: default:
return fmt.Errorf("group: invalid enum value for currency field: %q", c) return fmt.Errorf("group: invalid enum value for currency field: %q", c)

View file

@ -127,7 +127,7 @@ var (
{Name: "created_at", Type: field.TypeTime}, {Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime},
{Name: "name", Type: field.TypeString, Size: 255}, {Name: "name", Type: field.TypeString, Size: 255},
{Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr"}, Default: "usd"}, {Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb"}, Default: "usd"},
} }
// GroupsTable holds the schema information for the "groups" table. // GroupsTable holds the schema information for the "groups" table.
GroupsTable = &schema.Table{ GroupsTable = &schema.Table{

View file

@ -27,7 +27,7 @@ func (Group) Fields() []ent.Field {
NotEmpty(), NotEmpty(),
field.Enum("currency"). field.Enum("currency").
Default("usd"). Default("usd").
Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr"), Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb"),
} }
} }

View file

@ -1,4 +1,4 @@
export type Codes = "USD" | "EUR" | "GBP" | "JPY" | "ZAR" | "AUD" | "NOK" | "SEK" | "DKK" | "INR"; export type Codes = "USD" | "EUR" | "GBP" | "JPY" | "ZAR" | "AUD" | "NOK" | "SEK" | "DKK" | "INR" | "RMB";
export type Currency = { export type Currency = {
code: Codes; code: Codes;
@ -20,6 +20,12 @@ export const currencies: Currency[] = [
symbol: "£", symbol: "£",
name: "British Pound", name: "British Pound",
}, },
{
code: "RMB",
local: "zh-CN",
symbol: "¥",
name: "Chinese Yuan",
},
{ {
code: "DKK", code: "DKK",
local: "da-DK", local: "da-DK",