import { Injectable } from "@nestjs/common"; import { InjectRepository } from "@nestjs/typeorm"; import { Resource } from "src/resource/entity/resource.entity"; import { Repository } from "typeorm"; @Injectable() export class AdminResourceService { constructor( @InjectRepository(Resource) private readonly resourceRepository: Repository, ) { } async findAll() { return this.resourceRepository.find({ order: { updatedAt: 'DESC', } }); } async findById(id: string): Promise { return this.resourceRepository.findOne({ where: { id } }); } async create(data: Partial): Promise { const resource = this.resourceRepository.create(data); return this.resourceRepository.save(resource); } async update(data: Partial): Promise { // const updateRes = await this.resourceRepository.update(id, data); // updateRes.affected // return this.resourceRepository.findOne({ where: { id } }); return this.resourceRepository.save(data); } async delete(id: string): Promise { await this.resourceRepository.delete(id); } }