refactor: 调整adminResource服务结构

This commit is contained in:
2025-12-19 19:02:10 +08:00
parent 89e99dc9e9
commit 586a2976d2
6 changed files with 64 additions and 26 deletions

View File

@@ -0,0 +1,38 @@
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<Resource>,
) { }
async findAll() {
return this.resourceRepository.find();
}
async findById(id: string): Promise<Resource> {
return this.resourceRepository.findOne({ where: { id } });
}
async create(data: Partial<Resource>): Promise<Resource> {
const resource = this.resourceRepository.create(data);
return this.resourceRepository.save(resource);
}
async update(data: Partial<Resource>): Promise<Resource> {
// 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<void> {
await this.resourceRepository.delete(id);
}
}