fix: rename event module into analytics and clean (#482)
This commit is contained in:
@ -31,7 +31,6 @@
|
||||
"@casl/ability": "^6.5.0",
|
||||
"@casl/prisma": "^1.4.0",
|
||||
"@nestjs/apollo": "^11.0.5",
|
||||
"@nestjs/axios": "^3.0.0",
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/config": "^2.3.2",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
|
||||
@ -10,7 +10,6 @@ import { GraphQLError } from 'graphql';
|
||||
import { PrismaModule } from './database/prisma.module';
|
||||
import { HealthModule } from './health/health.module';
|
||||
import { AbilityModule } from './ability/ability.module';
|
||||
import { EventModule } from './core/analytics/event.module';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
@Module({
|
||||
@ -34,7 +33,6 @@ import GraphQLJSON from 'graphql-type-json';
|
||||
HealthModule,
|
||||
AbilityModule,
|
||||
CoreModule,
|
||||
EventModule,
|
||||
],
|
||||
providers: [AppService],
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ObjectType, Field } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
export class Event {
|
||||
export class Analytics {
|
||||
@Field(() => Boolean, {
|
||||
description: 'Boolean that confirms query was dispatched',
|
||||
})
|
||||
8
server/src/core/analytics/analytics.module.ts
Normal file
8
server/src/core/analytics/analytics.module.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AnalyticsService } from './analytics.service';
|
||||
import { AnalyticsResolver } from './analytics.resolver';
|
||||
|
||||
@Module({
|
||||
providers: [AnalyticsResolver, AnalyticsService],
|
||||
})
|
||||
export class AnalyticsModule {}
|
||||
19
server/src/core/analytics/analytics.resolver.spec.ts
Normal file
19
server/src/core/analytics/analytics.resolver.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AnalyticsResolver } from './analytics.resolver';
|
||||
import { AnalyticsService } from './analytics.service';
|
||||
|
||||
describe('AnalyticsResolver', () => {
|
||||
let resolver: AnalyticsResolver;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AnalyticsResolver, AnalyticsService],
|
||||
}).compile();
|
||||
|
||||
resolver = module.get<AnalyticsResolver>(AnalyticsResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,7 +1,7 @@
|
||||
import { Resolver, Mutation, Args } from '@nestjs/graphql';
|
||||
import { EventService } from './event.service';
|
||||
import { Event } from './event.entity';
|
||||
import { CreateEventInput } from './dto/create-event.input';
|
||||
import { AnalyticsService } from './analytics.service';
|
||||
import { Analytics } from './analytics.entity';
|
||||
import { CreateAnalyticsInput } from './dto/create-analytics.input';
|
||||
import { OptionalJwtAuthGuard } from 'src/guards/optional-jwt.auth.guard';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { AuthWorkspace } from 'src/decorators/auth-workspace.decorator';
|
||||
@ -9,16 +9,16 @@ import { User, Workspace } from '@prisma/client';
|
||||
import { AuthUser } from 'src/decorators/auth-user.decorator';
|
||||
|
||||
@UseGuards(OptionalJwtAuthGuard)
|
||||
@Resolver(() => Event)
|
||||
export class EventResolver {
|
||||
constructor(private readonly eventService: EventService) {}
|
||||
@Resolver(() => Analytics)
|
||||
export class AnalyticsResolver {
|
||||
constructor(private readonly analyticsService: AnalyticsService) {}
|
||||
|
||||
@Mutation(() => Event)
|
||||
@Mutation(() => Analytics)
|
||||
createEvent(
|
||||
@Args() createEventInput: CreateEventInput,
|
||||
@Args() createEventInput: CreateAnalyticsInput,
|
||||
@AuthWorkspace() workspace: Workspace | undefined,
|
||||
@AuthUser() user: User | undefined,
|
||||
) {
|
||||
return this.eventService.create(createEventInput, user, workspace);
|
||||
return this.analyticsService.create(createEventInput, user, workspace);
|
||||
}
|
||||
}
|
||||
18
server/src/core/analytics/analytics.service.spec.ts
Normal file
18
server/src/core/analytics/analytics.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AnalyticsService } from './analytics.service';
|
||||
|
||||
describe('AnalyticsService', () => {
|
||||
let service: AnalyticsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AnalyticsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AnalyticsService>(AnalyticsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,15 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateEventInput } from './dto/create-event.input';
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { anonymize } from 'src/utils/anonymize';
|
||||
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 EventService {
|
||||
constructor(private readonly httpService: HttpService) {}
|
||||
export class AnalyticsService {
|
||||
private readonly httpService: AxiosInstance;
|
||||
|
||||
create(
|
||||
createEventInput: CreateEventInput,
|
||||
constructor() {
|
||||
this.httpService = axios.create({
|
||||
baseURL: 'https://t.twenty.com/api/v1/s2s',
|
||||
});
|
||||
}
|
||||
|
||||
async create(
|
||||
createEventInput: CreateAnalyticsInput,
|
||||
user: User | undefined,
|
||||
workspace: Workspace | undefined,
|
||||
) {
|
||||
@ -27,11 +33,9 @@ export class EventService {
|
||||
},
|
||||
};
|
||||
|
||||
this.httpService
|
||||
.post('https://t.twenty.com/api/v1/s2s/event?noToken', data)
|
||||
.subscribe({
|
||||
error: () => null,
|
||||
});
|
||||
try {
|
||||
await this.httpService.post('/event?noToken', data);
|
||||
} catch {}
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
@ -3,7 +3,7 @@ import GraphQLJSON from 'graphql-type-json';
|
||||
import { IsNotEmpty, IsString, IsObject } from 'class-validator';
|
||||
|
||||
@ArgsType()
|
||||
export class CreateEventInput {
|
||||
export class CreateAnalyticsInput {
|
||||
@Field({ description: 'Type of the event' })
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ -1,10 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EventService } from './event.service';
|
||||
import { EventResolver } from './event.resolver';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
@Module({
|
||||
providers: [EventResolver, EventService],
|
||||
imports: [HttpModule],
|
||||
})
|
||||
export class EventModule {}
|
||||
@ -1,21 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EventResolver } from './event.resolver';
|
||||
import { EventService } from './event.service';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
describe('EventResolver', () => {
|
||||
let resolver: EventResolver;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [HttpModule],
|
||||
providers: [EventResolver, EventService],
|
||||
}).compile();
|
||||
|
||||
resolver = module.get<EventResolver>(EventResolver);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(resolver).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,20 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { EventService } from './event.service';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
describe('EventService', () => {
|
||||
let service: EventService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [HttpModule],
|
||||
providers: [EventService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<EventService>(EventService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -6,7 +6,7 @@ import { PersonModule } from './person/person.module';
|
||||
import { PipelineModule } from './pipeline/pipeline.module';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { WorkspaceModule } from './workspace/workspace.module';
|
||||
import { EventModule } from './analytics/event.module';
|
||||
import { AnalyticsModule } from './analytics/analytics.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -17,7 +17,7 @@ import { EventModule } from './analytics/event.module';
|
||||
PersonModule,
|
||||
PipelineModule,
|
||||
WorkspaceModule,
|
||||
EventModule,
|
||||
AnalyticsModule,
|
||||
],
|
||||
exports: [
|
||||
AuthModule,
|
||||
@ -27,7 +27,7 @@ import { EventModule } from './analytics/event.module';
|
||||
PersonModule,
|
||||
PipelineModule,
|
||||
WorkspaceModule,
|
||||
EventModule,
|
||||
AnalyticsModule,
|
||||
],
|
||||
})
|
||||
export class CoreModule {}
|
||||
|
||||
@ -1055,11 +1055,6 @@
|
||||
lodash.omit "4.5.0"
|
||||
tslib "2.5.2"
|
||||
|
||||
"@nestjs/axios@^3.0.0":
|
||||
version "3.0.0"
|
||||
resolved "https://registry.npmjs.org/@nestjs/axios/-/axios-3.0.0.tgz"
|
||||
integrity sha512-ULdH03jDWkS5dy9X69XbUVbhC+0pVnrRcj7bIK/ytTZ76w7CgvTZDJqsIyisg3kNOiljRW/4NIjSf3j6YGvl+g==
|
||||
|
||||
"@nestjs/cli@^9.0.0":
|
||||
version "9.5.0"
|
||||
resolved "https://registry.npmjs.org/@nestjs/cli/-/cli-9.5.0.tgz"
|
||||
|
||||
Reference in New Issue
Block a user