Skip to content

Commit a822cc8

Browse files
pysnooLabclaude
andcommitted
fix: add deal_type and recent updated_at to demo deals
- Set deal_type ("tondeuse" 2/3, "entretien" 1/3) on all generated deals - Link product_id / service_id based on deal_type - "commande" stage deals get updated_at within last 60 days so the RevenueWidget shows non-zero monthly and yearly CA in demo mode Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b097ec7 commit a822cc8

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

  • src/components/atomic-crm/providers/fakerest/dataGenerator

src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { add } from "date-fns";
22
import { datatype, lorem, random } from "faker/locale/en_US";
33

4-
import {
5-
defaultDealCategories,
6-
defaultDealStages,
7-
} from "../../../root/defaultConfiguration";
4+
import { defaultDealStages } from "../../../root/defaultConfiguration";
85
import type { Deal } from "../../../types";
96
import type { Db } from "./types";
107
import { randomDate } from "./utils";
118

9+
const daysAgo = (n: number) => {
10+
const d = new Date();
11+
d.setDate(d.getDate() - n);
12+
return d;
13+
};
14+
1215
export const generateDeals = (db: Db): Deal[] => {
1316
const deals = Array.from(Array(50).keys()).map((id) => {
1417
const company = random.arrayElement(db.companies);
@@ -27,17 +30,36 @@ export const generateDeals = (db: Db): Deal[] => {
2730
.toISOString()
2831
.split("T")[0];
2932

33+
const dealType: "tondeuse" | "entretien" =
34+
id % 3 === 0 ? "entretien" : "tondeuse";
35+
const stage = random.arrayElement(defaultDealStages).value;
36+
37+
// "commande" deals get a recent updated_at (current month/year) so the
38+
// RevenueWidget has data to display in demo mode
39+
const updatedAt =
40+
stage === "commande"
41+
? randomDate(daysAgo(60), daysAgo(1)).toISOString()
42+
: randomDate(new Date(created_at)).toISOString();
43+
3044
return {
3145
id,
3246
name: lowercaseName[0].toUpperCase() + lowercaseName.slice(1),
3347
company_id: company.id,
3448
contact_ids: contacts.map((contact) => contact.id),
35-
category: random.arrayElement(defaultDealCategories).value,
36-
stage: random.arrayElement(defaultDealStages).value,
49+
stage,
50+
deal_type: dealType,
51+
product_id:
52+
dealType === "tondeuse" && db.products?.length
53+
? db.products[id % db.products.length].id
54+
: undefined,
55+
service_id:
56+
dealType === "entretien" && db.services?.length
57+
? db.services[id % db.services.length].id
58+
: undefined,
3759
description: lorem.paragraphs(datatype.number({ min: 1, max: 4 })),
3860
amount: datatype.number(1000) * 100,
3961
created_at,
40-
updated_at: randomDate(new Date(created_at)).toISOString(),
62+
updated_at: updatedAt,
4163
expected_closing_date,
4264
sales_id: company.sales_id!,
4365
index: 0,

0 commit comments

Comments
 (0)