File

src/testimonials/testimonials.service.ts

Index

Methods

Constructor

constructor(testimonialRp: Repository<TestimonialsEntity>)
Parameters :
Name Type Optional
testimonialRp Repository<TestimonialsEntity> No

Methods

Async deleteTestimonial
deleteTestimonial(id: any)
Parameters :
Name Type Optional
id any No
Returns : unknown
Async findAllTestimonials
findAllTestimonials()
Returns : unknown
Async getTotalRows
getTotalRows()
Returns : unknown
Async getTwoRandomRows
getTwoRandomRows(id)
Parameters :
Name Optional
id No
Returns : unknown
Async saveTestimonial
saveTestimonial(testimonial: any)
Parameters :
Name Type Optional
testimonial any No
Returns : unknown
Async updateTestimonial
updateTestimonial(id: number, testimonial: any)
Parameters :
Name Type Optional
id number No
testimonial any No
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);            
        }
    }

}

results matching ""

    No results matching ""