Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert data-generator package to TypeScript #5174

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}))
);
};
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