runable
This commit is contained in:
@@ -28,10 +28,10 @@ export class PaginationDto {
|
||||
limit?: number = 20;
|
||||
|
||||
get skip(): number {
|
||||
return (this.page - 1) * this.limit;
|
||||
return ((this.page || 1) - 1) * (this.limit || 20);
|
||||
}
|
||||
|
||||
get take(): number {
|
||||
return this.limit;
|
||||
return this.limit || 20;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { Cache } from 'cache-manager';
|
||||
import type { Cache } from 'cache-manager';
|
||||
|
||||
@Injectable()
|
||||
export class CustomCacheInterceptor implements NestInterceptor {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
|
||||
export default registerAs('app', () => ({
|
||||
port: parseInt(process.env.PORT, 10) || 3000,
|
||||
port: parseInt(process.env.PORT || '', 10) || 3000,
|
||||
environment: process.env.NODE_ENV || 'development',
|
||||
apiPrefix: process.env.API_PREFIX || 'api',
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export default registerAs(
|
||||
(): TypeOrmModuleOptions => ({
|
||||
type: 'postgres',
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
port: parseInt(process.env.DB_PORT, 10) || 5432,
|
||||
port: parseInt(process.env.DB_PORT || '', 10) || 5432,
|
||||
username: process.env.DB_USERNAME || 'postgres',
|
||||
password: process.env.DB_PASSWORD || 'postgres',
|
||||
database: process.env.DB_DATABASE || 'retail_pos',
|
||||
@@ -20,9 +20,6 @@ export default registerAs(
|
||||
logging: process.env.NODE_ENV === 'development',
|
||||
migrations: ['dist/database/migrations/*.js'],
|
||||
migrationsRun: false, // Run migrations manually
|
||||
ssl:
|
||||
process.env.NODE_ENV === 'production'
|
||||
? { rejectUnauthorized: false }
|
||||
: false,
|
||||
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -2,10 +2,10 @@ import { registerAs } from '@nestjs/config';
|
||||
|
||||
export default registerAs('redis', () => ({
|
||||
host: process.env.REDIS_HOST || 'localhost',
|
||||
port: parseInt(process.env.REDIS_PORT, 10) || 6379,
|
||||
port: parseInt(process.env.REDIS_PORT || '', 10) || 6379,
|
||||
password: process.env.REDIS_PASSWORD || undefined,
|
||||
ttl: parseInt(process.env.CACHE_TTL, 10) || 300, // 5 minutes default
|
||||
max: parseInt(process.env.CACHE_MAX_ITEMS, 10) || 1000,
|
||||
ttl: parseInt(process.env.CACHE_TTL || '', 10) || 300, // 5 minutes default
|
||||
max: parseInt(process.env.CACHE_MAX_ITEMS || '', 10) || 1000,
|
||||
|
||||
// Cache strategy
|
||||
cache: {
|
||||
|
||||
@@ -12,7 +12,7 @@ config();
|
||||
export const dataSourceOptions: DataSourceOptions = {
|
||||
type: 'postgres',
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
port: parseInt(process.env.DB_PORT, 10) || 5432,
|
||||
port: parseInt(process.env.DB_PORT || '', 10) || 5432,
|
||||
username: process.env.DB_USERNAME || 'postgres',
|
||||
password: process.env.DB_PASSWORD || 'postgres',
|
||||
database: process.env.DB_DATABASE || 'retail_pos',
|
||||
|
||||
@@ -14,7 +14,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: configService.get<string>('JWT_SECRET'),
|
||||
secretOrKey: configService.get<string>('JWT_SECRET') || 'fallback-secret',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ export class CategoriesRepository {
|
||||
return this.repository.findOne({ where: { name } });
|
||||
}
|
||||
|
||||
async update(id: string, updateCategoryDto: UpdateCategoryDto): Promise<Category> {
|
||||
async update(id: string, updateCategoryDto: UpdateCategoryDto): Promise<Category | null> {
|
||||
await this.repository.update(id, updateCategoryDto);
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
@@ -72,18 +72,21 @@ export class CategoriesService {
|
||||
const total = category.products.length;
|
||||
const products = category.products.slice(skip, skip + take);
|
||||
|
||||
const limit = paginationDto.limit || 20;
|
||||
const page = paginationDto.page || 1;
|
||||
|
||||
return {
|
||||
...plainToClass(CategoryResponseDto, category, {
|
||||
excludeExtraneousValues: false,
|
||||
}),
|
||||
products,
|
||||
meta: {
|
||||
page: paginationDto.page,
|
||||
limit: paginationDto.limit,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / paginationDto.limit),
|
||||
hasPreviousPage: paginationDto.page > 1,
|
||||
hasNextPage: paginationDto.page < Math.ceil(total / paginationDto.limit),
|
||||
totalPages: Math.ceil(total / limit),
|
||||
hasPreviousPage: page > 1,
|
||||
hasNextPage: page < Math.ceil(total / limit),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Category } from '../../categories/entities/category.entity';
|
||||
import { TransactionItem } from '../../transactions/entities/transaction-item.entity';
|
||||
|
||||
@Entity('products')
|
||||
@Index(['name', 'categoryId'], { name: 'idx_products_name_category' })
|
||||
@Index('idx_products_name_category', ['name', 'categoryId'])
|
||||
export class Product {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@@ -31,7 +31,7 @@ export class UsersRepository {
|
||||
return this.repository.findOne({ where: { email } });
|
||||
}
|
||||
|
||||
async update(id: string, updateUserDto: UpdateUserDto): Promise<User> {
|
||||
async update(id: string, updateUserDto: UpdateUserDto): Promise<User | null> {
|
||||
await this.repository.update(id, updateUserDto);
|
||||
return this.findOne(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user