fix: rename event module into analytics and clean (#482)

This commit is contained in:
Jérémy M
2023-06-30 11:24:05 +02:00
committed by GitHub
parent 7893d5dba5
commit cca36cf50f
16 changed files with 75 additions and 104 deletions

View File

@ -0,0 +1,42 @@
import { Injectable } from '@nestjs/common';
import { User, Workspace } from '@prisma/client';
import axios, { AxiosInstance } from 'axios';
import { CreateAnalyticsInput } from './dto/create-analytics.input';
import { anonymize } from 'src/utils/anonymize';
@Injectable()
export class AnalyticsService {
private readonly httpService: AxiosInstance;
constructor() {
this.httpService = axios.create({
baseURL: 'https://t.twenty.com/api/v1/s2s',
});
}
async create(
createEventInput: CreateAnalyticsInput,
user: User | undefined,
workspace: Workspace | undefined,
) {
if (process.env.IS_TELEMETRY_ENABLED === 'false') {
return;
}
const data = {
type: createEventInput.type,
data: {
userUUID: user ? anonymize(user.id) : undefined,
workspaceUUID: workspace ? anonymize(workspace.id) : undefined,
workspaceDomain: workspace ? workspace.domainName : undefined,
...createEventInput.data,
},
};
try {
await this.httpService.post('/event?noToken', data);
} catch {}
return { success: true };
}
}