fix: 合同更新时附件的处理

This commit is contained in:
louis 2024-03-01 16:54:21 +08:00
parent 24309f47d2
commit fde00d6ad1
3 changed files with 24 additions and 13 deletions

View File

@ -94,9 +94,17 @@ pnpm migration:generate
```bash
pnpm migration:revert
```
4.执行sql覆盖docker中的数据库
```bash
docker exec -i huaxin-admin-mysql mysql -h 127.0.0.1 -u root -phuaxin123 hxoa < hxoa20240301.sql
```
更多细节,请移步至[官方文档](https://typeorm.io/migrations)
> [!TIP]
> 如果你的`实体类`或`数据库配置`有更新,请执行`npm run build`后再进行数据库迁移相关操作。
### 部署
chmod +x deploy.sh
./deploy.sh

View File

@ -54,7 +54,8 @@ export class ContractDto {
export class ContractUpdateDto extends PartialType(ContractDto) {
@ApiProperty({ description: '附件' })
@IsArray({})
@IsOptional()
@IsArray()
fileIds: number[];
}
export class ContractQueryDto extends IntersectionType(

View File

@ -68,19 +68,21 @@ export class ContractService {
.leftJoinAndSelect('contract.files', 'files')
.where('contract.id = :id', { id })
.getOne();
const count = await this.storageRepository
.createQueryBuilder('storage')
.where('storage.id in(:fileIds)', { fileIds })
.getCount();
if (count !== fileIds?.length) {
throw new BusinessException(ErrorEnum.STORAGE_NOT_FOUND);
if (fileIds?.length) {
const count = await this.storageRepository
.createQueryBuilder('storage')
.where('storage.id in(:fileIds)', { fileIds })
.getCount();
if (count !== fileIds?.length) {
throw new BusinessException(ErrorEnum.STORAGE_NOT_FOUND);
}
// 附件要批量更新
await manager
.createQueryBuilder()
.relation(ContractEntity, 'files')
.of(id)
.addAndRemove(fileIds, contract.files);
}
// 附件要批量更新
await manager
.createQueryBuilder()
.relation(ContractEntity, 'files')
.of(id)
.addAndRemove(fileIds, contract.files);
});
}