Skip to content

Commit

Permalink
refactor: get all schemas API (#813)
Browse files Browse the repository at this point in the history
* feat: get w3c schema details by schema id

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: applied validations

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: get schemas by orgId response

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: optimized logic

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: added query parameter in get all schemas API

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refactor: property type

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* refcator: delete ecosystem member template

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

---------

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>
Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 11, 2024
1 parent d0bbb11 commit be9d736
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
2 changes: 2 additions & 0 deletions apps/api-gateway/src/interfaces/ISchemaSearch.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SchemaType } from '@credebl/enum/enum';
import { IUserRequestInterface } from '../schema/interfaces';

export interface ISchemaSearchPayload {
Expand All @@ -7,6 +8,7 @@ export interface ISchemaSearchPayload {
sortField: string;
sortBy: string;
searchByText?: string;
schemaType?: SchemaType;
user?: IUserRequestInterface
}

Expand Down
12 changes: 9 additions & 3 deletions apps/api-gateway/src/platform/platform.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ResponseMessages } from '@credebl/common/response-messages';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { AuthGuard } from '@nestjs/passport';
import * as QRCode from 'qrcode';
import { CredDefSortFields, SortFields } from '@credebl/enum/enum';
import { CredDefSortFields, SchemaType, SortFields } from '@credebl/enum/enum';
import { GetAllPlatformCredDefsDto } from '../credential-definition/dto/get-all-platform-cred-defs.dto';

@Controller('')
Expand All @@ -32,6 +32,11 @@ export class PlatformController {
name: 'sortField',
enum: SortFields,
required: false
})
@ApiQuery({
name: 'schemaType',
enum: SchemaType,
required: false
})
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
Expand All @@ -41,14 +46,15 @@ export class PlatformController {
@Res() res: Response,
@User() user: IUserRequestInterface
): Promise<Response> {
const { ledgerId, pageSize, searchByText, pageNumber, sorting, sortByValue } = getAllSchemaDto;
const { ledgerId, pageSize, searchByText, pageNumber, sorting, sortByValue, schemaType } = getAllSchemaDto;
const schemaSearchCriteria: ISchemaSearchPayload = {
ledgerId,
pageNumber,
searchByText,
pageSize,
sortField: sorting,
sortBy: sortByValue
sortBy: sortByValue,
schemaType
};
const schemasResponse = await this.platformService.getAllSchema(schemaSearchCriteria, user);
const finalResponse: IResponse = {
Expand Down
11 changes: 10 additions & 1 deletion apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsEnum, IsOptional, IsUUID, Min } from 'class-validator';
import { toNumber, trim } from '@credebl/common/cast.helper';
import { CredDefSortFields, SortFields, SortValue } from '@credebl/enum/enum';
import { CredDefSortFields, SchemaType, SortFields, SortValue } from '@credebl/enum/enum';

export class GetAllSchemaDto {
@ApiProperty({ required: false })
Expand Down Expand Up @@ -121,5 +121,14 @@ export class GetAllSchemaByPlatformDto {
@ApiProperty({ required: false })
@IsOptional()
sortByValue: string = SortValue.DESC;

@ApiProperty({
type: SchemaType,
required: false
})
@Transform(({ value }) => trim(value))
@IsOptional()
@IsEnum(SchemaType)
schemaType: SchemaType;

}
2 changes: 1 addition & 1 deletion apps/ecosystem/templates/DeleteEcosystemMemberTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class DeleteEcosystemMemberTemplate {
Hello ${email},
</p>
<p>
We would like to inform you that the organization“${orgName}”, has removed their participation as a member from the "${ecosystemName}" ecsosystem on CREDEBL.
We would like to inform you that the organization ${orgName}”, has removed their participation as a member from the "${ecosystemName}" on CREDEBL.
<hr style="border-top:1px solid #e8e8e8" />
<footer style="padding-top: 10px;">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SortValue } from '@credebl/enum/enum';
import { SchemaType, SortValue } from '@credebl/enum/enum';
import { IUserRequestInterface } from './schema.interface';

export interface ISchema {
Expand Down Expand Up @@ -57,6 +57,7 @@ export interface ISchemaSearchCriteria {
sortField: string;
sortBy: string;
searchByText?: string;
schemaType?: SchemaType;
user?: IUserRequestInterface
schemaId?: string;
orgId?: string;
Expand Down
24 changes: 14 additions & 10 deletions apps/ledger/src/schema/repositories/schema.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ export class SchemaRepository {

async getAllSchemaDetails(payload: ISchemaSearchCriteria): Promise<IPlatformSchemas> {
try {
const { ledgerId, schemaType, searchByText, sortField, sortBy, pageSize, pageNumber } = payload;
const schemasResult = await this.prisma.schema.findMany({
where: {
ledgerId: payload.ledgerId,
ledgerId,
type: schemaType,
OR: [
{ name: { contains: payload.searchByText, mode: 'insensitive' } },
{ version: { contains: payload.searchByText, mode: 'insensitive' } },
{ schemaLedgerId: { contains: payload.searchByText, mode: 'insensitive' } },
{ issuerId: { contains: payload.searchByText, mode: 'insensitive' } }
{ name: { contains: searchByText, mode: 'insensitive' } },
{ version: { contains: searchByText, mode: 'insensitive' } },
{ schemaLedgerId: { contains: searchByText, mode: 'insensitive' } },
{ issuerId: { contains: searchByText, mode: 'insensitive' } }
]
},
select: {
Expand All @@ -232,18 +234,20 @@ export class SchemaRepository {
createdBy: true,
publisherDid: true,
orgId: true, // This field can be null
issuerId: true
issuerId: true,
type: true
},
orderBy: {
[payload.sortField]: SortValue.DESC === payload.sortBy ? SortValue.DESC : SortValue.ASC
[sortField]: SortValue.DESC === sortBy ? SortValue.DESC : SortValue.ASC
},
take: Number(payload.pageSize),
skip: (payload.pageNumber - 1) * payload.pageSize
take: Number(pageSize),
skip: (pageNumber - 1) * pageSize
});

const schemasCount = await this.prisma.schema.count({
where: {
ledgerId: payload.ledgerId
ledgerId,
type: schemaType
}
});

Expand Down

0 comments on commit be9d736

Please sign in to comment.