Skip to content
Snippets Groups Projects
schemas.controller.ts 7.40 KiB
import type {
  EventAnonCredsSchemasGetAll,
  EventAnonCredsSchemasGetById,
  EventAnonCredsSchemasRegister,
} from '@ocm/shared';

import {
  Body,
  Controller,
  Get,
  HttpStatus,
  NotFoundException,
  Param,
  Post,
  Query,
  UseInterceptors,
  UsePipes,
  ValidationPipe,
  Version,
} from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { MultitenancyParams, ResponseFormatInterceptor } from '@ocm/shared';
import { Observable, of, switchMap } from 'rxjs';

import { GetByIdParams } from './dto/get-by-id.dto.js';
import { RegisterSchemaPayload } from './dto/register-schema.dto.js';
import { SchemasService } from './schemas.service.js';

@Controller()
@UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
@UseInterceptors(ResponseFormatInterceptor)
@ApiTags('Schemas')
export class SchemasController {
  public constructor(private readonly schemasService: SchemasService) {}

  @Version('1')
  @Get()
  @ApiOperation({
    summary: 'Fetch a list of schemas',
    description: 'This call provides a list of schemas for a given tenant',
  })
  @ApiResponse({
    status: HttpStatus.OK,
    description: 'Schemas fetched successfully',
    content: {
      'application/json': {
        schema: {},
        examples: {
          'Schemas fetched successfully': {
            value: {
              statusCode: 200,
              message: 'Schemas fetched successfully',
              data: [],
            },
          },
        },
      },
    },
  })
  @ApiResponse({
    status: HttpStatus.NOT_FOUND,
    description: 'Tenant not found',
    content: {
      'application/json': {
        schema: {},
        examples: {
          'Tenant not found': {
            value: {
              statusCode: 404,
              message: 'Tenant not found',