Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

js-entity-repos/express

Repository files navigation

express

A concrete implementation of js-entity-repos for express.

Usage

  1. Install it with npm i @js-entity-repos/express.
  2. For each entity you will need to do the following.
    1. Create an Entity interface.
    2. Construct the facade.
    3. Use the facade.

Note that you'll probably want to use this with the Axios implementation of js-entity-repos.

Entity Interface

import Entity from '@js-entity-repos/core/dist/types/Entity';

export interface TodoEntity extends Entity {
  readonly description: string;
  readonly completed: boolean;
}

Construct the Facade

import factory from '@js-entity-repos/express/dist/factory';

const todosFacade = factory<TodoEntity>({
  // Optional property that modifies a filter for the service.
  constructFilter: (filter) => {
    return filter;
  },
  // Optional property.
  defaultPaginationLimit: 10,
  // Optional property to handle transactions.
  handleTransaction: async ({ req, res }, handler) => {
    // The transactionId allow items found in logs to be matched with responses to users.
    const transactionId = uuid();
    try {
      await handler({ transactionId });
    } catch (err) {
      console.error({ err, req, res, transactionId})
      res.status(500).send(transactionId);
    }
  };
  service,
});

About

A concrete implementation of js-entity-repos for express.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •