Skip to content

Commit

Permalink
Merge pull request #60 from hypersign-protocol/somechanges
Browse files Browse the repository at this point in the history
Somechanges
  • Loading branch information
Pratap2018 authored Nov 13, 2024
2 parents 3c6b632 + f33f5a7 commit 9458d16
Show file tree
Hide file tree
Showing 9 changed files with 580 additions and 322 deletions.
95 changes: 41 additions & 54 deletions src/decorators/authHeader.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,41 @@
import { SetMetadata, applyDecorators } from "@nestjs/common";
import { ApiHeader } from "@nestjs/swagger";






export const AuthHeader = ():PropertyDecorator=>{


return applyDecorators(
ApiHeader({
name: 'Authorization',
description: 'Auth Header',
required: true,

}),
ApiHeader({
name: 'Capability-invocation',
description: 'Capability-invocation Header',
required: true,
}),
ApiHeader({
name:'Controller',
description:'Controller Header',
required:true,
}),
ApiHeader({
name:'Digest',
description:'Digest Header',
required:true,
}),
ApiHeader({
name:'VermethodId',
description:'Verification Method Id Header',
required:true,
}),
ApiHeader({
name:'Host',
description:'Host Header',
required:true,
}),
ApiHeader({
name:'Content-Length',
description:'Content-Length Header',


}),



)
}
import { applyDecorators } from '@nestjs/common';
import { ApiHeader } from '@nestjs/swagger';

export const AuthHeader = (): PropertyDecorator => {
return applyDecorators(
ApiHeader({
name: 'Authorization',
description: 'Auth Header',
required: true,
}),
ApiHeader({
name: 'Capability-invocation',
description: 'Capability-invocation Header',
required: true,
}),
ApiHeader({
name: 'Controller',
description: 'Controller Header',
required: true,
}),
ApiHeader({
name: 'Digest',
description: 'Digest Header',
required: true,
}),
ApiHeader({
name: 'VermethodId',
description: 'Verification Method Id Header',
required: true,
}),
ApiHeader({
name: 'Host',
description: 'Host Header',
required: true,
}),
ApiHeader({
name: 'Content-Length',
description: 'Content-Length Header',
}),
);
};
183 changes: 132 additions & 51 deletions src/user-vault/controllers/user-vault.controller.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,141 @@
import { UserVaultService } from '../services/user-vault.service';
import { ApiBody, ApiHeader, ApiQuery, ApiResponse, ApiTags } from "@nestjs/swagger";
import { Body, Controller, Get, Header, HttpStatus, Logger, Param, Post, Put, Query, RawBodyRequest, Redirect, Req, Res, UsePipes, ValidationPipe } from "@nestjs/common";
import { AuthHeader } from "../../decorators/authHeader.decorator";
import { CreateDocumentDTO, DocumentQueryDTO, DocumentResponseDTO, UpdateDoumentDTO } from "../dto/document.dto";
import {
ApiBody,
ApiHeader,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import {
Body,
Controller,
Delete,
Get,
Header,
HttpStatus,
Logger,
Param,
Post,
Put,
Query,
RawBodyRequest,
Redirect,
Req,
Res,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { AuthHeader } from '../../decorators/authHeader.decorator';
import {
CreateDocumentDTO,
DocumentQueryDTO,
DocumentResponseDTO,
UpdateDoumentDTO,
} from '../dto/document.dto';

@ApiTags('Vault Endpoints')
@Controller('vault')
export class UserVaultController {
constructor(private readonly vaultService: UserVaultService) {}

@AuthHeader()
@Post(':vaultId/document')
@ApiResponse({ status: 201, type: DocumentResponseDTO, })
async createDocument(@Param() _params, @Req() _req, @Body() _body: CreateDocumentDTO): Promise<DocumentResponseDTO> {
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;
return await this.vaultService.createDocument({ id, document: _body ,invoker});
}

@AuthHeader()
@ApiResponse({ status: 200, type: DocumentResponseDTO, })
@Get(':vaultId/document/:documentId')
async getEdv(@Param() _params,@Req() _req): Promise<any> {
const documentId = _params.documentId;
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;

return await this.vaultService.getDocument({ id, documentId ,invoker});
}

@AuthHeader()
@ApiResponse({ status: 200, type: DocumentResponseDTO })
@Put(':vaultId/document')
async updateDocument(@Param() _params, @Body() _body: UpdateDoumentDTO,@Res() _res): Promise<DocumentResponseDTO> {
const id = _params.vaultId;
return _res.status(HttpStatus.OK).send(await this.vaultService.updateDocument({ id, document: _body }))
}

@AuthHeader()
@ApiResponse({ status: 302, type: [DocumentResponseDTO] })
@ApiQuery({ name: 'limit', required: true, description: 'Number of documents to return' })
@ApiQuery({ name: 'page', required: true, description: 'Page number' })
@Get(':vaultId/documents')
async getAllDocuments(@Param() _params, @Query() _query,@Res() _res): Promise<DocumentResponseDTO[]> {
const id = _params.vaultId;
const limit = _query.limit ? _query.limit : 10;
const page = _query.page ? _query.page : 1;
return _res.status(HttpStatus.FOUND).send ( await this.vaultService.getAllDocuments(id, page, limit));
}

@AuthHeader()
@ApiResponse({ status: 200, type: [DocumentResponseDTO] })
@Post(':vaultId/query')
async queryDocuments(@Param() _params, @Body() _body:DocumentQueryDTO,@Res() _res): Promise<DocumentResponseDTO[]> {
const id = _params.vaultId;
return _res.status(HttpStatus.OK).send(await this.vaultService.queryDocuments(id, _body));
}
@AuthHeader()
@Post(':vaultId/document')
@ApiResponse({ status: 201, type: DocumentResponseDTO })
async createDocument(
@Param() _params,
@Req() _req,
@Body() _body: CreateDocumentDTO,
): Promise<DocumentResponseDTO> {
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;
return await this.vaultService.createDocument({
id,
document: _body,
invoker,
});
}

@AuthHeader()
@Delete(':vaultId/document/:documentId')
@ApiResponse({ status: 200 })
async deleteDocument(@Param() _params, @Req() _req): Promise<any> {
const id = _params.vaultId;
const docId = _params.documentId;
const invoker = _req.headers.vermethodid;
return await this.vaultService.deleteDocument({
id,
documentId: docId,
invoker,
});
}
@AuthHeader()
@Delete('/:vaultId')
@ApiResponse({ status: 200 })
async deleteVault(@Param() _params, @Req() _req) {
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;

return await this.vaultService.deleteVault({ id, invoker });
}

@AuthHeader()
@ApiResponse({ status: 200, type: DocumentResponseDTO })
@Get(':vaultId/document/:documentId')
async getEdv(@Param() _params, @Req() _req): Promise<any> {
const documentId = _params.documentId;
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;

return await this.vaultService.getDocument({ id, documentId, invoker });
}

@AuthHeader()
@ApiResponse({ status: 200, type: DocumentResponseDTO })
@Put(':vaultId/document')
async updateDocument(
@Param() _params,
@Body() _body: UpdateDoumentDTO,
@Res() _res,
): Promise<DocumentResponseDTO> {
const id = _params.vaultId;
return _res
.status(HttpStatus.OK)
.send(await this.vaultService.updateDocument({ id, document: _body }));
}

@AuthHeader()
@ApiResponse({ status: 302, type: [DocumentResponseDTO] })
@ApiQuery({
name: 'limit',
required: true,
description: 'Number of documents to return',
})
@ApiQuery({ name: 'page', required: true, description: 'Page number' })
@Get(':vaultId/documents')
async getAllDocuments(
@Param() _params,
@Query() _query,
@Res() _res,
): Promise<DocumentResponseDTO[]> {
const id = _params.vaultId;
const limit = _query.limit ? _query.limit : 10;
const page = _query.page ? _query.page : 1;
return _res
.status(HttpStatus.FOUND)
.send(await this.vaultService.getAllDocuments(id, page, limit));
}

@AuthHeader()
@ApiResponse({ status: 200, type: [DocumentResponseDTO] })
@Post(':vaultId/query')
async queryDocuments(
@Param() _params,
@Body() _body: DocumentQueryDTO,
@Res() _res,
): Promise<DocumentResponseDTO[]> {
const id = _params.vaultId;
return _res
.status(HttpStatus.OK)
.send(await this.vaultService.queryDocuments(id, _body));
}
}
3 changes: 2 additions & 1 deletion src/user-vault/dto/document.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export class IIndexed{
@ApiProperty()
hmac:Ihmac;

@ApiProperty()
@ApiProperty({
})
attributes:IAttributes;
}

Expand Down
1 change: 1 addition & 0 deletions src/user-vault/providers/databaseProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const UserVaultProviders = [
}

const uri = `${BASE_DB_PATH}/${tenantDB}${process.env.DB_CONFIG}`;
Logger.debug('connecting ' + tenantDB, 'DB Provider');
Logger.log(uri, 'tenant-mongoose-connections');
Logger.log(
'Before creating new db connection...',
Expand Down
Loading

0 comments on commit 9458d16

Please sign in to comment.