Coder Social home page Coder Social logo

pragma-brewery's Introduction

🍻 Pragma Brewery

To run the project

Nodejs must be installed. Desirably one of the latest versions - I have used v14.8.0. And then run from the command line:

npm install
npm run build
npm start

http://localhost:3000/

For testing

npm test

If you have any troubles running the project please let me know.

The challenge

Shane is responsible for driving the large transport truck, delivering goods from the brewery to a number of pubs across the city each week. Each beer has its own specific refrigeration needs while being transported:

  • Beer 1 (Pilsner): 4°C - 6°C
  • Beer 2 (IPA): 5°C - 6°C
  • Beer 3 (Lager): 4°C - 7°C
  • Beer 4 (Stout): 6°C - 8°C
  • Beer 5 (Wheat beer): 3°C - 5°C
  • Beer 6 (Pale Ale): 4°C - 6°C

The refrigerated truck is loaded with multiple containers with beer bottles inside, each container set to a specific temperature and each containing a thermometer sensor. While driving, Shane is alerted if any of the containers fall outside of the temperature range. Unfortunately, this is common due to factors such as opening the doors to unload, the heat of the Sydney summer or sometimes due to forgetting the container doors ajar. Develop a solution that allows Shane to be aware of the current temperature of each container and notifies him when the temperatures are outside the correct range.

Questions

  • What are the highlights of your logic/code writing style? Main piece is probably polling logic. For example if "Shane" would lost his connection for some time it would still try to fetch data over and over. But behaviour can be changed with keepPollingOnError param. (Which actually could be improved too by allowing setting number of times to retry instead of always "yes" or always "no". One more item for next question :) ). First catch here decides whether handle error and pass to next then or break the chain and reject promise. Which then will be handled in next catch. this.pollingBeerTempIds.length check serves here both as error avoider and polling breaker, stopTemperaturesPolling does exactly that - sets empty array for this.pollingBeerTempIds.

    private doTemperaturesPolling(): void {
        if (!this.pollingBeerTempIds.length) {
            return;
        }
    
        this.fetchTemperatures(this.pollingBeerTempIds)
            .catch((error) => {
                if (this.keepPollingOnError) {
                    console.log('Couldn\'t fetch temperatures - retrying');
                    return;
                }
                this.stopTemperaturesPolling();
                return Promise.reject(error);
            })
            .then(() => {
                setTimeout(
                    () => this.doTemperaturesPolling(),
                    this.beerPollingTime
                );
            })
            .catch((error) => {
                // error handling
                console.warn(error.message);
            });
    }

    Also there is good showcase for new typescript operator ??. Temperature could be null or number as declared in Beer model. null - when no data received yet and any number - when at least one response data recorded. Regular if or analogical operator would not display 0 temp. But ?? operator helps here.

    export interface IBeerPlain {
        id: string;
        minTemperature: number;
        maxTemperature: number;
        type: BeerType;
        temperature: null | number;
    }
    
    // ...................
    <td className="...">{temperature ?? 'n/a'}</td>;
    // ...................

    useAsync hook with AsyncResultContentWrapper also good example for handling any async request in react components.

    // ...................
    export const AsyncResultWrapper: React.FC<{ result: UseAsyncResult }> = ({
        result,
        children,
    }) => {
        switch (result.status) {
            case 'pending':
                return <>Loading ...</>;
            case 'fulfilled':
                return <>{children}</>;
            case 'rejected':
                return <>Failed to fetch: {result.reason}</>;
            default:
                return null;
        }
    };
    // ...................
    const beersFetchResult = useAsync(() => beersStore.fetchBeers());
    // ...................
    
    <AsyncResultWrapper result={beersFetchResult}>
        <BeersTable beers={beers} />
    </AsyncResultWrapper>;
  • What could you do better in your code next iteration? Having more time I would add tests for react components, improve tests overall. Also I could add routing and some navigation. Would improve error handling, especially need to show some error when temeprature requests failing. It will still show last temperature received so that "Shane" would at least know recently recorded data. But if it keeps failing for a long time "Shane" must know that to take some actions as temperature level may become too critical.

  • What were the questions you would ask and your own answers/assumptions? I think solution is pretty self-explanatory in that regard.

  • Any other notes you feel relevant for the evaluation of your solution DB - Just a JSON file with data BE - server/index.tsfile is a default code generated by express-generator FE - mobx with mobx-react-lite helps synchronize app state with react components efficiently. Tailwind.css provides various utility classes & helps style components quickly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.