Skip to content

Commit 218424f

Browse files
committed
added metaData fields in update
1 parent 36f710f commit 218424f

File tree

2 files changed

+212
-177
lines changed

2 files changed

+212
-177
lines changed
Lines changed: 195 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,200 @@
1-
import { ApiProperty } from "@nestjs/swagger";
2-
import { IsNotEmpty, IsOptional, IsString, IsUUID, IsEnum, IsLongitude, IsLatitude, IsBoolean, IsInt, Min, IsDateString, IsObject, ValidateIf, ValidateNested, Validate, IsIn } from 'class-validator';
3-
import { MeetingDetails } from "src/common/utils/types";
4-
import { Transform, Type } from "class-transformer";
5-
import { UrlWithProviderValidator } from "src/common/utils/validation.util";
6-
import { MeetingDetailsDto } from "./create-event.dto";
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import {
3+
IsNotEmpty,
4+
IsOptional,
5+
IsString,
6+
IsUUID,
7+
IsEnum,
8+
IsLongitude,
9+
IsLatitude,
10+
IsBoolean,
11+
IsInt,
12+
Min,
13+
IsDateString,
14+
IsObject,
15+
ValidateIf,
16+
ValidateNested,
17+
Validate,
18+
IsIn,
19+
} from 'class-validator';
20+
import { MeetingDetails } from 'src/common/utils/types';
21+
import { Transform, Type } from 'class-transformer';
22+
import { UrlWithProviderValidator } from 'src/common/utils/validation.util';
23+
import { MeetingDetailsDto } from './create-event.dto';
724
export interface UpdateResult {
8-
onlineDetails?: any;
9-
erMetaData?: any;
10-
eventDetails?: any;
11-
repetationDetail?: any;
12-
recurrenceUpdate?: any;
25+
onlineDetails?: any;
26+
erMetaData?: any;
27+
eventDetails?: any;
28+
repetationDetail?: any;
29+
recurrenceUpdate?: any;
1330
}
1431

1532
export class UpdateEventDto {
16-
17-
@ApiProperty({
18-
type: String,
19-
description: 'Status',
20-
example: 'live'
21-
})
22-
@IsEnum(['live', 'draft', 'archived'], {
23-
message: 'Status must be one of: live, draft, archived',
24-
})
25-
@IsString()
26-
@IsOptional()
27-
@IsNotEmpty()
28-
status: string;
29-
30-
@IsOptional()
31-
@IsString()
32-
startTime?: string;
33-
34-
@ApiProperty({
35-
type: String,
36-
description: 'title',
37-
example: 'Sample Event'
38-
})
39-
@IsString()
40-
@IsNotEmpty()
41-
@IsOptional()
42-
title?: string;
43-
44-
@ApiProperty({
45-
type: String,
46-
description: 'isRecurring',
47-
example: true
48-
})
49-
@IsBoolean()
50-
isMainEvent: boolean;
51-
52-
@ApiProperty({
53-
type: MeetingDetailsDto,
54-
description: 'Online Meeting Details',
55-
example: {
56-
url: 'https://example.com/meeting',
57-
id: '123-456-789',
58-
password: 'xxxxxxx',
59-
},
60-
})
61-
@IsObject()
62-
// @ValidateIf((o => o.onlineProvider != undefined))
63-
@ValidateIf(o => o.onlineProvider != undefined || o.onlineDetails != undefined)
64-
@ValidateNested({ each: true })
65-
@Type(() => MeetingDetailsDto)
66-
@Transform(({ value, obj }) => {
67-
value.onlineProvider = obj.onlineProvider; // Pass the provider to the nested DTO
68-
return value;
69-
})
70-
onlineDetails: MeetingDetails;
71-
72-
73-
@ApiProperty({
74-
description: 'MetaData Details',
75-
example: {
76-
"topic": "Java",
77-
"mentorId": "1244546647",
78-
"subTopic": "Type of fetaures"
79-
}
80-
})
81-
@IsObject()
82-
@IsOptional()
83-
erMetaData: any;
84-
85-
86-
@ApiProperty({
87-
type: String,
88-
description: 'Start Datetime',
89-
example: '2024-06-02T02:00:00Z'
90-
})
91-
@ValidateIf(o => o.endDatetime !== undefined)
92-
@IsDateString()
93-
startDatetime: Date;
94-
95-
@ApiProperty({
96-
type: String,
97-
description: 'End Datetime',
98-
example: '2024-06-02T05:00:00Z'
99-
})
100-
@ValidateIf(o => o.startDatetime !== undefined)
101-
@IsDateString()
102-
endDatetime: Date;
103-
104-
@ApiProperty({
105-
type: String,
106-
description: 'Location',
107-
example: 'Event Location'
108-
})
109-
@IsString()
110-
@IsNotEmpty()
111-
@IsOptional()
112-
location: string;
113-
114-
115-
@ApiProperty({
116-
type: Number,
117-
description: 'Latitude',
118-
example: 18.508345134886994
119-
})
120-
@ValidateIf(o => o.latitude !== undefined)
121-
@IsLongitude()
122-
longitude: number;
123-
124-
@ApiProperty({
125-
type: Number,
126-
description: 'Latitude',
127-
example: 18.508345134886994
128-
})
129-
@ValidateIf(o => o.longitude !== undefined)
130-
@IsLatitude()
131-
latitude: number;
132-
133-
@ApiProperty({
134-
type: String,
135-
description: 'Online Provider',
136-
example: 'Zoom',
137-
})
138-
@IsOptional()
139-
@IsString()
140-
@IsNotEmpty()
141-
@IsIn(['Zoom', 'GoogleMeet'])
142-
onlineProvider: string;
143-
144-
145-
146-
@IsString()
147-
@IsOptional()
148-
createdBy: string;
149-
150-
@IsString()
151-
@IsOptional()
152-
updatedBy: string;
153-
154-
@IsOptional()
155-
updateAt: Date;
156-
157-
// Validation to ensure if isMainEvent is true, title or status must be provided
158-
@ValidateIf(o => !o.title && !o.status && !o.onlineDetails && !o.location && !o.latitude && !o.erMetaData && !o.startDatetime && !o.onlineProvider)
159-
@IsNotEmpty({ message: 'If isMainEvent is provided, at least one of title or status must be provided.' })
160-
validateFields?: any;
161-
162-
33+
@ApiProperty({
34+
type: String,
35+
description: 'Status',
36+
example: 'live',
37+
})
38+
@IsEnum(['live', 'draft', 'archived'], {
39+
message: 'Status must be one of: live, draft, archived',
40+
})
41+
@IsString()
42+
@IsOptional()
43+
@IsNotEmpty()
44+
status: string;
45+
46+
@IsOptional()
47+
@IsString()
48+
startTime?: string;
49+
50+
@ApiProperty({
51+
type: String,
52+
description: 'title',
53+
example: 'Sample Event',
54+
})
55+
@IsString()
56+
@IsNotEmpty()
57+
@IsOptional()
58+
title?: string;
59+
60+
@ApiProperty({
61+
type: String,
62+
description: 'isRecurring',
63+
example: true,
64+
})
65+
@IsBoolean()
66+
isMainEvent: boolean;
67+
68+
@ApiProperty({
69+
type: MeetingDetailsDto,
70+
description: 'Online Meeting Details',
71+
example: {
72+
url: 'https://example.com/meeting',
73+
id: '123-456-789',
74+
password: 'xxxxxxx',
75+
},
76+
})
77+
@IsObject()
78+
// @ValidateIf((o => o.onlineProvider != undefined))
79+
@ValidateIf(
80+
(o) => o.onlineProvider != undefined || o.onlineDetails != undefined,
81+
)
82+
@ValidateNested({ each: true })
83+
@Type(() => MeetingDetailsDto)
84+
@Transform(({ value, obj }) => {
85+
value.onlineProvider = obj.onlineProvider; // Pass the provider to the nested DTO
86+
return value;
87+
})
88+
onlineDetails: MeetingDetails;
89+
90+
@ApiProperty({
91+
description: 'ErMetaData Details',
92+
example: {
93+
topic: 'Java',
94+
mentorId: '1244546647',
95+
subTopic: 'Type of fetaures',
96+
},
97+
})
98+
@IsObject()
99+
@IsOptional()
100+
erMetaData: any;
101+
102+
@ApiProperty({
103+
description: 'MetaData Details',
104+
example: {
105+
topic: 'Java',
106+
mentorId: '1244546647',
107+
subTopic: 'Type of fetaures',
108+
},
109+
})
110+
@IsObject()
111+
@IsOptional()
112+
metadata: any;
113+
114+
@ApiProperty({
115+
type: String,
116+
description: 'Start Datetime',
117+
example: '2024-06-02T02:00:00Z',
118+
})
119+
@ValidateIf((o) => o.endDatetime !== undefined)
120+
@IsDateString()
121+
startDatetime: Date;
122+
123+
@ApiProperty({
124+
type: String,
125+
description: 'End Datetime',
126+
example: '2024-06-02T05:00:00Z',
127+
})
128+
@ValidateIf((o) => o.startDatetime !== undefined)
129+
@IsDateString()
130+
endDatetime: Date;
131+
132+
@ApiProperty({
133+
type: String,
134+
description: 'Location',
135+
example: 'Event Location',
136+
})
137+
@IsString()
138+
@IsNotEmpty()
139+
@IsOptional()
140+
location: string;
141+
142+
@ApiProperty({
143+
type: Number,
144+
description: 'Latitude',
145+
example: 18.508345134886994,
146+
})
147+
@ValidateIf((o) => o.latitude !== undefined)
148+
@IsLongitude()
149+
longitude: number;
150+
151+
@ApiProperty({
152+
type: Number,
153+
description: 'Latitude',
154+
example: 18.508345134886994,
155+
})
156+
@ValidateIf((o) => o.longitude !== undefined)
157+
@IsLatitude()
158+
latitude: number;
159+
160+
@ApiProperty({
161+
type: String,
162+
description: 'Online Provider',
163+
example: 'Zoom',
164+
})
165+
@IsOptional()
166+
@IsString()
167+
@IsNotEmpty()
168+
@IsIn(['Zoom', 'GoogleMeet'])
169+
onlineProvider: string;
170+
171+
@IsString()
172+
@IsOptional()
173+
createdBy: string;
174+
175+
@IsString()
176+
@IsOptional()
177+
updatedBy: string;
178+
179+
@IsOptional()
180+
updateAt: Date;
181+
182+
// Validation to ensure if isMainEvent is true, title or status must be provided
183+
@ValidateIf(
184+
(o) =>
185+
!o.title &&
186+
!o.status &&
187+
!o.onlineDetails &&
188+
!o.location &&
189+
!o.latitude &&
190+
!o.erMetaData &&
191+
!o.startDatetime &&
192+
!o.onlineProvider &&
193+
!o.metadata,
194+
)
195+
@IsNotEmpty({
196+
message:
197+
'If isMainEvent is provided, at least one of title or status must be provided.',
198+
})
199+
validateFields?: any;
163200
}

0 commit comments

Comments
 (0)