fix: 合同更新时附件的处理
This commit is contained in:
parent
24309f47d2
commit
fde00d6ad1
|
@ -94,9 +94,17 @@ pnpm migration:generate
|
||||||
```bash
|
```bash
|
||||||
pnpm migration:revert
|
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)
|
更多细节,请移步至[官方文档](https://typeorm.io/migrations)
|
||||||
|
|
||||||
> [!TIP]
|
> [!TIP]
|
||||||
> 如果你的`实体类`或`数据库配置`有更新,请执行`npm run build`后再进行数据库迁移相关操作。
|
> 如果你的`实体类`或`数据库配置`有更新,请执行`npm run build`后再进行数据库迁移相关操作。
|
||||||
|
|
||||||
|
### 部署
|
||||||
|
chmod +x deploy.sh
|
||||||
|
./deploy.sh
|
|
@ -54,7 +54,8 @@ export class ContractDto {
|
||||||
|
|
||||||
export class ContractUpdateDto extends PartialType(ContractDto) {
|
export class ContractUpdateDto extends PartialType(ContractDto) {
|
||||||
@ApiProperty({ description: '附件' })
|
@ApiProperty({ description: '附件' })
|
||||||
@IsArray({})
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
fileIds: number[];
|
fileIds: number[];
|
||||||
}
|
}
|
||||||
export class ContractQueryDto extends IntersectionType(
|
export class ContractQueryDto extends IntersectionType(
|
||||||
|
|
|
@ -68,19 +68,21 @@ export class ContractService {
|
||||||
.leftJoinAndSelect('contract.files', 'files')
|
.leftJoinAndSelect('contract.files', 'files')
|
||||||
.where('contract.id = :id', { id })
|
.where('contract.id = :id', { id })
|
||||||
.getOne();
|
.getOne();
|
||||||
const count = await this.storageRepository
|
if (fileIds?.length) {
|
||||||
.createQueryBuilder('storage')
|
const count = await this.storageRepository
|
||||||
.where('storage.id in(:fileIds)', { fileIds })
|
.createQueryBuilder('storage')
|
||||||
.getCount();
|
.where('storage.id in(:fileIds)', { fileIds })
|
||||||
if (count !== fileIds?.length) {
|
.getCount();
|
||||||
throw new BusinessException(ErrorEnum.STORAGE_NOT_FOUND);
|
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);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue