From fde00d6ad11b441b0ad3f469688a68f51ecfcf8b Mon Sep 17 00:00:00 2001 From: louis <869322496@qq.com> Date: Fri, 1 Mar 2024 16:54:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=88=E5=90=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E9=99=84=E4=BB=B6=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ src/modules/contract/contract.dto.ts | 3 ++- src/modules/contract/contract.service.ts | 26 +++++++++++++----------- 3 files changed, 24 insertions(+), 13 deletions(-) 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); }); }