-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore.ts
More file actions
102 lines (88 loc) · 2.67 KB
/
Copy pathstore.ts
File metadata and controls
102 lines (88 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* DEMO DATA: NOT REAL CUSTOMER DATA
*
* This is an in-memory store used so the API is runnable and testable without
* a database connection. Replace with a real persistence layer (e.g.
* PostgreSQL via freclean-data) before any production use. Every seeded
* record below is fictional and used only to demonstrate the API shape.
*/
import { v4 as uuid } from 'uuid';
export type Store = Record<string, Record<string, any>>;
export const RESOURCES = [
'users',
'customers',
'services',
'bookings',
'orders',
'products',
'inventory',
'staff',
'teams',
'entrepreneurs',
'payments',
'assets',
'reviews',
'notifications',
'reports',
'analytics',
'audit',
] as const;
export type ResourceName = (typeof RESOURCES)[number];
const store: Store = Object.fromEntries(RESOURCES.map((r) => [r, {}]));
function seed(resource: ResourceName, records: Array<Record<string, any>>) {
for (const record of records) {
const id = record.id ?? uuid();
store[resource][id] = { id, ...record, _demo: true };
}
}
// Minimal seed data so endpoints return something meaningful in demos.
// All records are marked _demo: true and should never be presented as real.
seed('services', [
{ name: 'Airbnb turnover cleaning', category: 'residential', status: 'active' },
{ name: 'Office cleaning', category: 'commercial', status: 'active' },
]);
seed('products', [
{
sku: 'DEMO-MSC-750',
name: 'FreClean Multi-Surface Cleaner 750ml',
category: 'cleaning',
lifecycleStatus: 'development',
retailPrice: null,
},
]);
seed('assets', [
{
assetName: 'Not provided',
symbol: 'N/A',
network: 'celo',
contractAddress: null,
decimals: null,
status: 'in_development',
paymentEnabled: false,
verificationDate: null,
notes: 'Placeholder row: no Celo asset has been verified for payments yet.',
},
]);
export const db = store;
export function list(resource: ResourceName) {
return Object.values(store[resource]);
}
export function get(resource: ResourceName, id: string) {
return store[resource][id] ?? null;
}
export function create(resource: ResourceName, data: Record<string, any>) {
const id = uuid();
const record = { id, ...data, createdAt: new Date().toISOString() };
store[resource][id] = record;
return record;
}
export function update(resource: ResourceName, id: string, data: Record<string, any>) {
if (!store[resource][id]) return null;
store[resource][id] = { ...store[resource][id], ...data, updatedAt: new Date().toISOString() };
return store[resource][id];
}
export function remove(resource: ResourceName, id: string) {
if (!store[resource][id]) return false;
delete store[resource][id];
return true;
}