mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
add revenue table and save
This commit is contained in:
parent
883fd2580f
commit
49b4948d0f
4 changed files with 105 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import kafka from '@/lib/kafka';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { saveEventData } from './saveEventData';
|
||||
import { saveRevenue } from './saveRevenue';
|
||||
|
||||
export interface SaveEventArgs {
|
||||
websiteId: string;
|
||||
|
|
@ -130,6 +131,20 @@ async function relationalQuery({
|
|||
eventData,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
const { revenue, currency } = eventData;
|
||||
|
||||
if (revenue > 0 && currency) {
|
||||
await saveRevenue({
|
||||
websiteId,
|
||||
sessionId,
|
||||
eventId: websiteEventId,
|
||||
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
|
||||
currency,
|
||||
revenue,
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
36
src/queries/sql/events/saveRevenue.ts
Normal file
36
src/queries/sql/events/saveRevenue.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { uuid } from '@/lib/crypto';
|
||||
import { PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export interface SaveRevenueArgs {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
eventName: string;
|
||||
currency: string;
|
||||
revenue: number;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export async function saveRevenue(data: SaveRevenueArgs) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(data),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(data: SaveRevenueArgs) {
|
||||
const { websiteId, sessionId, eventId, eventName, currency, revenue, createdAt } = data;
|
||||
|
||||
await prisma.client.revenue.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
websiteId,
|
||||
sessionId,
|
||||
eventId,
|
||||
eventName,
|
||||
currency,
|
||||
revenue,
|
||||
createdAt,
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue