Skip to content

Commit 6db9ce6

Browse files
refactor: get all ecosystems api to support orgid as optional query params
Signed-off-by: pranalidhanavade <pranali.dhanavade@ayanworks.com>
1 parent 11f3653 commit 6db9ce6

6 files changed

Lines changed: 61 additions & 186 deletions

File tree

apps/api-gateway/src/ecosystem/ecosystem.controller.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,14 @@ export class EcosystemController {
206206
summary: 'Get ecosystems',
207207
description: 'Fetch ecosystems for Platform Admin or Ecosystem Lead'
208208
})
209+
@ApiQuery({
210+
name: 'orgId',
211+
required: false,
212+
type: String
213+
})
209214
@Roles(OrgRoles.PLATFORM_ADMIN, OrgRoles.ECOSYSTEM_LEAD)
210-
async getEcosystems(@User() reqUser: user, @Res() res: Response): Promise<Response> {
211-
const ecosystems = await this.ecosystemService.getEcosystems(reqUser.id);
215+
async getEcosystems(@User() reqUser: user, @Res() res: Response, @Query('orgId') orgId?: string): Promise<Response> {
216+
const ecosystems = await this.ecosystemService.getEcosystems(reqUser.id, orgId);
212217

213218
return res.status(HttpStatus.OK).json({
214219
statusCode: HttpStatus.OK,

apps/api-gateway/src/ecosystem/ecosystem.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export class EcosystemService {
3939
* @param userId
4040
* @returns All ecosystems from platform
4141
*/
42-
async getEcosystems(userId: string): Promise<IEcosystem[]> {
43-
return this.natsClient.sendNatsMessage(this.serviceProxy, 'get-ecosystems', { userId });
42+
async getEcosystems(userId: string, orgId: string): Promise<IEcosystem[]> {
43+
return this.natsClient.sendNatsMessage(this.serviceProxy, 'get-ecosystems', { userId, orgId });
4444
}
4545

4646
/**

apps/ecosystem/repositories/ecosystem.repository.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,4 +1241,49 @@ export class EcosystemRepository {
12411241
}
12421242
});
12431243
}
1244+
1245+
async getAllEcosystemsByOrgId(orgId: string): Promise<ecosystem[]> {
1246+
try {
1247+
if (!orgId) {
1248+
throw new BadRequestException(ResponseMessages.ecosystem.error.invalidOrgId);
1249+
}
1250+
1251+
return await this.prisma.ecosystem.findMany({
1252+
where: {
1253+
deletedAt: null,
1254+
ecosystemOrgs: {
1255+
some: {
1256+
orgId,
1257+
deletedAt: null
1258+
}
1259+
}
1260+
},
1261+
orderBy: {
1262+
createDateTime: 'desc'
1263+
},
1264+
include: {
1265+
ecosystemOrgs: {
1266+
where: {
1267+
orgId,
1268+
deletedAt: null
1269+
},
1270+
include: {
1271+
ecosystemRole: true,
1272+
organisation: {
1273+
select: {
1274+
id: true,
1275+
name: true,
1276+
orgSlug: true,
1277+
logoUrl: true
1278+
}
1279+
}
1280+
}
1281+
}
1282+
}
1283+
});
1284+
} catch (error) {
1285+
this.logger.error(`getAllEcosystemsByOrgId error: ${error.message}`);
1286+
throw error;
1287+
}
1288+
}
12441289
}

apps/ecosystem/src/ecosystem.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export class EcosystemController {
6868
* @returns List of ecosystems
6969
*/
7070
@MessagePattern({ cmd: 'get-ecosystems' })
71-
async getEcosystems(payload: { userId: string }): Promise<IEcosystem[]> {
72-
return this.ecosystemService.getEcosystems(payload.userId);
71+
async getEcosystems(payload: { userId: string; orgId: string }): Promise<IEcosystem[]> {
72+
return this.ecosystemService.getEcosystems(payload.userId, payload.orgId);
7373
}
7474

7575
/**

apps/ecosystem/src/ecosystem.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,15 @@ export class EcosystemService {
280280
}
281281
}
282282

283-
async getEcosystems(userId: string): Promise<IEcosystem[]> {
283+
async getEcosystems(userId: string, orgId: string): Promise<IEcosystem[]> {
284284
if (!userId) {
285285
throw new BadRequestException(ResponseMessages.ecosystem.error.userIdMissing);
286286
}
287287
try {
288+
if (orgId) {
289+
return this.ecosystemRepository.getAllEcosystemsByOrgId(orgId);
290+
}
291+
288292
const leadEcosystems = await this.ecosystemRepository.getEcosystemsForEcosystemLead(userId);
289293

290294
if (0 < leadEcosystems.length) {

libs/prisma-service/prisma/data/credebl-master-table.json

Lines changed: 0 additions & 179 deletions
This file was deleted.

0 commit comments

Comments
 (0)