Skip to content

Commit

Permalink
Merge pull request #97 from panoratech/feat/custom-fields
Browse files Browse the repository at this point in the history
feat add
  • Loading branch information
naelob authored Nov 26, 2023
2 parents 910f0bf + e5c8d90 commit a002c9c
Show file tree
Hide file tree
Showing 32 changed files with 576 additions and 123 deletions.
271 changes: 244 additions & 27 deletions packages/api/prisma/schema.prisma

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions packages/api/src/@core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AuthService {

const res = await this.prisma.users.create({
data: {
id_user: '1', //todo
email: user.email,
password_hash: hashedPassword,
first_name: user.first_name,
Expand All @@ -42,7 +43,7 @@ export class AuthService {
async login(user: LoginCredentials): Promise<{ access_token: string }> {
try {
const foundUser = await this.prisma.users.findUnique({
where: { id_user: user.id_user },
where: { id_user: String(user.id_user) },
});
//TODO: if not founder
if (
Expand Down Expand Up @@ -104,8 +105,8 @@ export class AuthService {

//must be called only if user is logged in
async generateApiKey(
projectId: number,
userId: number,
projectId: number | string,
userId: number | string,
): Promise<{ access_token: string }> {
console.log("'ddddd");
const jwtPayload = {
Expand All @@ -121,8 +122,8 @@ export class AuthService {
}

async generateApiKeyForUser(
userId: number,
projectId: number,
userId: number | string,
projectId: number | string,
): Promise<{ api_key: string }> {
try {
//tmp create first these 2 :
Expand All @@ -141,7 +142,7 @@ export class AuthService {
//TODO: CHECK IF PROJECT_ID IS EXISTENT
//fetch user_id
const foundUser = await this.prisma.users.findUnique({
where: { id_user: userId },
where: { id_user: userId as string },
});
if (!foundUser) {
throw new UnauthorizedException(
Expand All @@ -158,9 +159,10 @@ export class AuthService {
console.log('hey2');
const new_api_key = await this.prisma.api_keys.create({
data: {
id_api_key: '1', //TODO
api_key_hash: hashed_token,
id_project: projectId,
id_user: userId,
id_project: projectId as string,
id_user: userId as string,
},
});
if (!new_api_key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class CrmConnectionsService {
}

async handleCRMTokensRefresh(
connectionId: bigint,
connectionId: string,
providerId: string,
refresh_token: string,
account_url?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class HubspotConnectionService {
async addLinkedUserAndProjectTest() {
// Adding a new organization
const newOrganization = {
id_organization: '1', //TODO
name: 'New Organization',
stripe_customer_id: 'stripe-customer-123',
};
Expand All @@ -30,19 +31,21 @@ export class HubspotConnectionService {

// Example data for a new project
const newProject = {
id_project: '1',
name: 'New Project',
id_organization: 1n, // bigint value
id_organization: '1',
};
const data1 = await this.prisma.projects.create({
data: newProject,
});
this.logger.log('Added new project ' + data1);

const newLinkedUser = {
id_linked_user: '1',
linked_user_origin_id: '12345',
alias: 'ACME COMPANY',
status: 'Active',
id_project: 1n, // bigint value
id_project: '1',
};
const data = await this.prisma.linked_users.create({
data: newLinkedUser,
Expand All @@ -58,7 +61,7 @@ export class HubspotConnectionService {
try {
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: BigInt(linkedUserId),
id_linked_user: linkedUserId,
},
});
if (isNotUnique)
Expand Down Expand Up @@ -92,6 +95,7 @@ export class HubspotConnectionService {
//TODO: encrypt the access token and refresh tokens
const db_res = await this.prisma.connections.create({
data: {
id_connection: '1', //TODO
provider_slug: 'hubspot',
token_type: 'oauth',
access_token: data.access_token,
Expand All @@ -101,10 +105,10 @@ export class HubspotConnectionService {
),
created_at: new Date(),
projects: {
connect: { id_project: BigInt(projectId) },
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: BigInt(linkedUserId) },
connect: { id_linked_user: linkedUserId },
},
//id of the end-customer defined in the company application, this is how requests could be made on behlaf of the user
// without it, we cant retrieve the right row in our db
Expand All @@ -116,7 +120,7 @@ export class HubspotConnectionService {
}
}

async handleHubspotTokenRefresh(connectionId: bigint, refresh_token: string) {
async handleHubspotTokenRefresh(connectionId: string, refresh_token: string) {
try {
const REDIRECT_URI = `${config.OAUTH_REDIRECT_BASE}/connections/oauth/callback`; //tocheck

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class PipedriveConnectionService {
try {
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: BigInt(linkedUserId),
id_linked_user: linkedUserId,
},
});
if (isNotUnique)
Expand Down Expand Up @@ -59,6 +59,7 @@ export class PipedriveConnectionService {
//TODO: encrypt the access token and refresh tokens
const db_res = await this.prisma.connections.create({

Check warning on line 60 in packages/api/src/@core/connections/crm/services/pipedrive/pipedrive.service.ts

View workflow job for this annotation

GitHub Actions / build-api (16.x)

'db_res' is assigned a value but never used
data: {
id_connection: '1', //TODO
provider_slug: 'pipedrive',
token_type: 'oauth',
access_token: data.access_token,
Expand All @@ -68,10 +69,10 @@ export class PipedriveConnectionService {
),
created_at: new Date(),
projects: {
connect: { id_project: BigInt(projectId) },
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: BigInt(linkedUserId) },
connect: { id_linked_user: linkedUserId },
},
},
});
Expand All @@ -81,7 +82,7 @@ export class PipedriveConnectionService {
}

async handlePipedriveTokenRefresh(
connectionId: bigint,
connectionId: string,
refresh_token: string,
) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ZendeskConnectionService {
try {
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: BigInt(linkedUserId),
id_linked_user: linkedUserId,
},
});
if (isNotUnique)
Expand Down Expand Up @@ -57,6 +57,7 @@ export class ZendeskConnectionService {
//TODO: encrypt the access token and refresh tokens
const db_res = await this.prisma.connections.create({
data: {
id_connection: '1', //TODO
provider_slug: 'zendesk',
token_type: 'oauth',
access_token: data.access_token,
Expand All @@ -66,18 +67,18 @@ export class ZendeskConnectionService {
),
created_at: new Date(),
projects: {
connect: { id_project: BigInt(projectId) },
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: BigInt(linkedUserId) },
connect: { id_linked_user: linkedUserId },
},
},
});
} catch (error) {
handleServiceError(error, this.logger, 'zendesk', Action.oauthCallback);
}
}
async handleZendeskTokenRefresh(connectionId: bigint, refresh_token: string) {
async handleZendeskTokenRefresh(connectionId: string, refresh_token: string) {
try {
const formData = new URLSearchParams({
grant_type: 'refresh_token',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ZohoConnectionService {
try {
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: BigInt(linkedUserId),
id_linked_user: linkedUserId,
},
});
if (isNotUnique)
Expand Down Expand Up @@ -64,6 +64,7 @@ export class ZohoConnectionService {
//TODO: encrypt the access token and refresh tokens
const db_res = await this.prisma.connections.create({
data: {
id_connection: '1', //TODO
provider_slug: 'zoho',
token_type: 'oauth',
access_token: data.access_token,
Expand All @@ -73,10 +74,10 @@ export class ZohoConnectionService {
),
created_at: new Date(),
projects: {
connect: { id_project: BigInt(projectId) },
connect: { id_project: projectId },
},
linked_users: {
connect: { id_linked_user: BigInt(linkedUserId) },
connect: { id_linked_user: linkedUserId },
},
account_url: domain,
},
Expand All @@ -86,7 +87,7 @@ export class ZohoConnectionService {
}
}
async handleZohoTokenRefresh(
connectionId: bigint,
connectionId: string,
refresh_token: string,
domain: string,
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FieldMappingController } from './field-mapping.controller';

describe('FieldMappingController', () => {
let controller: FieldMappingController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [FieldMappingController],
}).compile();

controller = module.get<FieldMappingController>(FieldMappingController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';

@Controller('field-mapping')
export class FieldMappingController {}
9 changes: 9 additions & 0 deletions packages/api/src/@core/field-mapping/field-mapping.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { FieldMappingService } from './field-mapping.service';
import { FieldMappingController } from './field-mapping.controller';

@Module({
providers: [FieldMappingService],
controllers: [FieldMappingController],
})
export class FieldMappingModule {}
18 changes: 18 additions & 0 deletions packages/api/src/@core/field-mapping/field-mapping.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FieldMappingService } from './field-mapping.service';

describe('FieldMappingService', () => {
let service: FieldMappingService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [FieldMappingService],
}).compile();

service = module.get<FieldMappingService>(FieldMappingService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
4 changes: 4 additions & 0 deletions packages/api/src/@core/field-mapping/field-mapping.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class FieldMappingService {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export class CreateLinkedUserDto {
linked_user_origin_id: string;
alias: string;
status?: string;
id_project: number;
id_project: string;
}
3 changes: 2 additions & 1 deletion packages/api/src/@core/linked-users/linked-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class LinkedUsersService {
const res = await this.prisma.linked_users.create({
data: {
...rest,
id_project: Number(id_project),
id_linked_user: '1', // TODO
id_project: id_project,
status: data.status || 'active',
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export class OrganisationsService {
}
async createOrganization(data: CreateOrganizationDto) {
const res = await this.prisma.organizations.create({
data: data,
data: {
...data,
id_organization: '1',
},
});
}
}
3 changes: 2 additions & 1 deletion packages/api/src/@core/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export class ProjectsService {
const res = await this.prisma.projects.create({
data: {
...rest,
id_organization: Number(id_organization),
id_project: '1', //TODO
id_organization: id_organization,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
import { LinkedUsersModule } from './@core/linked-users/linked-users.module';
import { OrganisationsModule } from './@core/organisations/organisations.module';
import { ProjectsModule } from './@core/projects/projects.module';
import { FieldMappingModule } from './@core/field-mapping/field-mapping.module';

@Module({
imports: [
FieldMappingModule,
LinkedUsersModule,
OrganisationsModule,
ProjectsModule,
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@nestjs/common';
import { LoggerService } from './@core/logger/logger.service';

@Injectable()
export class AppService {
Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/crm/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export type UnifiedCrm =
| UnifiedContactOutput
| UnifiedDealInput;

export class PassThroughRequestDto {
method: 'GET' | 'POST';
path: string;
data?: Record<string, any> | Record<string, any>[];
headers?: Record<string, string>;
}
export * from './../contact/services/freshsales/types';
export * from './../contact/services/zendesk/types';
export * from './../contact/services/hubspot/types';
Expand Down
Loading

0 comments on commit a002c9c

Please sign in to comment.