agregado Scroll infinito para las encuestas
This commit is contained in:
@@ -3,7 +3,7 @@ import { Inject, Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||
import * as schema from 'src/database/index';
|
||||
import { products, viewProductsStore } from 'src/database/index';
|
||||
import { eq, like, or, SQL, sql, and, not } from 'drizzle-orm';
|
||||
import { eq, like, or, SQL, sql, and, not, ne } from 'drizzle-orm';
|
||||
import { CreateProductDto } from './dto/create-product.dto';
|
||||
import { UpdateProductDto } from './dto/update-product.dto';
|
||||
import { Product, Store, Inventory } from './entities/inventory.entity';
|
||||
@@ -28,12 +28,21 @@ export class InventoryService {
|
||||
let searchCondition: SQL<unknown> | undefined;
|
||||
|
||||
if (search) {
|
||||
searchCondition = and(or(
|
||||
like(products.title, `%${search}%`),
|
||||
like(products.description, `%${search}%`),
|
||||
), eq(products.userId, id));
|
||||
searchCondition = and(
|
||||
or(
|
||||
like(products.title, `%${search}%`),
|
||||
like(products.description, `%${search}%`),
|
||||
),
|
||||
and(
|
||||
eq(products.userId, id),
|
||||
ne(products.status, 'ELIMINADO')
|
||||
)
|
||||
)
|
||||
} else {
|
||||
searchCondition = eq(products.userId, id);
|
||||
searchCondition = and(
|
||||
eq(products.userId, id),
|
||||
ne(products.status, 'ELIMINADO')
|
||||
)
|
||||
}
|
||||
|
||||
// Build sort condition
|
||||
@@ -98,7 +107,7 @@ export class InventoryService {
|
||||
like(viewProductsStore.title, `%${search}%`),
|
||||
like(viewProductsStore.description, `%${search}%`)
|
||||
),
|
||||
or(eq(viewProductsStore.status, 'PUBLICADO'), eq(viewProductsStore.status, 'AGOTADO'))
|
||||
and(ne(viewProductsStore.status, 'BORRADOR'), ne(viewProductsStore.status, 'ELIMINADO'))
|
||||
)
|
||||
} else if (search) {
|
||||
or(
|
||||
@@ -106,7 +115,7 @@ export class InventoryService {
|
||||
like(viewProductsStore.description, `%${search}%`)
|
||||
)
|
||||
} else if (isStore) {
|
||||
searchCondition = or(eq(viewProductsStore.status, 'PUBLICADO'), eq(viewProductsStore.status, 'AGOTADO'))
|
||||
searchCondition = and(ne(viewProductsStore.status, 'BORRADOR'), ne(viewProductsStore.status, 'ELIMINADO'))
|
||||
}
|
||||
|
||||
// Build sort condition
|
||||
@@ -177,7 +186,7 @@ export class InventoryService {
|
||||
phone: viewProductsStore.phone
|
||||
})
|
||||
.from(viewProductsStore)
|
||||
.where(eq(viewProductsStore.id, id));
|
||||
.where(and(eq(viewProductsStore.id, id), ne(viewProductsStore.status, 'ELIMINADO')));
|
||||
|
||||
if (find.length === 0) {
|
||||
throw new HttpException('Product does not exist', HttpStatus.NOT_FOUND);
|
||||
@@ -290,23 +299,21 @@ export class InventoryService {
|
||||
}
|
||||
|
||||
async remove(productId: number, userId: number): Promise<{ message: string }> {
|
||||
const picturesPath = join(__dirname, '..', '..', '..', '..', 'web', 'public', 'uploads', 'inventory', userId.toString() , productId.toString());
|
||||
// const picturesPath = join(__dirname, '..', '..', '..', '..', 'web', 'public', 'uploads', 'inventory', userId.toString() , productId.toString());
|
||||
|
||||
try {
|
||||
// Borra el directorio y todos sus contenidos de forma recursiva y forzada.
|
||||
await rm(picturesPath, { recursive: true, force: true });
|
||||
} catch (error) {
|
||||
// Es buena práctica manejar el error, aunque `force: true` lo hace menos probable.
|
||||
// Podrías registrar el error, pero no detener la ejecución.
|
||||
console.error(`No se pudo eliminar el directorio ${picturesPath}:`, error);
|
||||
}
|
||||
// try {
|
||||
// // Borra el directorio y todos sus contenidos de forma recursiva y forzada.
|
||||
// await rm(picturesPath, { recursive: true, force: true });
|
||||
// } catch (error) {
|
||||
// console.error(`No se pudo eliminar el directorio ${picturesPath}:`, error);
|
||||
// }
|
||||
|
||||
// Check if exists
|
||||
await this.findOne(productId);
|
||||
|
||||
// Delete user (this will cascade delete related records due to foreign key constraints)
|
||||
await this.drizzle.delete(products).where(eq(products.id, productId));
|
||||
// await this.drizzle.update(products).set({ status: 'ELIMINADO' }).where(eq(products.id, productId));
|
||||
// await this.drizzle.delete(products).where(eq(products.id, productId));
|
||||
await this.drizzle.update(products).set({ status: 'ELIMINADO' }).where(eq(products.id, productId));
|
||||
|
||||
return { message: 'Product deleted successfully' };
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
||||
import * as schema from '@/database/index';
|
||||
import { CreateSurveyDto } from './dto/create-survey.dto';
|
||||
import { UpdateSurveyDto } from './dto/update-survey.dto';
|
||||
import { and, count, eq, ilike, isNull, or, sql } from 'drizzle-orm';
|
||||
import { and, count, eq, ilike, isNull, like, or, sql } from 'drizzle-orm';
|
||||
import { SurveyDetailDto, SurveyStatisticsResponseDto } from './dto/statistics-response.dto';
|
||||
import { PaginationDto } from '@/common/dto/pagination.dto';
|
||||
import { AnswersSurveyDto } from './dto/response-survey.dto';
|
||||
@@ -92,7 +92,15 @@ export class SurveysService {
|
||||
// }
|
||||
|
||||
if (findForUserDto.rol[0].rol !== 'superadmin' && findForUserDto.rol[0].rol !== 'admin') {
|
||||
searchCondition = or(eq(surveys.targetAudience, findForUserDto.rol[0].rol), eq(surveys.targetAudience, 'all'))
|
||||
searchCondition = and(
|
||||
or(
|
||||
eq(surveys.targetAudience, findForUserDto.rol[0].rol),
|
||||
eq(surveys.targetAudience, 'all')
|
||||
),
|
||||
like(surveys.title, `%${search}%`)
|
||||
)
|
||||
} else {
|
||||
searchCondition = like(surveys.title, `%${search}%`)
|
||||
}
|
||||
|
||||
// console.log(searchCondition);
|
||||
|
||||
Reference in New Issue
Block a user