Incluindo tabela carModels e rotas para pegar lista de carros

This commit is contained in:
Matheus Albino Brunhara
2022-05-28 15:40:09 -05:00
parent 4d2eac45d2
commit ee259bd6ff
8 changed files with 243 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
export class CreateCarModelsTable1653768789073 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'carModels',
columns: [
{
name: 'id_model',
type: 'uuid',
isPrimary: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
},
{
name: 'name',
type: 'varchar',
}
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('carModels');
}
}

View File

@@ -0,0 +1,20 @@
import { getConnection, MigrationInterface, QueryRunner } from "typeorm";
import carModels from '../../constants/carModels'
import CarModels from "../../models/CarModels";
export class InsertDataIntoCarModelsTable1653769103891 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
carModels.forEach(async (car) => {
const GBP = await queryRunner.manager.save(queryRunner.manager.create<CarModels>(CarModels, { name: car.name }))
}
)}
public async down(queryRunner: QueryRunner): Promise<void> {
await getConnection()
.createQueryBuilder()
.delete()
.from(CarModels)
.execute();
}
}