wangzhibo
6 天以前 7dcc2997614f849258091f5d66e648317a40d323
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Provide } from '@midwayjs/core';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { CsSessionEntity } from '../entity/session';
 
/**
 * 客服会话
 */
@Provide()
export class CsSessionService extends BaseService {
  @InjectEntityModel(CsSessionEntity)
  csSessionEntity: Repository<CsSessionEntity>;
 
  /**
   * 会话详情
   * @param userId
   */
  async detail(userId: number) {
    return await this.csSessionEntity.findOneBy({ userId });
  }
 
  /**
   * 创建会话
   * @param userId
   * @returns
   */
  async create(userId: number) {
    const check = await this.detail(userId);
    if (check) {
      return check;
    }
    const session = new CsSessionEntity();
    session.userId = userId;
    await this.csSessionEntity.insert(session);
    return session;
  }
}