diff --git a/next/api/src/model/Ticket.ts b/next/api/src/model/Ticket.ts index 4e051f3f6..c941067e6 100644 --- a/next/api/src/model/Ticket.ts +++ b/next/api/src/model/Ticket.ts @@ -27,6 +27,7 @@ import { Organization } from './Organization'; import { Reply, TinyReplyInfo } from './Reply'; import { TinyUserInfo, User, systemUser } from './User'; import { Watch } from './Watch'; +import { TicketFieldValue } from './TicketFieldValue'; export class Status { // 0~99 未开始处理 @@ -228,6 +229,9 @@ export class Ticket extends Model { @field() closedAt?: Date; + @hasOneThroughPointer(() => TicketFieldValue) + fieldValue?: TicketFieldValue; + getUrlForEndUser() { return `${config.host}/tickets/${this.nid}`; } diff --git a/next/api/src/response/ticket.ts b/next/api/src/response/ticket.ts index d1dfe463f..eca27124b 100644 --- a/next/api/src/response/ticket.ts +++ b/next/api/src/response/ticket.ts @@ -14,6 +14,13 @@ export interface TicketResponseOptions { class BaseTicketResponse { constructor(readonly ticket: Ticket, private transferFile = false) {} + encodeFields() { + return this.ticket.fieldValue?.values.map((v) => ({ + id: v.field, + value: v.value, + })); + } + toJSON({ includeMetaKeys = [], includePrivateTags, includeTags }: TicketResponseOptions = {}) { return { id: this.ticket.id, @@ -40,6 +47,7 @@ class BaseTicketResponse { language: this.ticket.language, tags: includeTags ? this.ticket.tags : undefined, privateTags: includePrivateTags ? this.ticket.privateTags : undefined, + fields: this.encodeFields(), createdAt: this.ticket.createdAt.toISOString(), updatedAt: this.ticket.updatedAt.toISOString(), }; diff --git a/next/api/src/router/ticket.ts b/next/api/src/router/ticket.ts index 46e5f8831..2aba13ce8 100644 --- a/next/api/src/router/ticket.ts +++ b/next/api/src/router/ticket.ts @@ -49,6 +49,7 @@ const includeSchema = yup.object({ includeCategoryPath: yup.bool(), includeUnreadCount: yup.bool(), includeTag: yup.bool(), + includeFields: yup.bool(), }); export const ticketFiltersSchema = yup.object({ @@ -262,6 +263,11 @@ router.get( }, }); } + if (params.includeFields) { + finalQuery.preload('fieldValue', { + authOptions: { useMasterKey: true }, + }); + } let tickets: Ticket[]; if (params.count && !count) {