Skip to content

Commit

Permalink
Convert data-generator package to TypeScript
Browse files Browse the repository at this point in the history
Refs #4505
  • Loading branch information
fzaninotto committed Aug 20, 2020
1 parent 3a04918 commit 6b5da47
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 24 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Record } from 'ra-core';

import generateCustomers from './customers';
import generateCategories from './categories';
import generateProducts from './products';
Expand All @@ -6,13 +8,22 @@ import generateInvoices from './invoices';
import generateReviews from './reviews';
import finalize from './finalize';

export default (options = { serializeDate: true }) => {
const db = {};
export interface Db {
customers: Record[];
categories: Record[];
products: Record[];
commands: Record[];
invoices: Record[];
reviews: Record[];
}

export default (options = { serializeDate: true }): Db => {
const db = {} as Db;
db.customers = generateCustomers(db, options);
db.categories = generateCategories(db, options);
db.products = generateProducts(db, options);
db.categories = generateCategories();
db.products = generateProducts(db);
db.commands = generateCommands(db, options);
db.invoices = generateInvoices(db, options);
db.invoices = generateInvoices(db);
db.reviews = generateReviews(db, options);
finalize(db);

Expand Down
18 changes: 0 additions & 18 deletions examples/data-generator/src/invoices.js

This file was deleted.

21 changes: 21 additions & 0 deletions examples/data-generator/src/invoices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default db => {
let id = 0;

return (
db.commands
.filter(command => command.status !== 'delivered')
// @ts-ignore
.sort((a, b) => new Date(a.date) - new Date(b.date))
.map(command => ({
id: id++,
date: command.date,
command_id: command.id,
customer_id: command.customer_id,
total_ex_taxes: command.total_ex_taxes,
delivery_fees: command.delivery_fees,
tax_rate: command.tax_rate,
taxes: command.taxes,
total: command.total,
}))
);
};
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const weightedArrayElement = (values, weights) =>
export const weightedBoolean = likelyhood =>
faker.random.number(99) < likelyhood;

export const randomDate = (minDate, maxDate) => {
export const randomDate = (minDate?: Date, maxDate?: Date) => {
const minTs =
minDate instanceof Date
? minDate.getTime()
Expand Down

0 comments on commit 6b5da47

Please sign in to comment.