-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from hypersign-protocol/somechanges
Somechanges
- Loading branch information
Showing
9 changed files
with
580 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.