Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth #3

Open
wants to merge 4 commits into
base: nestjs-ddd
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
DB_DRIVER=sqlite
DB_PATH=./data/database.db
SECRET_KEY=ALGO DIFICIL DE ADIVINAR PARA QUE LO USE JWT
VERSION=el hash del último commit de este repositorio
VERSION=cba11b15935f0227fe25e663a5968e260ca53666
PORT=3000
AUTH0_ISSUER_URL=https://dev-keuhfnl9.us.auth0.com/
AUTH0_AUDIENCE=http://rent-a-car
8 changes: 7 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
"no-shadow": "warn",
"class-methods-use-this": "off",
"no-useless-constructor": "off",
"import/no-cycle": "off"
"import/no-cycle": "off",
"no-param-reassign": [
"error",
{
"props": false
}
]
},
"root": true,
"env": {
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Rent a Car

## Versión básica de NestJS
## Versión de NestJS + Auth0

Este branch contiene un setup básico de NestJS dentro de la carpeta `/api`
Esta versión del Rent a Car demuestra cómo utilizar Auth0 como proveedor de identidad.

## Cómo probar la aplicación

Crear una copia de .env.dist a .env

Para correct el servidor es necesario ejecutar las migraciones de la base de datos corriendo `npm run migration:run`

Una vez que las migraciones estén listas, podemos correr `npm run dev` para ejecutar el servidor
Para ejecutar el cliente el comando es `npm run client`

Se corre con `npm run dev:api`
Empty file added data/fixtures/.gitkeep
Empty file.
10 changes: 0 additions & 10 deletions data/fixtures/Permission.yml

This file was deleted.

6 changes: 0 additions & 6 deletions data/fixtures/Role.yml

This file was deleted.

14 changes: 0 additions & 14 deletions data/fixtures/User.yml

This file was deleted.

126 changes: 17 additions & 109 deletions data/migration/1615682148699-skeleton.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableUnique } from 'typeorm';
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
TableUnique,
} from 'typeorm';

async function createUsersTable(queryRunner: QueryRunner) {
await queryRunner.createTable(
Expand All @@ -12,16 +19,12 @@ async function createUsersTable(queryRunner: QueryRunner) {
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'role_id',
type: 'integer',
},
{
name: 'username',
type: 'varchar',
},
{
name: 'password',
name: 'external_id',
type: 'varchar',
},
{
Expand All @@ -44,60 +47,26 @@ async function createUsersTable(queryRunner: QueryRunner) {
true
);

await queryRunner.createForeignKey(
await queryRunner.createIndex(
'users',
new TableForeignKey({
columnNames: ['role_id'],
referencedColumnNames: ['id'],
referencedTableName: 'roles',
new TableIndex({
columnNames: ['external_id'],
})
);

await queryRunner.createUniqueConstraint(
'users',
new TableUnique({
name: 'users_unique_username',
columnNames: ['username'],
name: 'users_unique_external_id',
columnNames: ['external_id'],
})
);
}

async function createRolesTable(queryRunner: QueryRunner) {
await queryRunner.createTable(
new Table({
name: 'roles',
columns: [
{
name: 'id',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'created_at',
type: 'dateTime',
default: 'CURRENT_TIMESTAMP',
},
{
name: 'updated_at',
type: 'dateTime',
default: 'CURRENT_TIMESTAMP',
},
],
}),
true
);

await queryRunner.createUniqueConstraint(
'roles',
'users',
new TableUnique({
name: 'roles_unique_name',
columnNames: ['name'],
name: 'users_unique_username',
columnNames: ['username'],
})
);
}
Expand Down Expand Up @@ -325,76 +294,15 @@ async function createReservationsTable(queryRunner: QueryRunner) {
);
}

async function createPermissionsTable(queryRunner: QueryRunner) {
await queryRunner.createTable(
new Table({
name: 'permissions',
columns: [
{
name: 'id',
type: 'integer',
isGenerated: true,
isPrimary: true,
generationStrategy: 'increment',
},
{
name: 'role_id',
type: 'int',
},
{
name: 'action',
type: 'varchar',
},
{
name: 'subject',
type: 'varchar',
},
{
name: 'created_at',
type: 'dateTime',
default: 'CURRENT_TIMESTAMP',
},
{
name: 'updated_at',
type: 'dateTime',
default: 'CURRENT_TIMESTAMP',
},
],
}),
true
);

await queryRunner.createForeignKey(
'permissions',
new TableForeignKey({
columnNames: ['role_id'],
referencedColumnNames: ['id'],
referencedTableName: 'roles',
})
);

await queryRunner.createUniqueConstraint(
'permissions',
new TableUnique({
columnNames: ['role_id', 'action', 'subject'],
name: 'permissions_unique_role_id_and_action_and_subject',
})
);
}

export class skeleton1615682148699 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await createRolesTable(queryRunner);
await createUsersTable(queryRunner);
await createPermissionsTable(queryRunner);
await createClientsTable(queryRunner);
await createCarsTable(queryRunner);
await createReservationsTable(queryRunner);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('permissions');
await queryRunner.dropTable('roles');
await queryRunner.dropTable('users');
await queryRunner.dropTable('reservations');
await queryRunner.dropTable('clients');
Expand Down
4 changes: 1 addition & 3 deletions ormconfig.migrations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { UserSchema } from './src/module/auth/infrastructure/database/user.schema';
import { RoleSchema } from './src/module/auth/infrastructure/database/role.schema';
import { PermissionSchema } from './src/module/auth/infrastructure/database/permission.schema';

export default {
name: 'default',
type: 'sqlite',
database: process.env.DB_PATH,
logging: true,
entities: [UserSchema, RoleSchema, PermissionSchema],
entities: [UserSchema],
migrations: ['./data/migration/**/*.ts'],
cli: {
migrationsDir: ['./data/migration'],
Expand Down
Loading