Se implemento la carga de banner con orden en automatico, asi como la funcion de poder actualizar el orden de los banner, ademas de algunas actualizaciones de dependencias, todo esto se probo y funciona correctamente, se mandan estos cambios por que es una version estable a la cual se puede actualizar antes de seguir actualizando las dependencias faltantes
This commit is contained in:
Generated
+748
-949
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 21 KiB |
+1
-1
@@ -76,7 +76,7 @@ import { TylController } from './tyl/tyl.controller';
|
||||
username: configService.get('DB_USER'),
|
||||
password: configService.get('DB_PASSWORD'),
|
||||
database: configService.get('DB_NAME'),
|
||||
synchronize: false,
|
||||
synchronize: true,
|
||||
entities: [
|
||||
Evento,
|
||||
Participante,
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Put,
|
||||
Res,
|
||||
UploadedFile,
|
||||
UseInterceptors,
|
||||
@@ -57,6 +58,11 @@ export class CarruselController {
|
||||
return this.carruselService.updateImagenCarrusel(id, carruselDto);
|
||||
}
|
||||
|
||||
@Put('updateOrden')
|
||||
async updateOrden(@Body() banners: { id: number; orden: number}[]) {
|
||||
return this.carruselService.updateOrden(banners);
|
||||
}
|
||||
|
||||
@Delete('delete/:id')
|
||||
deleteImagenByRuta(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.carruselService.deleteImagenByRuta(id);
|
||||
|
||||
@@ -41,23 +41,24 @@ export class CarruselService {
|
||||
carruselDto.ruta = `/public/carrusel/${filename}`;
|
||||
|
||||
// Obtener el banner con mayor orden
|
||||
const ultimoCarrusel = await this.carruselRepository.findOne({
|
||||
const ultimoCarrusel = await this.carruselRepository.find({
|
||||
order: {
|
||||
orden: 'DESC',
|
||||
},
|
||||
take: 1
|
||||
});
|
||||
|
||||
const siguienteOrden = ultimoCarrusel
|
||||
? ultimoCarrusel.orden + 1
|
||||
: 1;
|
||||
const ultimoOrden = ultimoCarrusel.length > 0 ? ultimoCarrusel[0].orden : 0;
|
||||
// const siguienteOrden = ultimoCarrusel
|
||||
// ? ultimoCarrusel.orden + 1
|
||||
// : 1;
|
||||
|
||||
// const carruselCreate = this.carruselRepository.create(carruselDto);
|
||||
const carruselCreate = this.carruselRepository.create({
|
||||
...carruselDto,
|
||||
orden: siguienteOrden,
|
||||
orden: ultimoOrden + 1,
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
const carrusel = await this.carruselRepository.save(carruselCreate);
|
||||
return {
|
||||
@@ -77,6 +78,8 @@ export class CarruselService {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async updateImagenCarrusel(
|
||||
id: number,
|
||||
carruselDto: carruselDto,
|
||||
@@ -112,6 +115,30 @@ export class CarruselService {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar todas las imagenes por orden
|
||||
async updateOrden(banners: { id: number; orden: number}[]) {
|
||||
// Paso 1.- Mandar los banner a un orden extremo para que no causen conflicto al actualizar
|
||||
for( const banner of banners ) {
|
||||
await this.carruselRepository.update(
|
||||
{ id_imagen_carrusel: banner.id },
|
||||
{ orden: banner.orden + 1000 },
|
||||
);
|
||||
}
|
||||
|
||||
// Paso 2.- Actualizamos al nuevo orden
|
||||
for (const banner of banners ) {
|
||||
await this.carruselRepository.update(
|
||||
{ id_imagen_carrusel: banner.id },
|
||||
{ orden: banner.orden },
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
message: 'Orden actualizado correctamente',
|
||||
}
|
||||
}
|
||||
|
||||
async deleteImagenByRuta(id: number) {
|
||||
try {
|
||||
const res = await this.carruselRepository.findOne({
|
||||
@@ -128,7 +155,13 @@ export class CarruselService {
|
||||
}
|
||||
|
||||
getAllImages(): Promise<Carrusel[]> {
|
||||
return this.carruselRepository.find();
|
||||
// return this.carruselRepository.find();
|
||||
return this.carruselRepository.find({
|
||||
order: {
|
||||
orden: 'ASC',
|
||||
},
|
||||
});
|
||||
// return this.carruselRepository.find();
|
||||
}
|
||||
|
||||
async deleteAllCarrusel(): Promise<{ message: string }> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsNotEmpty, IsOptional } from "class-validator";
|
||||
import { IsNotEmpty, IsOptional, IsNumber } from "class-validator";
|
||||
|
||||
export class carruselDto {
|
||||
@IsNotEmpty()
|
||||
@@ -7,7 +7,7 @@ export class carruselDto {
|
||||
@IsNotEmpty()
|
||||
link: string
|
||||
|
||||
// @IsNotEmpty() valida que no sea nulo ni undefined ni cadena vacía
|
||||
// @IsOptional()
|
||||
// orden?: string
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
orden?: number
|
||||
}
|
||||
@@ -14,5 +14,5 @@ export class Carrusel {
|
||||
/* "https://www.acatlan.unam.mx/" */
|
||||
|
||||
@Column({ type: 'int', unique: true })
|
||||
orden: string
|
||||
orden: number
|
||||
}
|
||||
@@ -54,6 +54,8 @@ export class ComentariosService {
|
||||
if (to) {
|
||||
query.andWhere('comentarios.fecha_registro <= :to', { to: new Date(to) });
|
||||
}
|
||||
|
||||
query.orderBy('comentarios.fecha_registro', 'DESC');
|
||||
|
||||
return await query.getMany();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@ export class EventosService {
|
||||
) {}
|
||||
|
||||
getEventos() {
|
||||
return this.eventoRepository.find();
|
||||
return this.eventoRepository.find({
|
||||
order: {
|
||||
fecha_inicio: 'DESC',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public getEventosPorId(id: number) {
|
||||
|
||||
Reference in New Issue
Block a user