Skip to content

Commit

Permalink
Merge pull request #610 from panoratech/596-feat-add-id_connection-an…
Browse files Browse the repository at this point in the history
…d-id_project-to-events-object

596 feat add id connection and id project to events object
  • Loading branch information
naelob authored Aug 5, 2024
2 parents 49197ae + d0b2e83 commit 20caea3
Show file tree
Hide file tree
Showing 259 changed files with 5,137 additions and 1,540 deletions.
2 changes: 1 addition & 1 deletion apps/magic-link/src/hooks/queries/useUniqueMagicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const useUniqueMagicLink = (id: string | null) => {
if (!id) {
throw new Error('Magic Link ID is not available');
}
const response = await fetch(`${config.API_URL}/magic_links/single?id=${id.trim()}`);
const response = await fetch(`${config.API_URL}/magic_links/${id.trim()}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
Expand Down
19 changes: 13 additions & 6 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ datasource db {
model users {
id_user String @id(map: "pk_users") @db.Uuid
identification_strategy String
email String?
email String? @unique(map: "unique_email")
password_hash String?
first_name String
last_name String
id_stytch String? @unique(map: "force_stytch_id_unique")
created_at DateTime @default(now()) @db.Timestamp(6)
modified_at DateTime @default(now()) @db.Timestamp(6)
reset_token String?
reset_token_expires_at DateTime? @db.Timestamptz(6)
api_keys api_keys[]
projects projects[]
}
Expand Down Expand Up @@ -378,13 +380,15 @@ model entity {
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model events {
id_event String @id(map: "pk_jobs") @db.Uuid
status String
id_connection String @db.Uuid
id_project String @db.Uuid
type String
status String
direction String
timestamp DateTime @default(now()) @db.Timestamp(6)
method String
url String
provider String
timestamp DateTime @default(now()) @db.Timestamp(6)
id_linked_user String @db.Uuid
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_12")
jobs_status_history jobs_status_history[]
Expand Down Expand Up @@ -1661,8 +1665,9 @@ model ecom_fulfilments {
remote_id String?
id_ecom_order String? @db.Uuid
id_connection String @db.Uuid
modifed_at DateTime @db.Timestamptz(6)
modified_at DateTime @db.Timestamptz(6)
created_at DateTime @db.Timestamptz(6)
remote_deleted Boolean
ecom_orders ecom_orders? @relation(fields: [id_ecom_order], references: [id_ecom_order], onDelete: NoAction, onUpdate: NoAction, map: "fk_ecom_order_fulfilment")
@@index([id_ecom_order], map: "fk_index_ecom_order_fulfilment")
Expand Down Expand Up @@ -1704,8 +1709,9 @@ model ecom_product_variants {
weight BigInt?
inventory_quantity BigInt?
id_ecom_product String? @db.Uuid
modifed_at DateTime @db.Timestamptz(6)
modified_at DateTime @db.Timestamptz(6)
created_at DateTime @db.Timestamptz(6)
remote_deleted Boolean
ecom_products ecom_products? @relation(fields: [id_ecom_product], references: [id_ecom_product], onDelete: NoAction, onUpdate: NoAction, map: "fk_ecom_products_variants")
@@index([id_ecom_product], map: "fk_index_ecom_products_variants")
Expand All @@ -1721,9 +1727,10 @@ model ecom_products {
description String?
vendor String?
tags String[]
modifed_at DateTime @db.Timestamptz(6)
modified_at DateTime @db.Timestamptz(6)
created_at DateTime @db.Timestamptz(6)
id_connection String @db.Uuid
remote_deleted Boolean
ecom_product_variants ecom_product_variants[]
}

Expand Down
8 changes: 5 additions & 3 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2062,13 +2062,15 @@ CREATE INDEX FK_invite_link_linkedUserID ON invite_links
CREATE TABLE events
(
id_event uuid NOT NULL,
status text NOT NULL,
id_connection uuid NOT NULL,
id_project uuid NOT NULL,
type text NOT NULL,
status text NOT NULL,
direction text NOT NULL,
"timestamp" timestamp NOT NULL DEFAULT NOW(),
method text NOT NULL,
url text NOT NULL,
provider text NOT NULL,
"timestamp" timestamp NOT NULL DEFAULT NOW(),
id_linked_user uuid NOT NULL,
CONSTRAINT PK_jobs PRIMARY KEY ( id_event ),
CONSTRAINT FK_12 FOREIGN KEY ( id_linked_user ) REFERENCES linked_users ( id_linked_user )
Expand All @@ -2077,8 +2079,8 @@ CREATE INDEX FK_linkeduserID_projectID ON events
(
id_linked_user
);
COMMENT ON COLUMN events.status IS 'pending,, retry_scheduled, failed, success';
COMMENT ON COLUMN events.type IS 'example crm_contact.created crm_contact.deleted';
COMMENT ON COLUMN events.status IS 'pending,, retry_scheduled, failed, success';

-- ************************************** crm_tasks
CREATE TABLE crm_tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export class IngestDataService {

const event = await this.prisma.events.create({
data: {
id_connection: connectionId,
id_project: projectId,
id_event: uuidv4(),
status: 'success',
type: `${vertical}.${commonObject}.synced`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import { ApiProperty } from '@nestjs/swagger';
export class WebhookDto {
@ApiProperty({
type: String,
example: 'https://acme.com/webhook_receiver',
nullable: true,
description: 'The endpoint url of the webhook.',
})
url: string;

@ApiProperty({
type: String,
example: 'Webhook to receive connection events',
nullable: true,
description: 'The description of the webhook.',
})
description?: string;

@ApiProperty({
type: [String],
example: ['connection.created'],
nullable: true,
description: 'The events that the webhook listen to.',
})
Expand Down Expand Up @@ -54,63 +57,66 @@ export class SignatureVerificationDto {
export class WebhookResponse {
@ApiProperty({
type: String,
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
nullable: true,
description: 'The unique UUID of the webhook.',
})
id_webhook_endpoint: string;

@ApiProperty({
type: String,
example: 'Webhook to receive connection events',
nullable: true,
description: 'The description of the webhook.',
})
endpoint_description: string | null;

@ApiProperty({
type: String,
example: 'https://acme.com/webhook_receiver',
nullable: true,
description: 'The endpoint url of the webhook.',
})
url: string;

@ApiProperty({
type: String,
nullable: true,
description: 'The secret of the webhook.',
})
@ApiProperty({ type: String, description: 'The secret of the webhook.' })
secret: string;

@ApiProperty({
type: Boolean,
example: true,
nullable: true,
description: 'The status of the webhook.',
})
active: boolean;

@ApiProperty({
type: Date,
example: '2024-10-01T12:00:00Z',
description: 'The created date of the webhook.',
nullable: true,

description: 'The created date of the webhook.',
})
created_at: Date;

@ApiProperty({
type: [String],
example: ['connection.created'],
nullable: true,
description: 'The events that the webhook listen to.',
})
scope: string[];

@ApiProperty({
type: String,
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
nullable: true,
description: 'The project id tied to the webhook.',
})
id_project: string;

@ApiProperty({
type: Date,
example: '2024-10-01T12:00:00Z',
nullable: true,
description: 'The last update date of the webhook.',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ApiExcludeEndpoint,
ApiOperation,
ApiTags,
ApiParam,
} from '@nestjs/swagger';
import {
SignatureVerificationDto,
Expand Down Expand Up @@ -66,6 +67,13 @@ export class WebhookController {

@ApiOperation({ operationId: 'delete', summary: 'Delete Webhook' })
@ApiPostCustomResponse(WebhookResponse)
@ApiParam({
name: 'id',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
description: 'id of the webhook to delete.',
})
@Delete(':id')
@UseGuards(ApiKeyAuthGuard)
async deleteWebhook(@Request() req: any, @Param('id') whId: string) {
Expand All @@ -89,6 +97,13 @@ export class WebhookController {
})
@UseGuards(ApiKeyAuthGuard)
@ApiPostCustomResponse(WebhookResponse)
@ApiParam({
name: 'id',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
description: 'id of the webhook to update.',
})
@Put(':id')
async updateWebhookStatus(
@Request() req: any,
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/@core/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ApiBody,
ApiExcludeController,
ApiOperation,
ApiParam,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
Expand Down Expand Up @@ -98,6 +99,13 @@ export class AuthController {

@ApiOperation({ operationId: 'deleteApiKey', summary: 'Delete API Keys' })
@ApiResponse({ status: 201 })
@ApiParam({
name: 'id',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
description: 'Id of the api key to delete.',
})
@Delete('api_keys/:id')
@UseGuards(JwtAuthGuard)
async deleteApiKey(@Param('id') apiKeyId: string) {
Expand Down
26 changes: 23 additions & 3 deletions packages/api/src/@core/auth/dto/api-key.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { ApiProperty } from '@nestjs/swagger';

export class ApiKeyDto {
@ApiProperty()
@ApiProperty({
name: 'projectId',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
description: 'Id of the project',
})
projectId: string;
@ApiProperty()

@ApiProperty({
name: 'userId',
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
required: true,
type: String,
description: 'Id of the user',
})
userId: string;
@ApiProperty()

@ApiProperty({
name: 'keyName',
example: 'My Api Key',
required: true,
type: String,
description: 'Name of the key',
})
keyName: string;
}
42 changes: 36 additions & 6 deletions packages/api/src/@core/auth/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateUserDto {
@ApiProperty()
@ApiProperty({
example: 'John',
type: String,
description: 'The first name of the user',
})
first_name: string;
@ApiProperty()

@ApiProperty({
example: 'Doe',
type: String,
description: 'The last name of the user',
})
last_name: string;
@ApiProperty()

@ApiProperty({
example: '[email protected]',
type: String,
description: 'The email of the user',
})
email: string;
@ApiProperty()

@ApiProperty({
example: 'oauth2',
type: String,
description: 'The authentication strategy',
})
strategy: string;
@ApiPropertyOptional()

@ApiPropertyOptional({
example: '$hashed_163_password',
type: String,
description: 'The hashed password',
})
password_hash: string;
@ApiPropertyOptional()

@ApiPropertyOptional({
example: '801f9ede-c698-4e66-a7fc-48d19eebaa4f',
type: String,
required: false,
description: 'The organization ID',
})
id_organisation?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { IsEmail } from 'class-validator';
export class RequestPasswordResetDto {
@IsEmail()
email: string;
}
}
2 changes: 2 additions & 0 deletions packages/api/src/@core/connections/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ConnectionMetadata = {
linkedUserId: string;
remoteSource: string;
connectionId: string;
projectId: string;
};

@Injectable()
Expand All @@ -31,6 +32,7 @@ export class ConnectionUtils {
linkedUserId: res.id_linked_user,
remoteSource: res.provider_slug,
connectionId: res.id_connection,
projectId: res.id_project,
};
} catch (error) {
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class AccountingConnectionsService implements IConnectionCategory {
const data: Connection = await service.handleCallback(callbackOpts);
const event = await this.prisma.events.create({
data: {
id_connection: data.id_connection,
id_project: data.id_project,
id_event: uuidv4(),
status: 'success',
type: 'connection.created',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export class AtsConnectionsService implements IConnectionCategory {
const data: Connection = await service.handleCallback(callbackOpts);
const event = await this.prisma.events.create({
data: {
id_connection: data.id_connection,
id_project: data.id_project,
id_event: uuidv4(),
status: 'success',
type: 'connection.created',
Expand Down
Loading

0 comments on commit 20caea3

Please sign in to comment.