src/testimonials/testimonials.service.ts
Methods |
|
constructor(testimonialRp: Repository<TestimonialsEntity>)
|
||||||
Defined in src/testimonials/testimonials.service.ts:8
|
||||||
Parameters :
|
Async deleteTestimonial | ||||||
deleteTestimonial(id: any)
|
||||||
Defined in src/testimonials/testimonials.service.ts:39
|
||||||
Parameters :
Returns :
unknown
|
Async findAllTestimonials |
findAllTestimonials()
|
Defined in src/testimonials/testimonials.service.ts:30
|
Returns :
unknown
|
Async getTotalRows |
getTotalRows()
|
Defined in src/testimonials/testimonials.service.ts:51
|
Returns :
unknown
|
Async getTwoRandomRows | ||||
getTwoRandomRows(id)
|
||||
Defined in src/testimonials/testimonials.service.ts:60
|
||||
Parameters :
Returns :
unknown
|
Async saveTestimonial | ||||||
saveTestimonial(testimonial: any)
|
||||||
Defined in src/testimonials/testimonials.service.ts:13
|
||||||
Parameters :
Returns :
unknown
|
Async updateTestimonial |
updateTestimonial(id: number, testimonial: any)
|
Defined in src/testimonials/testimonials.service.ts:21
|
Returns :
unknown
|
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TestimonialsEntity } from 'src/database/entity/testimonials-entity/testimonials-entity';
import { ExceptionErrorMessage } from 'src/validation/exception-error';
import { Repository } from 'typeorm';
@Injectable()
export class TestimonialsService {
constructor(@InjectRepository(TestimonialsEntity)
private readonly testimonialRp:Repository<TestimonialsEntity>){
}
//Guardar Testimonio
async saveTestimonial(testimonial:any){
try {
return await this.testimonialRp.save(testimonial);
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Actualizar Testimonio
async updateTestimonial(id:number, testimonial:any){
try {
await this.testimonialRp.update(id,testimonial);
return await this.testimonialRp.findOneBy({id:id});
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Listar Testimonio
async findAllTestimonials(){
try {
return await this.testimonialRp.find({order:{createdAt:'DESC'}});
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Borrar Testimonio
async deleteTestimonial(id:any){
try {
await this.testimonialRp.delete({id:id});
return { message:"El registro seleccionado ha sido eliminado" };
}
catch(error){
ExceptionErrorMessage(error);
}
}
//Obtener el numero total de Filas
async getTotalRows(){
try {
return await this.testimonialRp.count();
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Obtener 2 registros aleatorios
async getTwoRandomRows(id){
try {
return await this.testimonialRp.find({where:[
{id:id[0],status:true},
{id:id[1],status:true},
]})
} catch (error) {
ExceptionErrorMessage(error);
}
}
}