Ver código fonte

修改查询

zs 10 meses atrás
pai
commit
7b9bcb479e

+ 1 - 1
src/service/platform/match.service.ts

@@ -18,7 +18,7 @@ export class MatchService extends BaseService<Match> {
     const data = { userInfo: {}, is_collection: false };
     // const arr = await this.model.findById(id).lean();
     const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'id')) {
+    if (arr && get(arr, 'id') && user) {
       // 查询是否收藏该比赛
       // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
       const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });

+ 1 - 1
src/service/system/dept.service.ts

@@ -9,7 +9,7 @@ export class DeptService extends BaseService<Dept> {
   @InjectEntityModel(Dept)
   model: Repository<Dept>;
   async queryAll() {
-    const data = await this.model.find({ order: { order_num: 1 } });
+    const data = await this.model.find({ order: { order_num: 'DESC' } });
     let treeData = data.filter(f => !f.parent_id);
     treeData = this.treeData(data, treeData);
     return treeData;

+ 7 - 6
src/service/users/company.service.ts

@@ -3,13 +3,14 @@ import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
 import { BaseService } from '../../frame/BaseService';
 import { Company } from '../../entity/users/company.entity';
+import { Collection } from '../../entity/platform/collection.entity';
 import { get, pick } from 'lodash';
 @Provide()
 export class CompanyService extends BaseService<Company> {
   @InjectEntityModel(Company)
   model: Repository<Company>;
-  // @InjectEntityModel(Collection)
-  // cModel: Repository<Collection>;
+  @InjectEntityModel(Collection)
+  cModel: Repository<Collection>;
 
   // 企业列表
   async list(query) {
@@ -39,14 +40,14 @@ export class CompanyService extends BaseService<Company> {
 
   // 企业详情
   async detail(id) {
-    // const user = this.ctx.user;
+    const user = this.ctx.user;
     const data = { is_collection: false };
     // const arr = await this.model.findById(id).lean();
     const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'id')) {
+    if (arr && get(arr, 'id') && user) {
       // TODO: 查询是否收藏该企业
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      // if (collection) data.is_collection = true;
+      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
+      if (collection) data.is_collection = true;
     }
     return { ...arr, ...data };
   }

+ 7 - 7
src/service/users/expert.service.ts

@@ -2,6 +2,7 @@ import { Provide } from '@midwayjs/core';
 import { InjectEntityModel } from '@midwayjs/typeorm';
 import { Equal, In, Repository } from 'typeorm';
 import { BaseService } from '../../frame/BaseService';
+import { Collection } from '../../entity/platform/collection.entity';
 import { Expert } from '../../entity/users/expert.entity';
 import { get, pick } from 'lodash';
 @Provide()
@@ -9,8 +10,8 @@ export class ExpertService extends BaseService<Expert> {
   @InjectEntityModel(Expert)
   model: Repository<Expert>;
 
-  // @InjectEntityModel(Collection)
-  // cModel: Repository<Collection>;
+  @InjectEntityModel(Collection)
+  cModel: Repository<Collection>;
 
   // 企业列表
   async list(query: any) {
@@ -31,14 +32,13 @@ export class ExpertService extends BaseService<Expert> {
 
   // 企业详情
   async detail(id) {
-    // const user = this.ctx.user;
+    const user = this.ctx.user;
     const data = { is_collection: false };
-    // const arr = await this.model.findById(id).lean();
     const arr = await this.model.findOne({ where: { id: Equal(id) } });
-    if (arr && get(arr, 'id')) {
+    if (arr && get(arr, 'id') && user) {
       // TODO: 查询是否收藏该企业
-      // const collection = await this.cModel.findOne({ user: user._id, source: arr._id }).lean();
-      // if (collection) data.is_collection = true;
+      const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
+      if (collection) data.is_collection = true;
     }
     return { ...arr, ...data };
   }