webadmin端增加商铺日志

This commit is contained in:
2026-07-07 12:12:12 +08:00
parent e25b208545
commit 6572799264
20 changed files with 919 additions and 5 deletions
@@ -10,6 +10,11 @@ export type TrackEventInput = {
extraJson?: Record<string, unknown>;
};
export type TrackStoreEventInput = TrackEventInput & {
storeAccountId?: bigint;
storeId: bigint;
};
@Injectable()
export class AnalyticsService {
constructor(private readonly prisma: PrismaService) {}
@@ -42,6 +47,16 @@ export class AnalyticsService {
void this.trackOne(userId, clientApp, event).catch(() => {});
}
async trackStoreOne(storeAccountId: bigint | undefined, clientApp: ClientApp | string, event: TrackStoreEventInput) {
await this.prisma.logStoreAnalytics.create({
data: this.toStoreRow(storeAccountId, clientApp, event),
});
}
trackStoreOneSafe(storeAccountId: bigint | undefined, clientApp: ClientApp | string, event: TrackStoreEventInput) {
void this.trackStoreOne(storeAccountId, clientApp, event).catch(() => {});
}
private toRow(userId: bigint, clientApp: ClientApp | string, event: TrackEventInput) {
return {
userId,
@@ -53,4 +68,20 @@ export class AnalyticsService {
extraJson: event.extraJson as never,
};
}
private toStoreRow(
storeAccountId: bigint | undefined,
clientApp: ClientApp | string,
event: TrackStoreEventInput,
) {
return {
storeAccountId,
storeId: event.storeId,
eventName: event.eventName,
clientApp: clientApp as ClientApp,
refType: event.refType,
refId: event.refId,
extraJson: event.extraJson as never,
};
}
}