HATEOAS-first backend framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
407 B

  1. import {DataSource} from '../src/backend/data-source';
  2. export const autoIncrement = async (dataSource: DataSource) => {
  3. const data = await dataSource.getMultiple() as Record<string, string>[];
  4. const highestId = data.reduce<number>(
  5. (highestId, d) => (Number(d.id) > highestId ? Number(d.id) : highestId),
  6. -Infinity
  7. );
  8. if (Number.isFinite(highestId)) {
  9. return (highestId + 1);
  10. }
  11. return 1;
  12. };