File

src/crypto/key/key.controller.ts

Prefix

key

Description

KeyController is responsible for managing keys in the system.

Index

Methods

Methods

Async addKey
addKey(token: TokenPayload, body: KeyImportDto)
Decorators :
@Post()

Add a new key to the key service.

Parameters :
Name Type Optional
token TokenPayload No
body KeyImportDto No
Returns : Promise<literal type>
deleteKey
deleteKey(token: TokenPayload, id: string)
Decorators :
@Delete(':id')

Delete a key from the key service.

Parameters :
Name Type Optional
token TokenPayload No
id string No
Returns : any
getKeys
getKeys(token: TokenPayload)
Decorators :
@Get()

Get all keys for the tenant.

Parameters :
Name Type Optional
token TokenPayload No
Returns : Promise<KeyObj[]>
import {
    Body,
    Controller,
    Delete,
    Get,
    Inject,
    Param,
    Post,
    UseGuards,
} from '@nestjs/common';
import { ApiSecurity } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../auth/auth.guard';
import { Token, TokenPayload } from '../../auth/token.decorator';
import { KeyObj, KeyService } from './key.service';
import { KeyImportDto } from './dto/key-import.dto';
import { CryptoService } from '../crypto.service';

/**
 * KeyController is responsible for managing keys in the system.
 */
@UseGuards(JwtAuthGuard)
@ApiSecurity('oauth2')
@Controller('key')
export class KeyController {
    constructor(
        @Inject('KeyService') public readonly keyService: KeyService,
        private cryptoService: CryptoService,
    ) {}

    /**
     * Get all keys for the tenant.
     * @param token
     * @returns
     */
    @Get()
    getKeys(@Token() token: TokenPayload): Promise<KeyObj[]> {
        const tenantId = token.sub;
        return this.keyService.getKeys(tenantId);
    }

    /**
     * Add a new key to the key service.
     * @param token
     * @param body
     * @returns
     */
    @Post()
    async addKey(
        @Token() token: TokenPayload,
        @Body() body: KeyImportDto,
    ): Promise<{ id: string }> {
        const tenantId = token.sub;
        const id = await this.cryptoService.importKey(tenantId, body);
        return { id };
    }

    /**
     * Delete a key from the key service.
     * @param token
     * @param id
     */
    @Delete(':id')
    deleteKey(@Token() token: TokenPayload, @Param('id') id: string) {
        return this.cryptoService.deleteKey(token.sub, id);
    }
}

results matching ""

    No results matching ""