Skip to content

Commit 710ef7e

Browse files
refactor: update organization API to support updation of country, state and city (#1180)
* refactor: update organization API to support updation of country, state and city Signed-off-by: pranalidhanavade <[email protected]> * resolved sonarlint issues Signed-off-by: pranalidhanavade <[email protected]> * resolved sonarlint issues Signed-off-by: pranalidhanavade <[email protected]> --------- Signed-off-by: pranalidhanavade <[email protected]>
1 parent d979119 commit 710ef7e

File tree

5 files changed

+221
-202
lines changed

5 files changed

+221
-202
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ApiExtraModels, ApiPropertyOptional } from '@nestjs/swagger';
2+
import { IsNotEmpty, IsNumber, IsOptional } from 'class-validator';
3+
4+
@ApiExtraModels()
5+
export class GeoLocationDto {
6+
@ApiPropertyOptional({ example: 101 })
7+
@IsOptional()
8+
@IsNotEmpty({ message: 'country is required' })
9+
@IsNumber({}, { message: 'countryId must be a number' })
10+
countryId?: number;
11+
12+
@ApiPropertyOptional({ example: 4008 })
13+
@IsOptional()
14+
@IsNotEmpty({ message: 'state is required' })
15+
@IsNumber({}, { message: 'stateId must be a number' })
16+
stateId?: number;
17+
18+
@ApiPropertyOptional({ example: 1000 })
19+
@IsOptional()
20+
@IsNotEmpty({ message: 'city is required' })
21+
@IsNumber({}, { message: 'cityId must be a number' })
22+
cityId?: number;
23+
}

apps/api-gateway/src/organization/dtos/create-organization-dto.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
2-
import { IsNotEmpty, IsNumber, IsOptional, IsString, IsUrl, MaxLength, MinLength } from 'class-validator';
2+
import { IsNotEmpty, IsOptional, IsString, IsUrl, MaxLength, MinLength } from 'class-validator';
33

44
import { Transform } from 'class-transformer';
55
import { IsNotSQLInjection, trim } from '@credebl/common/cast.helper';
6+
import { GeoLocationDto } from '../../dtos/geo-location-dto';
67

78
@ApiExtraModels()
8-
export class CreateOrganizationDto {
9+
export class CreateOrganizationDto extends GeoLocationDto {
910
@ApiProperty()
1011
@Transform(({ value }) => trim(value))
1112
@IsNotEmpty({ message: 'Organization name is required.' })
@@ -52,22 +53,4 @@ export class CreateOrganizationDto {
5253
@Transform(({ value }) => trim(value))
5354
@IsString({ message: 'registrationNumber must be in string format.' })
5455
registrationNumber?: string;
55-
56-
@ApiPropertyOptional({ example: 101 })
57-
@IsOptional()
58-
@IsNotEmpty({ message: 'country is required' })
59-
@IsNumber({}, { message: 'countryId must be a number' })
60-
countryId?: number;
61-
62-
@ApiPropertyOptional({ example: 4008 })
63-
@IsOptional()
64-
@IsNotEmpty({ message: 'state is required' })
65-
@IsNumber({}, { message: 'stateId must be a number' })
66-
stateId?: number;
67-
68-
@ApiPropertyOptional({ example: 1000 })
69-
@IsOptional()
70-
@IsNotEmpty({ message: 'city is required' })
71-
@IsNumber({}, { message: 'cityId must be a number' })
72-
cityId?: number;
7356
}

apps/api-gateway/src/organization/dtos/update-organization-dto.ts

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,44 @@ import { IsNotEmpty, IsOptional, IsString, IsBoolean, MaxLength, MinLength, Vali
33

44
import { Transform } from 'class-transformer';
55
import { ImageBase64Validator, IsNotSQLInjection, trim } from '@credebl/common/cast.helper';
6+
import { GeoLocationDto } from '../../dtos/geo-location-dto';
67

78
@ApiExtraModels()
8-
export class UpdateOrganizationDto {
9-
10-
11-
orgId: string;
12-
13-
@ApiPropertyOptional()
14-
@IsOptional()
15-
@Transform(({ value }) => trim(value))
16-
@IsNotEmpty({ message: 'Organization name is required.' })
17-
@MinLength(2, { message: 'Organization name must be at least 2 characters.' })
18-
@MaxLength(200, { message: 'Organization name must be at most 200 characters.' })
19-
@IsString({ message: 'Organization name must be in string format.' })
20-
@IsNotSQLInjection({ message: 'Incorrect pattern for organization name.' })
21-
name: string;
22-
23-
@ApiPropertyOptional()
24-
@IsOptional()
25-
@Transform(({ value }) => trim(value))
26-
@IsNotEmpty({ message: 'Description is required.' })
27-
@MinLength(2, { message: 'Description must be at least 2 characters.' })
28-
@MaxLength(1000, { message: 'Description must be at most 1000 characters.' })
29-
@IsString({ message: 'Description must be in string format.' })
30-
description: string;
31-
32-
@ApiPropertyOptional()
33-
@IsOptional()
34-
@Transform(({ value }) => trim(value))
35-
@Validate(ImageBase64Validator)
36-
logo?: string = '';
37-
38-
@ApiPropertyOptional()
39-
@IsOptional()
40-
website?: string;
41-
42-
@ApiPropertyOptional({ example: true })
43-
@IsOptional()
44-
@IsBoolean({ message: 'isPublic should be boolean' })
45-
@IsOptional()
46-
isPublic?: boolean = false;
47-
48-
}
9+
export class UpdateOrganizationDto extends GeoLocationDto {
10+
orgId: string;
11+
12+
@ApiPropertyOptional()
13+
@IsOptional()
14+
@Transform(({ value }) => trim(value))
15+
@IsNotEmpty({ message: 'Organization name is required.' })
16+
@MinLength(2, { message: 'Organization name must be at least 2 characters.' })
17+
@MaxLength(200, { message: 'Organization name must be at most 200 characters.' })
18+
@IsString({ message: 'Organization name must be in string format.' })
19+
@IsNotSQLInjection({ message: 'Incorrect pattern for organization name.' })
20+
name: string;
21+
22+
@ApiPropertyOptional()
23+
@IsOptional()
24+
@Transform(({ value }) => trim(value))
25+
@IsNotEmpty({ message: 'Description is required.' })
26+
@MinLength(2, { message: 'Description must be at least 2 characters.' })
27+
@MaxLength(1000, { message: 'Description must be at most 1000 characters.' })
28+
@IsString({ message: 'Description must be in string format.' })
29+
description: string;
30+
31+
@ApiPropertyOptional()
32+
@IsOptional()
33+
@Transform(({ value }) => trim(value))
34+
@Validate(ImageBase64Validator)
35+
logo?: string = '';
36+
37+
@ApiPropertyOptional()
38+
@IsOptional()
39+
website?: string;
40+
41+
@ApiPropertyOptional({ example: true })
42+
@IsOptional()
43+
@IsBoolean({ message: 'isPublic should be boolean' })
44+
@IsOptional()
45+
isPublic?: boolean = false;
46+
}

apps/organization/interfaces/organization.interface.ts

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Prisma } from "@prisma/client";
2-
import { JsonValue } from "@prisma/client/runtime/library";
1+
import { Prisma } from '@prisma/client';
2+
import { JsonValue } from '@prisma/client/runtime/library';
33

44
export interface IUserOrgRoles {
5-
id: string
6-
userId: string
7-
orgRoleId: string
8-
orgId: string | null,
9-
orgRole: IOrgRole
5+
id: string;
6+
userId: string;
7+
orgRoleId: string;
8+
orgId: string | null;
9+
orgRole: IOrgRole;
1010
}
1111

1212
export interface IClientCredentials {
@@ -21,9 +21,11 @@ export interface IUpdateOrganization {
2121
logo?: string;
2222
website?: string;
2323
orgSlug?: string;
24-
isPublic?:boolean;
24+
isPublic?: boolean;
2525
userId?: string;
26-
26+
countryId?: number;
27+
cityId?: number;
28+
stateId?: number;
2729
}
2830

2931
export interface ICreateConnectionUrl {
@@ -43,8 +45,7 @@ export interface IOrgAgent {
4345
apiKey: string;
4446
}
4547

46-
47-
export interface IGetOrgById {
48+
export interface IGetOrgById {
4849
id: string;
4950
name: string;
5051
description: string;
@@ -88,33 +89,33 @@ interface IOrgAgentType {
8889
interface ILedgers {
8990
id: string;
9091
name: string;
91-
networkType: string
92+
networkType: string;
9293
}
9394

9495
export interface IGetOrganization {
95-
totalCount:number;
96-
totalPages:number;
97-
organizations : IGetAllOrganizations[];
96+
totalCount: number;
97+
totalPages: number;
98+
organizations: IGetAllOrganizations[];
9899
}
99100

100-
interface IGetAllOrganizations{
101-
id: string,
102-
name: string,
103-
description: string,
104-
logoUrl: string,
105-
orgSlug: string,
101+
interface IGetAllOrganizations {
102+
id: string;
103+
name: string;
104+
description: string;
105+
logoUrl: string;
106+
orgSlug: string;
106107
userOrgRoles: IUserOrganizationRoles[];
107108
}
108109

109110
interface IUserOrganizationRoles {
110-
id: string,
111-
orgRole :IOrgRole;
111+
id: string;
112+
orgRole: IOrgRole;
112113
}
113114

114115
export interface IOrgRole {
115-
id: string
116-
name: string
117-
description: string
116+
id: string;
117+
name: string;
118+
description: string;
118119
}
119120

120121
export interface IOrgInvitationsPagination {
@@ -123,14 +124,14 @@ export interface IOrgInvitationsPagination {
123124
}
124125

125126
interface IInvitation {
126-
id: string,
127-
orgId: string,
128-
email: string,
129-
userId: string,
130-
status: string,
131-
orgRoles: string[],
132-
createDateTime: Date,
133-
createdBy:string,
127+
id: string;
128+
orgId: string;
129+
email: string;
130+
userId: string;
131+
status: string;
132+
orgRoles: string[];
133+
createDateTime: Date;
134+
createdBy: string;
134135
organisation: IOrganizationPagination;
135136
}
136137

@@ -156,15 +157,15 @@ export interface IDidList {
156157
}
157158

158159
export interface IPrimaryDid {
159-
orgId: string,
160-
did: string
160+
orgId: string;
161+
did: string;
161162
}
162163

163164
export interface IDidDetails {
164165
id: string;
165-
createDateTime: Date;
166+
createDateTime: Date;
166167
createdBy: string;
167-
lastChangedDateTime: Date;
168+
lastChangedDateTime: Date;
168169
lastChangedBy: string;
169170
orgId: string;
170171
isPrimaryDid: boolean;
@@ -174,9 +175,9 @@ export interface IDidDetails {
174175
}
175176

176177
export interface IPrimaryDidDetails extends IPrimaryDid {
177-
id: string
178-
networkId: string
179-
didDocument: Prisma.JsonValue
178+
id: string;
179+
networkId: string;
180+
didDocument: Prisma.JsonValue;
180181
}
181182

182183
export interface OrgInvitation {
@@ -194,17 +195,17 @@ export interface OrgInvitation {
194195
}
195196

196197
export interface ILedgerNameSpace {
197-
id: string;
198-
createDateTime: Date;
199-
lastChangedDateTime: Date;
200-
name: string;
201-
networkType: string;
202-
poolConfig: string;
203-
isActive: boolean;
204-
networkString: string;
205-
nymTxnEndpoint: string;
206-
indyNamespace: string;
207-
networkUrl: string;
198+
id: string;
199+
createDateTime: Date;
200+
lastChangedDateTime: Date;
201+
name: string;
202+
networkType: string;
203+
poolConfig: string;
204+
isActive: boolean;
205+
networkString: string;
206+
nymTxnEndpoint: string;
207+
indyNamespace: string;
208+
networkUrl: string;
208209
}
209210

210211
export interface IGetDids {
@@ -232,7 +233,6 @@ export interface ILedgerDetails {
232233
nymTxnEndpoint: string;
233234
indyNamespace: string;
234235
networkUrl: string;
235-
236236
}
237237
export interface IOrgRoleDetails {
238238
id: string;
@@ -250,10 +250,9 @@ export interface IEcosystemOrgStatus {
250250
status: string;
251251
}
252252

253-
254253
interface IDidDocument {
255254
id: string;
256-
"@context": string[];
255+
'@context': string[];
257256
authentication: string[];
258257
verificationMethod: IVerificationMethod[];
259258
}
@@ -296,11 +295,11 @@ interface IOrganisation {
296295
}
297296

298297
interface IUserOrgRolesDetails {
299-
id: string
300-
userId: string
301-
orgRoleId: string
302-
orgId: string | null,
303-
idpRoleId: string
298+
id: string;
299+
userId: string;
300+
orgRoleId: string;
301+
orgId: string | null;
302+
idpRoleId: string;
304303
}
305304
export interface IOrgDetails {
306305
organisations: IOrganisation[];

0 commit comments

Comments
 (0)