agent-list.service.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { Injectable } from '@nestjs/common'
  2. import { IAgentListService } from '@/interface/agent-list.interface'
  3. import { ServiceResponse } from '@/response/response.interface'
  4. import { BusinessCode, HttpStatusCode } from '@/response/status-code.enum'
  5. import { AgentListHttpService } from './agent-list-http.service'
  6. @Injectable()
  7. export class AgentListService implements IAgentListService {
  8. constructor(private readonly httpService: AgentListHttpService) {}
  9. async getNativeAgentList(
  10. params: Record<string, any>
  11. ): Promise<ServiceResponse<AgentListType[]>> {
  12. const { code, data, msg } =
  13. await this.httpService.getNativeAgentList(params)
  14. if (code !== HttpStatusCode.OK) {
  15. return {
  16. code: BusinessCode.BAD_REQUEST,
  17. msg: msg || '获取客服列表失败',
  18. data: null
  19. }
  20. }
  21. return {
  22. code: BusinessCode.SUCCESS,
  23. msg: '获取客服列表成功',
  24. data: data
  25. }
  26. }
  27. async getNativeAgentConfiguration(
  28. agentId: string
  29. ): Promise<ServiceResponse<AgentConfigurationType[]>> {
  30. const { code, data, msg } =
  31. await this.httpService.getNativeAgentConfiguration(agentId)
  32. if (code !== HttpStatusCode.OK) {
  33. return {
  34. code: BusinessCode.BAD_REQUEST,
  35. msg: msg || '获取客服列表失败',
  36. data: null
  37. }
  38. }
  39. return {
  40. code: BusinessCode.SUCCESS,
  41. msg: '获取客服列表成功',
  42. data: data
  43. }
  44. }
  45. async saveNativeAgentConfiguration(
  46. params: SaveAgentConfigurationType
  47. ): Promise<ServiceResponse<SaveAgentConfigurationType>> {
  48. const { code, data, msg } =
  49. await this.httpService.saveNativeAgentConfiguration(params)
  50. if (code !== HttpStatusCode.OK) {
  51. return {
  52. code: BusinessCode.BAD_REQUEST,
  53. msg: msg || '保存客服列表失败',
  54. data: null
  55. }
  56. }
  57. return {
  58. code: BusinessCode.SUCCESS,
  59. msg: '保存客服列表成功',
  60. data: data
  61. }
  62. }
  63. async getToolList(): Promise<ServiceResponse<any>> {
  64. const { code, data, msg } = await this.httpService.getToolList()
  65. if (code !== HttpStatusCode.OK) {
  66. return {
  67. code: BusinessCode.BAD_REQUEST,
  68. msg: msg || '获取工具列表失败',
  69. data: null
  70. }
  71. }
  72. return {
  73. code: BusinessCode.SUCCESS,
  74. msg: '获取工具列表成功',
  75. data: data
  76. }
  77. }
  78. async deleteNativeAgentConfiguration(
  79. agentId: number
  80. ): Promise<ServiceResponse<any>> {
  81. const { code, data, msg } =
  82. await this.httpService.deleteNativeAgentConfiguration(agentId)
  83. if (code !== HttpStatusCode.OK) {
  84. return {
  85. code: BusinessCode.BAD_REQUEST,
  86. msg: msg || '删除客服列表失败',
  87. data: null
  88. }
  89. }
  90. return {
  91. code: BusinessCode.SUCCESS,
  92. msg: '删除客服列表成功',
  93. data: data
  94. }
  95. }
  96. }