feat: 新增图片资源上传和管理服务
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
ConflictException,
|
||||
Logger,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository, FindOptionsWhere } from 'typeorm';
|
||||
@@ -11,12 +12,16 @@ import { UpdateBrokerDto } from './dto/update-broker.dto';
|
||||
import { QueryBrokerDto } from './dto/query-broker.dto';
|
||||
import { BatchCreateBrokerDto } from './dto/batch-create-broker.dto';
|
||||
import { PaginationInfo } from '@/common/dto/pagination.dto';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
|
||||
@Injectable()
|
||||
export class BrokerService {
|
||||
private readonly logger = new Logger(BrokerService.name);
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Broker)
|
||||
private readonly brokerRepository: Repository<Broker>,
|
||||
private readonly storageService: StorageService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -290,9 +295,30 @@ export class BrokerService {
|
||||
|
||||
/**
|
||||
* 删除 broker
|
||||
* 同时删除券商Logo图片
|
||||
*/
|
||||
async remove(id: number): Promise<void> {
|
||||
const broker = await this.findOne(id);
|
||||
|
||||
// 删除券商Logo图片
|
||||
if (broker.brokerImage) {
|
||||
try {
|
||||
const imagePath = this.storageService.extractStoragePath(
|
||||
broker.brokerImage,
|
||||
);
|
||||
if (imagePath) {
|
||||
await this.storageService.delete(imagePath);
|
||||
this.logger.log(`已删除券商Logo: ${imagePath}`);
|
||||
}
|
||||
} catch (error) {
|
||||
// 图片删除失败不影响券商删除操作
|
||||
this.logger.warn(
|
||||
`删除券商Logo失败: ${broker.brokerImage}`,
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await this.brokerRepository.remove(broker);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user