File

src/phrases/phrases.service.ts

Index

Methods

Constructor

constructor(phrasesRp: Repository<PhrasesEntity>)
Parameters :
Name Type Optional
phrasesRp Repository<PhrasesEntity> No

Methods

Async deletePhrase
deletePhrase(id: any)
Parameters :
Name Type Optional
id any No
Returns : unknown
Async findAllPhrase
findAllPhrase()
Returns : unknown
Async savePhrase
savePhrase(phrase: any)
Parameters :
Name Type Optional
phrase any No
Returns : unknown
Async updatePhrase
updatePhrase(id: number, phrase: any)
Parameters :
Name Type Optional
id number No
phrase any No
Returns : unknown
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { PhrasesEntity } from 'src/database/entity/phrases/phrases-entity';
import { ExceptionErrorMessage } from 'src/validation/exception-error';
import { Repository } from 'typeorm';

@Injectable()
export class PhrasesService {
    constructor(@InjectRepository(PhrasesEntity)
    private readonly phrasesRp:Repository<PhrasesEntity>){
    }

    //Guardar Frase
    async savePhrase(phrase:any){
        try {
            return await this.phrasesRp.save(phrase);
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }

    //Actualizar Frase
    async updatePhrase(id:number, phrase:any){
        try {
            await this.phrasesRp.update(id,phrase);
            return await this.phrasesRp.findOneBy({id:id});
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }


    
    //Listar Frases
    async findAllPhrase(){
        try {
            return await this.phrasesRp.find({order:{createdAt:'DESC'},take:10});
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }

    //Borrar Prensa
    async deletePhrase(id:any){
        try {
             await this.phrasesRp.delete({ id:id })
             return { message:"El registro seleccionado ha sido eliminado" };

        }
        catch(error){
            ExceptionErrorMessage(error);            
        }
    }
    

}

results matching ""

    No results matching ""