Skip to content

Instantly share code, notes, and snippets.

@mvcds
Last active August 16, 2021 20:16

Revisions

  1. mvcds revised this gist Aug 16, 2021. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions countryConfiguration.ts
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    //hard-coded data giving by business (probably) to "play safe"
    const defaultConfiguration = {
    alcohol: 21,
    softDrugs: Infinity,
    @@ -7,18 +6,20 @@ const defaultConfiguration = {
    adult: 21
    }

    // ts-magic, creates an interface-like type definition
    // it uses a value as template, infering the types correctly
    type Configuration = typeof defaultConfiguration

    export const async getCountryConfiguration = (
    country: Country
    ): Configuration => {
    //try-catch is on the service
    const record: Configuration = await service.getCountryConfiguration(country)

    return {
    ...defaultConfiguration,
    ...record
    try {
    const record: Configuration = await service.getCountryConfiguration(country)

    return {
    ...defaultConfiguration,
    ...record
    }
    } catch (e) {
    logger.error(`service.getCountryConfiguration for ${country}`, e)
    return defaultConfiguration
    }
    }
  2. mvcds created this gist Aug 16, 2021.
    24 changes: 24 additions & 0 deletions countryConfiguration.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    //hard-coded data giving by business (probably) to "play safe"
    const defaultConfiguration = {
    alcohol: 21,
    softDrugs: Infinity,
    hardDrugs: Infinity,
    drive: 21,
    adult: 21
    }

    // ts-magic, creates an interface-like type definition
    // it uses a value as template, infering the types correctly
    type Configuration = typeof defaultConfiguration

    export const async getCountryConfiguration = (
    country: Country
    ): Configuration => {
    //try-catch is on the service
    const record: Configuration = await service.getCountryConfiguration(country)

    return {
    ...defaultConfiguration,
    ...record
    }
    }