diff --git a/src/database/data-source.ts b/src/database/data-source.ts index e2c3909..efc9ec3 100644 --- a/src/database/data-source.ts +++ b/src/database/data-source.ts @@ -21,7 +21,7 @@ export const dataSourceOptions: DataSourceOptions = { synchronize: false, // Never use true in production logging: process.env.NODE_ENV === 'development', ssl: - process.env.NODE_ENV === 'production' + process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false, }; diff --git a/src/database/migrations/1704470000000-CreateUsersTable.ts b/src/database/migrations/1704470000000-CreateUsersTable.ts deleted file mode 100644 index 59ba1c8..0000000 --- a/src/database/migrations/1704470000000-CreateUsersTable.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm'; - -export class CreateUsersTable1704470000000 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.createTable( - new Table({ - name: 'users', - columns: [ - { - name: 'id', - type: 'uuid', - isPrimary: true, - generationStrategy: 'uuid', - default: 'uuid_generate_v4()', - }, - { - name: 'name', - type: 'varchar', - length: '255', - isNullable: false, - }, - { - name: 'email', - type: 'varchar', - length: '255', - isNullable: false, - isUnique: true, - }, - { - name: 'password', - type: 'varchar', - length: '255', - isNullable: false, - }, - { - name: 'roles', - type: 'text', - isNullable: false, - default: "'user'", - }, - { - name: 'isActive', - type: 'boolean', - default: true, - }, - { - name: 'createdAt', - type: 'timestamp', - default: 'CURRENT_TIMESTAMP', - }, - { - name: 'updatedAt', - type: 'timestamp', - default: 'CURRENT_TIMESTAMP', - onUpdate: 'CURRENT_TIMESTAMP', - }, - ], - }), - true, - ); - - // Create index on email - await queryRunner.createIndex( - 'users', - new TableIndex({ - name: 'idx_users_email', - columnNames: ['email'], - }), - ); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropIndex('users', 'idx_users_email'); - await queryRunner.dropTable('users'); - } -} diff --git a/src/database/seeds/run-seeds.ts b/src/database/seeds/run-seeds.ts index 8f1c84d..51654d2 100644 --- a/src/database/seeds/run-seeds.ts +++ b/src/database/seeds/run-seeds.ts @@ -1,4 +1,5 @@ import AppDataSource from '../data-source'; +import { seedUsers } from './users.seed'; import { seedCategories } from './categories.seed'; import { seedProducts } from './products.seed'; @@ -11,6 +12,10 @@ async function runSeeds() { console.log('✓ Database connection established\n'); // Run seeds in order + console.log('👥 Seeding users...'); + await seedUsers(AppDataSource); + console.log('✓ Users seeded successfully\n'); + console.log('📦 Seeding categories...'); await seedCategories(AppDataSource); console.log('✓ Categories seeded successfully\n'); diff --git a/src/modules/auth/auth.controller.ts b/src/modules/auth/auth.controller.ts index e5452af..17c8174 100644 --- a/src/modules/auth/auth.controller.ts +++ b/src/modules/auth/auth.controller.ts @@ -19,12 +19,14 @@ import { AuthService } from './auth.service'; import { LocalAuthGuard } from './guards/local-auth.guard'; import { JwtAuthGuard } from './guards/jwt-auth.guard'; import { LoginDto, RegisterDto, AuthResponseDto } from './dto'; +import { Public } from '../../common/decorators/public.decorator'; @ApiTags('Authentication') @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) {} + @Public() @Post('register') @HttpCode(HttpStatus.CREATED) @ApiOperation({ summary: 'Register a new user' }) @@ -45,6 +47,7 @@ export class AuthController { return this.authService.register(registerDto); } + @Public() @Post('login') @UseGuards(LocalAuthGuard) @HttpCode(HttpStatus.OK)