Browse Source

✨ feat(contracts): add contract query features

- override getList method to support associated client information query by default
- add findByClientId method to query contract list by client ID
- add client relation query and sort by creation time in descending order for contract queries
yourname 8 months ago
parent
commit
7995059573
1 changed files with 27 additions and 0 deletions
  1. 27 0
      src/server/modules/contracts/hetong.service.ts

+ 27 - 0
src/server/modules/contracts/hetong.service.ts

@@ -6,4 +6,31 @@ export class HetongService extends GenericCrudService<Hetong> {
   constructor(dataSource: DataSource) {
     super(dataSource, Hetong);
   }
+  /**
+   * 重写getList方法,支持关联查询客户信息
+   */
+  async getList(
+    page: number = 1,
+    pageSize: number = 10,
+    keyword?: string,
+    searchFields?: string[],
+    where: Partial<Hetong> = {},
+    relations: string[] = ['client'], // 默认关联查询客户信息
+    order: { [P in keyof Hetong]?: 'ASC' | 'DESC' } = {}
+  ): Promise<[Hetong[], number]> {
+    return super.getList(page, pageSize, keyword, searchFields, where, relations, order);
+  }
+
+  /**
+   * 根据客户ID查询合同列表
+   * @param clientId 客户ID
+   * @returns 合同列表
+   */
+  async findByClientId(clientId: number): Promise<Hetong[]> {
+    return this.repository.find({
+      where: { clientId },
+      relations: ['client'], // 关联查询客户信息
+      order: { createdAt: 'DESC' }
+    });
+  }
 }