Skip to content

Commit

Permalink
feat(next/api): new ticket duration metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Mar 22, 2024
1 parent d8e8c5f commit 1c1a5b6
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 110 deletions.
38 changes: 38 additions & 0 deletions next/api/src/service/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ACLBuilder } from '@/orm';
import { User } from '@/model/User';
import { Ticket } from '@/model/Ticket';
import { Reply } from '@/model/Reply';
import { Action, OpsLog } from '@/model/OpsLog';
import { userService } from '@/user/services/user';
import { createQueue, Job, Queue } from '@/queue';
import { DetectTicketLanguageJobData } from '@/interfaces/ticket';
Expand All @@ -15,15 +16,32 @@ import { translateService } from './translate';
interface GetRepliesOptions {
author?: boolean;
files?: boolean;

/**
* Should include internal replies
*/
internal?: boolean;

/**
* Should include deleted replies
*/
deleted?: boolean;

skip?: number;
limit?: number;
cursor?: Date;
desc?: boolean;
count?: boolean;
}

interface GetOpsLogsOptions {
actions?: Action[];
skip?: number;
limit?: number;
cursor?: Date;
desc?: boolean;
}

interface TransferTicketJobData {
sourceUserId: string;
targetUserId: string;
Expand Down Expand Up @@ -92,6 +110,26 @@ export class TicketService {
return query.find({ useMasterKey: true });
}

async getOpsLogs(ticketId: string, options: GetOpsLogsOptions = {}) {
const query = OpsLog.queryBuilder()
.where('ticket', '==', Ticket.ptr(ticketId))
.limit(options.limit || 10)
.orderBy('createdAt', options.desc ? 'desc' : 'asc');
if (options.actions?.length) {
query.where('action', 'in', options.actions);
}
if (options.cursor) {
if (options.desc) {
query.where('createdAt', '<', options.cursor);
} else {
query.where('createdAt', '>', options.cursor);
}
} else if (options.skip) {
query.skip(options.skip);
}
return query.find({ useMasterKey: true });
}

async isTicketEvaluable(ticket: Ticket) {
if (!ticket.closedAt) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions next/api/src/ticket/TicketUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TinyReplyInfo } from '@/model/Reply';
import { TicketLog } from '@/model/TicketLog';
import { searchTicketService } from '@/service/search-ticket';
import htmlify from '@/utils/htmlify';
import { durationMetricsService } from './services/duration-metrics';

export interface UpdateOptions {
useMasterKey?: boolean;
Expand Down Expand Up @@ -354,6 +355,9 @@ export class TicketUpdater {
}

await searchTicketService.addSyncJob([ticket.id]);
if (this.data.status && ticket.isClosed()) {
durationMetricsService.createCreateMetricsJob({ ticketId: ticket.id });
}

return ticket;
}
Expand Down
109 changes: 0 additions & 109 deletions next/api/src/ticket/services/duration-metric.ts

This file was deleted.

Loading

0 comments on commit 1c1a5b6

Please sign in to comment.