1.0.38 • Published 1 year ago

validateroutemslib v1.0.38

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

validate route micro service library (validateroutemslib)

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install validateroutemslib

Usage

import-module

Import library Module, with 'url' in initialize, and Guards your module project.

import { Global, Module } from '@nestjs/common';
import { ValidateService } from 'application/use-cases/validate/validate.service';
import { ValidateRouteMsLibModule, EvaAuthGuard, EvaRoleGuard } from 'validateroutemslib';
import { APP_GUARD } from '@nestjs/core';
import * as dotenv from 'dotenv';
dotenv.config();

@Module({
  imports: [ValidateRouteMsLibModule.initialize('url')],
  providers: [
    {
      provide: APP_GUARD,
      useClass: EvaAuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: EvaRoleGuard,
    },
  ]
})
export class ValidateModule {}

Create decorator

create-roles-decorator

Create file with decorator.

roles.decorator

import { SetMetadata } from '@nestjs/common';

export const Roles = (...roles: string[]) => SetMetadata('roles', roles);

Example

example-controller

Import '@UseGuards()' guards decorator to validate token. If you want includes privileges add @Roles('ROLES')

import { UseGuards, Get, Param } from '@nestjs/common';
import { Roles } from '@/shared/decorators/roles/roles.decorator';
import { User } from '@shared/decorators/user/user.decorator';
import { EvaRole } from 'validateroutemslib';

@Get(':postId')
@Roles(EvaRole.Super) // optional
@UseGuards()
async getPostById(
    @User() user,
    @Param('postId') postId: number,
): Promise<any> {
  return this.postService.getPostById(user, postId);
}
1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.38

1 year ago

1.0.16

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago