diff --git a/data-import.sh b/data-import.sh deleted file mode 100755 index 3bed428..0000000 --- a/data-import.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash - -slack datastore put ' -{ - "datastore": "countries", - "item": { - "id": "jp", - "label": "Japan" - } -} -' - -slack datastore put ' -{ - "datastore": "public_holidays", - "item": { - "country_id_and_year": "jp-2023", - "holidays": [ - "20230101", - "20230102", - "20230109", - "20230211", - "20230223", - "20230321", - "20230429", - "20230503", - "20230504", - "20230505", - "20230717", - "20230811", - "20230918", - "20230923", - "20231009", - "20231103", - "20231123" - ] - } -} -' -slack datastore put ' -{ - "datastore": "public_holidays", - "item": { - "country_id_and_year": "jp-2024", - "holidays": [ - "20240101", - "20240108", - "20240211", - "20240212", - "20240223", - "20240320", - "20240429", - "20240503", - "20240504", - "20240505", - "20240506", - "20240715", - "20240811", - "20240812", - "20240916", - "20240922", - "20241014", - "20241103", - "20241104", - "20241123" - ] - } -} -' diff --git a/functions/internals/constants.ts b/functions/internals/constants.ts index 4a87c90..015c582 100644 --- a/functions/internals/constants.ts +++ b/functions/internals/constants.ts @@ -105,7 +105,6 @@ export class Label { static RefreshButton = "Refresh"; static Language = "Language"; static Country = "Country"; - static Japan = "Japan"; static Work = "Work"; static BreakTime = "Break time"; static TimeOff = "Time off"; @@ -145,6 +144,10 @@ export class Label { static hour = "hour"; static minute = "minute"; + // Countries + static Japan = "Japan"; + static UnitedStates = "United States"; + // Report UI messages static HereIsTheReportYouRequested = "Here is the monthly report you requested!"; @@ -179,3 +182,8 @@ export class EntryType { static BreakTime = "break_time"; static TimeOff = "time_off"; } + +export class CountryCode { + static UnitedStates = "us"; + static Japan = "jp"; +} diff --git a/functions/internals/datastore.ts b/functions/internals/datastore.ts index a1d10d2..9befcbe 100644 --- a/functions/internals/datastore.ts +++ b/functions/internals/datastore.ts @@ -15,6 +15,7 @@ import Projects from "../../datastores/projects.ts"; import OrganizationPolicies from "../../datastores/organization_policies.ts"; import { todayYYYYMMDD } from "./datetime.ts"; +import { CountryCode, Label } from "./constants.ts"; export type LogLevel = "DEBUG" | "INFO"; @@ -250,6 +251,84 @@ export async function fetchAllCountries( return (await c.findAll()).items; } +const DefaultCountries: Attributes[] = [ + { id: CountryCode.Japan, label: Label.Japan }, + { id: CountryCode.UnitedStates, label: Label.UnitedStates }, +]; +interface setupCountriesAndHolidaysIfNecessaryArgs { + countries: SavedAttributes[]; + c: DataMapper; + ph: DataMapper; +} +export async function setupCountriesAndHolidaysIfNecessary( + { countries, c, ph }: setupCountriesAndHolidaysIfNecessaryArgs, +): Promise[]> { + if (countries.length !== DefaultCountries.length) { + for (const attributes of DefaultCountries) { + await c.save({ attributes }); + } + for (const attributes of DefaultPublicHolidays) { + await ph.save({ attributes }); + } + return (await c.findAll()).items; + } + return countries; +} + +// ----------------------------------------- +// PublicHolidays +// ----------------------------------------- + +const DefaultPublicHolidays: Attributes[] = [ + { + country_id_and_year: CountryCode.Japan + "-2023", + holidays: [ + "20230101", + "20230102", + "20230109", + "20230211", + "20230223", + "20230321", + "20230429", + "20230503", + "20230504", + "20230505", + "20230717", + "20230811", + "20230918", + "20230923", + "20231009", + "20231103", + "20231123", + ], + }, + { + country_id_and_year: CountryCode.Japan + "-2024", + holidays: [ + "20240101", + "20240108", + "20240211", + "20240212", + "20240223", + "20240320", + "20240429", + "20240503", + "20240504", + "20240505", + "20240506", + "20240715", + "20240811", + "20240812", + "20240916", + "20240922", + "20241014", + "20241103", + "20241104", + "20241123", + ], + }, +]; + // ----------------------------------------- // Projects // ----------------------------------------- diff --git a/functions/internals/i18n.ts b/functions/internals/i18n.ts index 8d74c5f..b1209cb 100644 --- a/functions/internals/i18n.ts +++ b/functions/internals/i18n.ts @@ -12,7 +12,6 @@ labels[Label.Save] = { "ja": "保存する" }; labels[Label.RefreshButton] = { "ja": "更新" }; labels[Label.Language] = { "ja": "言語" }; labels[Label.Country] = { "ja": "国" }; -labels[Label.Japan] = { "ja": "日本" }; labels[Label.Work] = { "ja": "勤務" }; labels[Label.BreakTime] = { "ja": "休憩" }; labels[Label.TimeOff] = { "ja": "休暇" }; @@ -51,6 +50,9 @@ labels[Label.minutes] = { "ja": "分" }; labels[Label.day] = { "ja": "日" }; labels[Label.hour] = { "ja": "時間" }; labels[Label.minute] = { "ja": "分" }; +// Countries +labels[Label.Japan] = { "ja": "日本" }; +labels[Label.Japan] = { "us": "アメリカ合衆国" }; // Report UI messages labels[Label.HereIsTheReportYouRequested] = { "ja": "こちらがご希望の月次レポートです!", diff --git a/functions/run_timesheet.ts b/functions/run_timesheet.ts index 15438fe..ac87d3b 100644 --- a/functions/run_timesheet.ts +++ b/functions/run_timesheet.ts @@ -65,6 +65,7 @@ import { saveTimeEntry, saveUserSettings, serializeTimeEntry, + setupCountriesAndHolidaysIfNecessary, TE, US, } from "./internals/datastore.ts"; @@ -117,11 +118,12 @@ export default SlackFunction( if (isDebugMode) { console.log(`### First time user (settings: ${p(settings)})`); } - view = toUserSettingsView({ - view, - countries: await fetchAllCountries({ ...components }), + let countries = await fetchAllCountries({ ...components }); + countries = await setupCountriesAndHolidaysIfNecessary({ ...components, + countries, }); + view = toUserSettingsView({ view, countries, ...components }); } else { const item = await fetchTimeEntry({ ...components }); const manualEntryPermitted = await isManualEntryPermitted({ @@ -701,8 +703,9 @@ export default SlackFunction( view: await toMainView({ view: newView(language), item: entryForTheDay, - manualEntryPermitted, ...components, + manualEntryPermitted, + language: saved.language, }), }; }