diff --git a/api/aksjeeier_test.go b/api/aksjeeier_test.go index 795e8a9..6efb5a2 100644 --- a/api/aksjeeier_test.go +++ b/api/aksjeeier_test.go @@ -99,7 +99,7 @@ func TestShouldFailWithBadRequest2(t *testing.T) { func contains(captables []model.CapTable, id string) bool { for _, captable := range captables { for _, tokenHolder := range captable.TokenHolders { - if tokenHolder.Owner.Person.BirthDate == id[0:6] { + if tokenHolder.Owner.Person.BirthYear == id[4:6] { return true } if tokenHolder.Owner.Company.Orgnr == id { diff --git a/api/wallet.go b/api/wallet.go index 8da3b90..df34b5a 100644 --- a/api/wallet.go +++ b/api/wallet.go @@ -2,6 +2,7 @@ package api import ( "brok/navnetjener/model" + "brok/navnetjener/utils" "net/http" "github.com/gin-gonic/gin" @@ -41,7 +42,7 @@ func CreateWallet(context *gin.Context) { for _, wallet := range newWallet { if wallet.OwnerPersonFnr != "" { - wallet.OwnerPersonBirthDate = wallet.OwnerPersonFnr[:6] + wallet.OwnerPersonBirthYear = utils.FindBirthYear(wallet.OwnerPersonFnr) } savedWallet, err := wallet.Save() if err != nil { diff --git a/database/testdata.sql b/database/testdata.sql index 8041a21..fdc0bad 100644 --- a/database/testdata.sql +++ b/database/testdata.sql @@ -23,7 +23,7 @@ CREATE TABLE navnetjener.wallets ( "deleted_at" timestamptz, "owner_person_first_name" varchar(255), "owner_person_last_name" varchar(255), - "owner_person_birth_date" varchar(6), + "owner_person_birth_year" varchar(4), "owner_person_fnr" varchar(11), "owner_company_name" varchar(255), "owner_company_orgnr" varchar(9), @@ -67,17 +67,17 @@ CREATE INDEX idx_wallet_address ON navnetjener.wallets (wallet_address); 0xe0457130d824848853d398f1e358c31c415eaba4 0xeae18965741f8d221d488512468f5f334198c1f1 */ -INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_date, wallet_address) VALUES -('Elise', 'Berg', '310780472', '21058000000', '210580', '0x0c6598f08872e79c8195882e059acf8cee7eb468'), -('Lars', 'Myhre', '310780472', '14039000010', '140390', '0x2f6fa0b1adf996a1795dabc4b06e66b18ff867a5'), -('Nina', 'Pedersen', '310780472', '15097600020', '150976', '0x39d1786d6c23955830146b3658c6f028507c0fbe'), -('Johan', 'Aas', '310780472', '11066500030', '110665', '0x642c9271f215901ef01fde16f38b1257c97528a6'), -('Ingeborg', 'Knutsen', '310780472', '08097900040', '080979', '0x93ec94e79347c9a7b7b1c4685a24322bbbbfb26f'), -('Maria', 'Sunde', '310780472', '01028800050', '010288', '0x9865006528b2883bcc2a343a1b0c6168540d0847'), -('Knut', 'Hagen', '310780472', '09000000060', '090000', '0xaf4f666604609d92fb64b0ac2e3b5455026b6113'), -('Ellen', 'Eide', '310780472', '30037200070', '300372', '0xdc4bdc357910e51c22471a51be33fa840e850647'), -('Peter', 'Lang', '310780472', '27098900080', '270989', '0xe0457130d824848853d398f1e358c31c415eaba4'), -('Oscar', 'Nilsen', '310780472', '25029500090', '250295', '0xeae18965741f8d221d488512468f5f334198c1f1'); +INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_year, wallet_address) VALUES +('Elise', 'Berg', '310780472', '21058000000', '1980', '0x0c6598f08872e79c8195882e059acf8cee7eb468'), +('Lars', 'Myhre', '310780472', '14039000010', '1990', '0x2f6fa0b1adf996a1795dabc4b06e66b18ff867a5'), +('Nina', 'Pedersen', '310780472', '15097600020', '1976', '0x39d1786d6c23955830146b3658c6f028507c0fbe'), +('Johan', 'Aas', '310780472', '11066500030', '1965', '0x642c9271f215901ef01fde16f38b1257c97528a6'), +('Ingeborg', 'Knutsen', '310780472', '08097900040', '79', '0x93ec94e79347c9a7b7b1c4685a24322bbbbfb26f'), +('Maria', 'Sunde', '310780472', '01028800050', '1988', '0x9865006528b2883bcc2a343a1b0c6168540d0847'), +('Knut', 'Hagen', '310780472', '09000000060', '2000', '0xaf4f666604609d92fb64b0ac2e3b5455026b6113'), +('Ellen', 'Eide', '310780472', '30037200070', '1972', '0xdc4bdc357910e51c22471a51be33fa840e850647'), +('Peter', 'Lang', '310780472', '27098900080', '1989', '0xe0457130d824848853d398f1e358c31c415eaba4'), +('Oscar', 'Nilsen', '310780472', '25029500090', '1995', '0xeae18965741f8d221d488512468f5f334198c1f1'); /* FORSTÃ…ELSESFULL KOSTBAR TIGER AS @@ -86,9 +86,9 @@ INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name 0x1a5c49f5a6398b84a68746d5d1172cb38f71104e 0xd1db4aac0a1d1bc5e71c0d90da1aae4c4354a3e4 */ -INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_date, wallet_address) VALUES -('Elise', 'Berg', '310812277', '21058000000', '210580', '0x1a5c49f5a6398b84a68746d5d1172cb38f71104e'), -('Lars', 'Myhre', '310812277', '14039000010', '140390', '0xd1db4aac0a1d1bc5e71c0d90da1aae4c4354a3e4'); +INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_year, wallet_address) VALUES +('Elise', 'Berg', '310812277', '21058000000', '1980', '0x1a5c49f5a6398b84a68746d5d1172cb38f71104e'), +('Lars', 'Myhre', '310812277', '14039000010', '1990', '0xd1db4aac0a1d1bc5e71c0d90da1aae4c4354a3e4'); /* @@ -99,10 +99,10 @@ INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name 0x635e62f8e16087875bea87dd26d7845104ccb1e1 0xcf1f029280db9169c15841962f2282e57f04640f */ -INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_date, wallet_address) VALUES -('Emma', 'Olsen', '310767859', '22047500120', '220475', '0x4f4441a36e5870018a9481fd7dab9d326f71f1fe'), -('Hans', 'Iversen', '310767859', '08078100130', '080781', '0x635e62f8e16087875bea87dd26d7845104ccb1e1'), -('Sara', 'Johansen', '310767859', '12109000140', '121090', '0xcf1f029280db9169c15841962f2282e57f04640f'); +INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_year, wallet_address) VALUES +('Emma', 'Olsen', '310767859', '22047500120', '1975', '0x4f4441a36e5870018a9481fd7dab9d326f71f1fe'), +('Hans', 'Iversen', '310767859', '08078100130', '1981', '0x635e62f8e16087875bea87dd26d7845104ccb1e1'), +('Sara', 'Johansen', '310767859', '12100100140', '2001', '0xcf1f029280db9169c15841962f2282e57f04640f'); /* @@ -120,10 +120,10 @@ INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name 0xcc6aa2c0d12716916e19012e954a0630fa25e097 0x8be848ce9ebba1e304e6daa1d6b1b40f17e478fd */ -INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_date, wallet_address) VALUES -('Elise', 'Berg', '815493000', '21058000000', '210580', '0xbbb12c73703a8dc9ae2569e1c7ad699a5ac8c782'), -('Lars', 'Myhre', '815493000', '14039000001', '140390', '0xcc6aa2c0d12716916e19012e954a0630fa25e097'), -('Nina', 'Pedersen', '815493000', '15097600002', '150976', '0x8be848ce9ebba1e304e6daa1d6b1b40f17e478fd'); +INSERT INTO navnetjener.wallets (owner_person_first_name, owner_person_last_name, cap_table_orgnr, owner_person_fnr, owner_person_birth_year, wallet_address) VALUES +('Elise', 'Berg', '815493000', '21058000000', '1980', '0xbbb12c73703a8dc9ae2569e1c7ad699a5ac8c782'), +('Lars', 'Myhre', '815493000', '14039000001', '1990', '0xcc6aa2c0d12716916e19012e954a0630fa25e097'), +('Nina', 'Pedersen', '815493000', '15090200002', '2002', '0x8be848ce9ebba1e304e6daa1d6b1b40f17e478fd'); /* For aksjonerer som er foretak diff --git a/model/database.go b/model/database.go index 70dfc95..f486291 100644 --- a/model/database.go +++ b/model/database.go @@ -13,7 +13,7 @@ type Wallet struct { OwnerPersonFirstName string `gorm:"size:255;" json:"owner_person_first_name"` OwnerPersonLastName string `gorm:"size:255;" json:"owner_person_last_name"` OwnerPersonFnr string `gorm:"" json:"owner_person_fnr"` - OwnerPersonBirthDate string `gorm:"" json:"owner_person_birth_date"` + OwnerPersonBirthYear string `gorm:"" json:"owner_person_birth_year"` OwnerCompanyName string `gorm:"size:255;" json:"owner_company_name"` OwnerCompanyOrgnr string `gorm:"size:9;" json:"owner_company_orgnr"` @@ -30,7 +30,7 @@ type Owner struct { type Person struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` - BirthDate string `json:"birth_date"` + BirthYear string `json:"birth_year"` } type Company struct { @@ -176,7 +176,7 @@ func parseWalletToPublicInfo(wallet Wallet) PublicWalletInfo { Person: Person{ FirstName: wallet.OwnerPersonFirstName, LastName: wallet.OwnerPersonLastName, - BirthDate: wallet.OwnerPersonBirthDate, + BirthYear: wallet.OwnerPersonBirthYear, }, Company: Company{ Name: wallet.OwnerCompanyName, diff --git a/model/database_test.go b/model/database_test.go index d70248c..2f5ab0a 100644 --- a/model/database_test.go +++ b/model/database_test.go @@ -11,7 +11,7 @@ func TestParseWalletToPublicInfo(t *testing.T) { OwnerPersonFirstName: "firstName", OwnerPersonLastName: "lastName", OwnerPersonFnr: "12345678901", - OwnerPersonBirthDate: "123456", + OwnerPersonBirthYear: "56", OwnerCompanyName: "", OwnerCompanyOrgnr: "", } @@ -20,7 +20,7 @@ func TestParseWalletToPublicInfo(t *testing.T) { assert.Equal(t, publicPersonWallet.Owner.Person.FirstName, personWallet.OwnerPersonFirstName) assert.Equal(t, publicPersonWallet.Owner.Person.LastName, personWallet.OwnerPersonLastName) - assert.Equal(t, publicPersonWallet.Owner.Person.BirthDate, personWallet.OwnerPersonBirthDate) + assert.Equal(t, publicPersonWallet.Owner.Person.BirthYear, personWallet.OwnerPersonBirthYear) assert.Equal(t, publicPersonWallet.Owner.Company.Name, personWallet.OwnerCompanyName) assert.Equal(t, publicPersonWallet.Owner.Company.Orgnr, personWallet.CapTableOrgnr) } diff --git a/model/sanitazion.go b/model/sanitazion.go index 80e14d1..7e61e10 100644 --- a/model/sanitazion.go +++ b/model/sanitazion.go @@ -15,7 +15,7 @@ func SanitizeWallet(w *Wallet) { w.OwnerPersonFirstName = SanitizeString(w.OwnerPersonFirstName) w.OwnerPersonLastName = SanitizeString(w.OwnerPersonLastName) w.OwnerPersonFnr = SanitizeString(w.OwnerPersonFnr) - w.OwnerPersonBirthDate = SanitizeString(w.OwnerPersonBirthDate) + w.OwnerPersonBirthYear = SanitizeString(w.OwnerPersonBirthYear) w.OwnerCompanyName = SanitizeString(w.OwnerCompanyName) w.OwnerCompanyOrgnr = SanitizeString(w.OwnerCompanyOrgnr) w.WalletAddress = SanitizeString(w.WalletAddress) diff --git a/utils/birthyear.go b/utils/birthyear.go new file mode 100644 index 0000000..ed549f5 --- /dev/null +++ b/utils/birthyear.go @@ -0,0 +1,20 @@ +package utils + +import ( + "fmt" + "strconv" + "time" +) + +func FindBirthYear(fnr string) string { + thisYear := time.Now().Year() + birthYear, _ := strconv.Atoi("20" + fnr[4:6]) + + // check if person is born in the 1900 or 2000 + // limit: persons over 100 years old wil be 1 year old with this function + if birthYear >= thisYear { + return "19" + fnr[4:6] + } else { + return fmt.Sprint(birthYear) + } +} diff --git a/utils/birthyear_test.go b/utils/birthyear_test.go new file mode 100644 index 0000000..e845b8e --- /dev/null +++ b/utils/birthyear_test.go @@ -0,0 +1,26 @@ +package utils_test + +import ( + "brok/navnetjener/utils" + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test50YearOldPerson(t *testing.T) { + birthYear := utils.FindBirthYear("11117300000") + + assert.Equal(t, "1973", birthYear) +} + +func Test10YearOldPerson(t *testing.T) { + birthYear := utils.FindBirthYear("11111300000") + + assert.Equal(t, "2013", birthYear) +} + +func Test120YearOldPerson(t *testing.T) { + birthYear := utils.FindBirthYear("11110300000") + + assert.Equal(t, "2003", birthYear) +}