diff --git a/README.md b/README.md index a2a3f7b..a394936 100644 --- a/README.md +++ b/README.md @@ -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 \ No newline at end of file diff --git a/src/modules/contract/contract.dto.ts b/src/modules/contract/contract.dto.ts index 9b4ca8b..a1b7be7 100644 --- a/src/modules/contract/contract.dto.ts +++ b/src/modules/contract/contract.dto.ts @@ -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( diff --git a/src/modules/contract/contract.service.ts b/src/modules/contract/contract.service.ts index 59bcb22..6ff5b66 100644 --- a/src/modules/contract/contract.service.ts +++ b/src/modules/contract/contract.service.ts @@ -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); }); }