src/category/category.service.ts
Methods |
|
constructor(categoryRp: Repository<CategoryEntity>)
|
||||||
Defined in src/category/category.service.ts:7
|
||||||
Parameters :
|
Async deleteCategory | ||||||
deleteCategory(id: any)
|
||||||
Defined in src/category/category.service.ts:53
|
||||||
Parameters :
Returns :
unknown
|
Async findAllCategorys |
findAllCategorys()
|
Defined in src/category/category.service.ts:32
|
Returns :
unknown
|
Async findAllCategorysActive |
findAllCategorysActive()
|
Defined in src/category/category.service.ts:42
|
Returns :
unknown
|
Async saveCategory | ||||||
saveCategory(category: any)
|
||||||
Defined in src/category/category.service.ts:13
|
||||||
Parameters :
Returns :
unknown
|
Async updateCategory |
updateCategory(id: number, category: any)
|
Defined in src/category/category.service.ts:22
|
Returns :
unknown
|
import { Injectable } from '@nestjs/common';
import { InjectRepository} from '@nestjs/typeorm'
import { Repository } from 'typeorm';
import { CategoryEntity } from 'src/database/entity/category-entity/category-entity';
import { ExceptionErrorMessage } from 'src/validation/exception-error';
@Injectable()
export class CategoryService {
constructor(@InjectRepository(CategoryEntity)
private readonly categoryRp:Repository<CategoryEntity>){
}
//Guardar Categoria
async saveCategory(category:any){
try {
return await this.categoryRp.save(category);
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Actualizar Categoria
async updateCategory(id:number, category:any){
try {
await this.categoryRp.update(id,category);
return await this.categoryRp.findOneBy({id:id});
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Listar Categorias
async findAllCategorys(){
try {
return await this.categoryRp.find({order:{createdAt:'DESC'}});
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Listar Categorias
async findAllCategorysActive(){
try {
return await this.categoryRp.find({order:{name:'ASC'},where:{status:true}});
} catch (error) {
ExceptionErrorMessage(error);
}
}
//Borrar Categoria
async deleteCategory(id:any){
try {
await this.categoryRp.createQueryBuilder()
.update(CategoryEntity)
.set({ status: false})
.where("id = :id", { id: id})
.execute();
return {message:"Se ha modificado el registro seleccionado"};
}
catch(error){
ExceptionErrorMessage(error);
}
}
}