This file contains hidden or 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
(function () { | |
'use strict'; | |
angular | |
.module('sidenav2',['ngMaterial', 'ngAnimate']) | |
.controller('sidenav2Ctrl', ['$scope', '$menuService',sidenav2Ctrl]) | |
.directive('sideMenu', sidenavDirective) | |
.directive('menuLink', sidenavMenuLinkDirective) | |
.directive('menuToggle', sidenavMenuToggleDirective) | |
.directive('menuHeading', sidenavMenuHeadingDirective) |
This file contains hidden or 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
/** | |
* Cria um array com n itens para realizar testes. | |
* | |
*/ | |
function getArray(n, obj){ | |
let r = []; | |
for(let i=0; i< n; i++){ | |
r.push(obj); | |
} | |
return r; |
This file contains hidden or 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
Configuring the setup | |
1. Setting up the dependices | |
yarn init -y (Initalises a packag.json with the default values) | |
yarn add knex sqlite3 (Add knex sqlite module) | |
yarn add jest --dev (Add jest to dev dependices) | |
2. Adding scripts to the package.json file |
This file contains hidden or 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
import { Get, Controller, Render } from '@nestjs/common'; | |
import { AppService } from './app.service'; | |
@Controller('cats') | |
export class AppController { | |
constructor(private readonly appService: AppService) {} | |
@Get() | |
public async index() { | |
const message = this.appService.getHello(); |
This file contains hidden or 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
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | |
@Entity() | |
export class User { | |
@PrimaryGeneratedColumn() | |
id: number; | |
@Column() | |
firstName: string; |
This file contains hidden or 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
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | |
import { Document } from 'mongoose'; | |
export type CatDocument = Cat & Document; | |
@Schema() | |
export class Cat { | |
@Prop() | |
name: string; |
This file contains hidden or 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
import { Model } from 'mongoose'; | |
import { Injectable } from '@nestjs/common'; | |
import { InjectModel } from '@nestjs/mongoose'; | |
import { Cat, CatDocument } from './schemas/cat.schema'; | |
import { CreateCatDto } from './dto/create-cat.dto'; | |
@Injectable() | |
export class CatsService { | |
constructor(@InjectModel(Cat.name) private catModel: Model<CatDocument>) {} |
This file contains hidden or 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
import { Injectable } from '@nestjs/common'; | |
import { InjectRepository } from '@nestjs/typeorm'; | |
import { Repository } from 'typeorm'; | |
import { User } from './user.entity'; | |
@Injectable() | |
export class UsersService { | |
constructor( | |
@InjectRepository(User) | |
private usersRepository: Repository<User>, |
This file contains hidden or 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
import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | |
import { Observable } from 'rxjs'; | |
@Injectable() | |
export class AuthGuard implements CanActivate { | |
canActivate( | |
context: ExecutionContext, | |
): boolean | Promise<boolean> | Observable<boolean> { | |
const request = context.switchToHttp().getRequest(); | |
return validateRequest(request); |
This file contains hidden or 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
{ | |
"statusCode": 403, | |
"message": "Forbidden resource", | |
"error": "Forbidden" | |
} |
OlderNewer