File

src/resources/resources.service.ts

Index

Methods

Constructor

constructor(resourcesRp: Repository<ResourcesEntity>)
Parameters :
Name Type Optional
resourcesRp Repository<ResourcesEntity> No

Methods

Async deleteResources
deleteResources(id: any)
Parameters :
Name Type Optional
id any No
Returns : unknown
Async findAllResources
findAllResources()
Returns : unknown
Async findAllResourcesActive
findAllResourcesActive()
Returns : unknown
Async saveResource
saveResource(resources: any)
Parameters :
Name Type Optional
resources any No
Returns : unknown
Async updateResource
updateResource(id: number, resources: any)
Parameters :
Name Type Optional
id number No
resources any No
Returns : unknown
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'
import { ResourcesEntity } from 'src/database/entity/resources-entity/resources-entity';
import { ExceptionErrorMessage } from 'src/validation/exception-error';
import { Repository } from 'typeorm';


@Injectable()
export class ResourcesService {
    constructor(@InjectRepository(ResourcesEntity)
        private readonly resourcesRp:Repository<ResourcesEntity>){
    }
    //Guardar Recurso
    async saveResource(resources:any){
        try {
            return await this.resourcesRp.save(resources);
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }

    //Actualizar Recurso
    async updateResource(id:number, resources:any){
        try {
            await this.resourcesRp.update(id,resources);
            return await this.resourcesRp.findOneBy({id:id});
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }

    //Listar Categorias
    async findAllResources(){
        try {
            return await this.resourcesRp.find({order:{sort:'ASC'}});
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }

    //Listar Categorias
    async findAllResourcesActive(){
        try {
            return await this.resourcesRp.find({order:{sort:'ASC'},where:{status:true}});
        } catch (error) {
            ExceptionErrorMessage(error);            
        }
    }


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

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




results matching ""

    No results matching ""