Skip to content

Commit

Permalink
🔥 Added validation pipes to inoput unified typse
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Apr 29, 2024
1 parent e2ffec2 commit 3ba8b8d
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 70 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"bcrypt": "^5.1.1",
"bull": "^4.11.5",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"class-validator": "^0.14.1",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"crypto": "^1.0.1",
Expand Down
31 changes: 27 additions & 4 deletions packages/api/src/crm/company/types/model.unified.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,85 @@
import { Address, Email, Phone } from '@crm/@utils/@types';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsOptional, IsString } from 'class-validator';

export class UnifiedCompanyInput {
@ApiProperty({ description: 'The name of the company' })
@ApiProperty({ type: String, description: 'The name of the company' })
@IsString()
name: string;

@ApiPropertyOptional({ description: 'The industry of the company' })
@ApiPropertyOptional({
type: String,
description: 'The industry of the company',
})
@IsString()
@IsOptional()
industry?: string;

@ApiPropertyOptional({
type: Number,
description: 'The number of employees of the company',
})
@IsNumber()
@IsOptional()
number_of_employees?: number;

@ApiPropertyOptional({
type: String,
description: 'The uuid of the user who owns the company',
})
@IsString()
@IsOptional()
user_id?: string;

@ApiPropertyOptional({
description: 'The email addresses of the company',
type: [Email],
})
@IsOptional()
email_addresses?: Email[];

@ApiPropertyOptional({
description: 'The addresses of the company',
type: [Address],
})
@IsOptional()
addresses?: Address[];

@ApiPropertyOptional({
description: 'The phone numbers of the company',
type: [Phone],
})
@IsOptional()
phone_numbers?: Phone[];

@ApiPropertyOptional({
type: {},
description:
'The custom field mappings of the company between the remote 3rd party & Panora',
})
@IsOptional()
field_mappings?: Record<string, any>;
}

export class UnifiedCompanyOutput extends UnifiedCompanyInput {
@ApiPropertyOptional({ description: 'The uuid of the company' })
@ApiPropertyOptional({ type: String, description: 'The uuid of the company' })
@IsString()
@IsOptional()
id?: string;

@ApiPropertyOptional({
type: String,
description: 'The id of the company in the context of the Crm 3rd Party',
})
@IsString()
@IsOptional()
remote_id?: string;

@ApiPropertyOptional({
type: [{}],
type: {},
description:
'The remote data of the company in the context of the Crm 3rd Party',
})
@IsOptional()
remote_data?: Record<string, any>;
}
20 changes: 16 additions & 4 deletions packages/api/src/crm/contact/types/model.unified.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Address, Email, Phone } from '@crm/@utils/@types';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';

export class UnifiedContactInput {
@ApiProperty({ description: 'The first name of the contact' })
@ApiProperty({ type: String, description: 'The first name of the contact' })
@IsString()
first_name: string;

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

@ApiPropertyOptional({
Expand All @@ -30,29 +33,38 @@ export class UnifiedContactInput {
type: String,
description: 'The uuid of the user who owns the contact',
})
@IsString()
@IsOptional()
user_id?: string;

@ApiPropertyOptional({
type: {},
description:
'The custom field mappings of the contact between the remote 3rd party & Panora',
})
@IsOptional()
field_mappings?: Record<string, any>;
}

export class UnifiedContactOutput extends UnifiedContactInput {
@ApiPropertyOptional({ description: 'The uuid of the contact' })
@ApiPropertyOptional({ type: String, description: 'The uuid of the contact' })
@IsString()
@IsOptional()
id?: string;

@ApiPropertyOptional({
type: String,
description: 'The id of the contact in the context of the Crm 3rd Party',
})
@IsString()
@IsOptional()
remote_id?: string;

@ApiPropertyOptional({
type: [{}],
type: {},
description:
'The remote data of the contact in the context of the Crm 3rd Party',
})
@IsOptional()
remote_data?: Record<string, any>;
}
34 changes: 28 additions & 6 deletions packages/api/src/crm/deal/types/model.unified.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,71 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNumber, IsOptional, IsString } from 'class-validator';

export class UnifiedDealInput {
@ApiProperty({ description: 'The name of the deal' })
@ApiProperty({ type: String, description: 'The name of the deal' })
@IsString()
name: string;

@ApiProperty({ description: 'The description of the deal' })
@ApiProperty({ type: String, description: 'The description of the deal' })
@IsString()
description: string;

@ApiProperty({ description: 'The amount of the deal' })
@ApiProperty({ type: Number, description: 'The amount of the deal' })
@IsNumber()
amount: number;

@ApiPropertyOptional({
type: String,
description: 'The uuid of the user who is on the deal',
})
@IsString()
@IsOptional()
user_id?: string;

@ApiPropertyOptional({ description: 'The uuid of the stage of the deal' })
@ApiPropertyOptional({
type: String,
description: 'The uuid of the stage of the deal',
})
@IsString()
@IsOptional()
stage_id?: string;

@ApiPropertyOptional({
type: String,
description: 'The uuid of the company tied to the deal',
})
@IsString()
@IsOptional()
company_id?: string;

@ApiPropertyOptional({
type: {},
description:
'The custom field mappings of the company between the remote 3rd party & Panora',
})
@IsOptional()
field_mappings?: Record<string, any>;
}

export class UnifiedDealOutput extends UnifiedDealInput {
@ApiPropertyOptional({ description: 'The uuid of the deal' })
@ApiPropertyOptional({ type: String, description: 'The uuid of the deal' })
@IsString()
@IsOptional()
id?: string;

@ApiPropertyOptional({
type: String,
description: 'The id of the deal in the context of the Crm 3rd Party',
})
@IsString()
@IsOptional()
remote_id?: string;

@ApiPropertyOptional({
type: [{}],
type: {},
description:
'The remote data of the deal in the context of the Crm 3rd Party',
})
@IsOptional()
remote_data?: Record<string, any>;
}
46 changes: 41 additions & 5 deletions packages/api/src/crm/engagement/types/model.unified.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,99 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsIn, IsOptional, IsString } from 'class-validator';

export class UnifiedEngagementInput {
@ApiPropertyOptional({ description: 'The content of the engagement' })
@ApiPropertyOptional({ type: String, description: 'The content of the engagement' })
@IsString()
@IsOptional()
content?: string;

@ApiPropertyOptional({ description: 'The direction of the engagement. Authorized values are INBOUND or OUTBOUND' })
@ApiPropertyOptional({
type: String,
description: 'The direction of the engagement. Authorized values are INBOUND or OUTBOUND'
})
@IsIn(['INBOUND', 'OUTBOUND'], {
message: "Direction must be either INBOUND or OUTBOUND"
})
@IsOptional()
direction?: string;

@ApiPropertyOptional({ description: 'The subject of the engagement' })
@ApiPropertyOptional({
type: String,
description: 'The subject of the engagement'
})
@IsString()
@IsOptional()
subject?: string;

@ApiPropertyOptional({ description: 'The start time of the engagement' })
@IsOptional()
start_at?: Date;

@ApiPropertyOptional({ description: 'The end time of the engagement' })
@IsOptional()
end_time?: Date;

@ApiProperty({
type: String,
description:
'The type of the engagement. Authorized values are EMAIL, CALL or MEETING',
})
@IsIn(['EMAIL', 'CALL', 'MEETING'], {
message: "Type must be either EMAIL, CALL or MEETING"
})
type: string;

@ApiPropertyOptional({
type: String,
description: 'The uuid of the user tied to the engagement',
})
@IsString()
@IsOptional()
user_id?: string;

@ApiPropertyOptional({
type: String,
description: 'The uuid of the company tied to the engagement',
})
@IsString()
@IsOptional()
company_id?: string; // uuid of Company object

@ApiPropertyOptional({
type: [String],
description: 'The uuids of contacts tied to the engagement object',
})
@IsOptional()
contacts?: string[]; // array of uuids of Engagement Contacts objects

@ApiPropertyOptional({
type: {},
description:
'The custom field mappings of the engagement between the remote 3rd party & Panora',
})
@IsOptional()
field_mappings?: Record<string, any>;
}

export class UnifiedEngagementOutput extends UnifiedEngagementInput {
@ApiPropertyOptional({ description: 'The uuid of the engagement' })
@ApiPropertyOptional({ type: String, description: 'The uuid of the engagement' })
@IsString()
@IsOptional()
id?: string;

@ApiPropertyOptional({
type: String,
description: 'The id of the engagement in the context of the Crm 3rd Party',
})
@IsString()
@IsOptional()
remote_id?: string;

@ApiPropertyOptional({
type: [{}],
type: {},
description:
'The remote data of the engagement in the context of the Crm 3rd Party',
})
@IsOptional()
remote_data?: Record<string, any>;
}
Loading

0 comments on commit 3ba8b8d

Please sign in to comment.