run
This commit is contained in:
@@ -21,7 +21,7 @@ export const dataSourceOptions: DataSourceOptions = {
|
|||||||
synchronize: false, // Never use true in production
|
synchronize: false, // Never use true in production
|
||||||
logging: process.env.NODE_ENV === 'development',
|
logging: process.env.NODE_ENV === 'development',
|
||||||
ssl:
|
ssl:
|
||||||
process.env.NODE_ENV === 'production'
|
process.env.DB_SSL === 'true'
|
||||||
? { rejectUnauthorized: false }
|
? { rejectUnauthorized: false }
|
||||||
: false,
|
: false,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';
|
|
||||||
|
|
||||||
export class CreateUsersTable1704470000000 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
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<void> {
|
|
||||||
await queryRunner.dropIndex('users', 'idx_users_email');
|
|
||||||
await queryRunner.dropTable('users');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import AppDataSource from '../data-source';
|
import AppDataSource from '../data-source';
|
||||||
|
import { seedUsers } from './users.seed';
|
||||||
import { seedCategories } from './categories.seed';
|
import { seedCategories } from './categories.seed';
|
||||||
import { seedProducts } from './products.seed';
|
import { seedProducts } from './products.seed';
|
||||||
|
|
||||||
@@ -11,6 +12,10 @@ async function runSeeds() {
|
|||||||
console.log('✓ Database connection established\n');
|
console.log('✓ Database connection established\n');
|
||||||
|
|
||||||
// Run seeds in order
|
// Run seeds in order
|
||||||
|
console.log('👥 Seeding users...');
|
||||||
|
await seedUsers(AppDataSource);
|
||||||
|
console.log('✓ Users seeded successfully\n');
|
||||||
|
|
||||||
console.log('📦 Seeding categories...');
|
console.log('📦 Seeding categories...');
|
||||||
await seedCategories(AppDataSource);
|
await seedCategories(AppDataSource);
|
||||||
console.log('✓ Categories seeded successfully\n');
|
console.log('✓ Categories seeded successfully\n');
|
||||||
|
|||||||
@@ -19,12 +19,14 @@ import { AuthService } from './auth.service';
|
|||||||
import { LocalAuthGuard } from './guards/local-auth.guard';
|
import { LocalAuthGuard } from './guards/local-auth.guard';
|
||||||
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
import { JwtAuthGuard } from './guards/jwt-auth.guard';
|
||||||
import { LoginDto, RegisterDto, AuthResponseDto } from './dto';
|
import { LoginDto, RegisterDto, AuthResponseDto } from './dto';
|
||||||
|
import { Public } from '../../common/decorators/public.decorator';
|
||||||
|
|
||||||
@ApiTags('Authentication')
|
@ApiTags('Authentication')
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authService: AuthService) {}
|
constructor(private readonly authService: AuthService) {}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Post('register')
|
@Post('register')
|
||||||
@HttpCode(HttpStatus.CREATED)
|
@HttpCode(HttpStatus.CREATED)
|
||||||
@ApiOperation({ summary: 'Register a new user' })
|
@ApiOperation({ summary: 'Register a new user' })
|
||||||
@@ -45,6 +47,7 @@ export class AuthController {
|
|||||||
return this.authService.register(registerDto);
|
return this.authService.register(registerDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Public()
|
||||||
@Post('login')
|
@Post('login')
|
||||||
@UseGuards(LocalAuthGuard)
|
@UseGuards(LocalAuthGuard)
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user