Modificaciones en los archivos de carrusel, entity, controller, servicio, se agrego un nuevo endpoint para actualizar los banner y se agrego un campo de orden en la entity
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 194 KiB |
@@ -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);
|
||||
|
||||
@@ -95,6 +95,21 @@ export class CarruselService {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar todas las imagenes por orden
|
||||
async updateOrden(banners: { id: number; orden: number}[]) {
|
||||
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({
|
||||
@@ -112,12 +127,12 @@ export class CarruselService {
|
||||
|
||||
getAllImages(): Promise<Carrusel[]> {
|
||||
// return this.carruselRepository.find();
|
||||
// return this.carruselRepository.find({
|
||||
// order: {
|
||||
// orden: 'ASC',
|
||||
// },
|
||||
// });
|
||||
return this.carruselRepository.find();
|
||||
return this.carruselRepository.find({
|
||||
order: {
|
||||
orden: 'ASC',
|
||||
},
|
||||
});
|
||||
// return this.carruselRepository.find();
|
||||
}
|
||||
|
||||
async deleteAllCarrusel(): Promise<{ message: string }> {
|
||||
|
||||
@@ -7,7 +7,7 @@ export class carruselDto {
|
||||
@IsNotEmpty()
|
||||
link: string
|
||||
|
||||
// @IsOptional()
|
||||
// @IsNumber()
|
||||
// orden?: number
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
orden?: number
|
||||
}
|
||||
@@ -13,6 +13,6 @@ export class Carrusel {
|
||||
link: string
|
||||
/* "https://www.acatlan.unam.mx/" */
|
||||
|
||||
// @Column({ type: 'int', default: 0 })
|
||||
// orden: number
|
||||
@Column({ type: 'int', default: 0 })
|
||||
orden: number
|
||||
}
|
||||
Reference in New Issue
Block a user