fix: bug in the sliders and blog module
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
|
||||
import { SliderMessage } from "../../../common/enums/message.enum";
|
||||
import { CreateSliderDto } from "../DTO/create-slider.dto";
|
||||
import { UpdateSliderDto } from "../DTO/update-slider.dto";
|
||||
import { Slider } from "../entities/slider.entity";
|
||||
|
||||
@Injectable()
|
||||
export class SliderService {
|
||||
constructor(
|
||||
@InjectRepository(Slider)
|
||||
private readonly sliderRepository: Repository<Slider>,
|
||||
) {}
|
||||
|
||||
async create(createSliderDto: CreateSliderDto): Promise<Slider> {
|
||||
const slider = this.sliderRepository.create(createSliderDto);
|
||||
return await this.sliderRepository.save(slider);
|
||||
}
|
||||
|
||||
async findAll(): Promise<Slider[]> {
|
||||
return await this.sliderRepository.find({
|
||||
order: {
|
||||
order: "ASC",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getSliderById(id: string): Promise<Slider> {
|
||||
const slider = await this.sliderRepository.findOne({ where: { id } });
|
||||
if (!slider) {
|
||||
throw new NotFoundException(SliderMessage.SLIDER_NOT_FOUND);
|
||||
}
|
||||
return slider;
|
||||
}
|
||||
|
||||
async update(id: string, updateSliderDto: UpdateSliderDto): Promise<Slider> {
|
||||
const slider = await this.getSliderById(id);
|
||||
Object.assign(slider, updateSliderDto);
|
||||
return await this.sliderRepository.save(slider);
|
||||
}
|
||||
|
||||
async remove(id: string): Promise<void> {
|
||||
const slider = await this.getSliderById(id);
|
||||
await this.sliderRepository.remove(slider);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user