Skip to content
Snippets Groups Projects
Unverified Commit 9771ee67 authored by Kevin Aleman's avatar Kevin Aleman Committed by GitHub
Browse files

Chore: Type omnichannel models (#23758)

parent f1ce17dd
No related merge requests found
Showing
with 235 additions and 73 deletions
......@@ -71,7 +71,7 @@ export async function findDepartmentsToAutocomplete({ uid, selector, onlyMyDepar
let { conditions = {} } = selector;
const options = {
fields: {
projection: {
_id: 1,
name: 1,
},
......
......@@ -111,7 +111,7 @@ export async function findVisitorsToAutocomplete({ userId, selector }) {
const { exceptions = [], conditions = {} } = selector;
const options = {
fields: {
projection: {
_id: 1,
name: 1,
username: 1,
......
import moment from 'moment';
import { AggregationCursor } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { ILivechatAgentActivity } from '../../../../definition/ILivechatAgentActivity';
export class LivechatAgentActivityRaw extends BaseRaw {
findAllAverageAvailableServiceTime({ date, departmentId }) {
export class LivechatAgentActivityRaw extends BaseRaw<ILivechatAgentActivity> {
findAllAverageAvailableServiceTime({ date, departmentId }: { date: Date; departmentId: string }): Promise<ILivechatAgentActivity[]> {
const match = { $match: { date } };
const lookup = {
$lookup: {
......@@ -56,7 +58,7 @@ export class LivechatAgentActivityRaw extends BaseRaw {
},
},
};
const params = [match];
const params = [match] as object[];
if (departmentId && departmentId !== 'undefined') {
params.push(lookup);
params.push(unwind);
......@@ -67,7 +69,19 @@ export class LivechatAgentActivityRaw extends BaseRaw {
return this.col.aggregate(params).toArray();
}
findAvailableServiceTimeHistory({ start, end, fullReport, onlyCount = false, options = {} }) {
findAvailableServiceTimeHistory({
start,
end,
fullReport,
onlyCount = false,
options = {},
}: {
start: string;
end: string;
fullReport: boolean;
onlyCount: boolean;
options: any;
}): AggregationCursor<ILivechatAgentActivity> {
const match = {
$match: {
date: {
......@@ -101,13 +115,12 @@ export class LivechatAgentActivityRaw extends BaseRaw {
_id: 0,
username: '$_id.username',
availableTimeInSeconds: 1,
...fullReport && { serviceHistory: 1 },
},
};
if (fullReport) {
project.$project.serviceHistory = 1;
}
const sort = { $sort: options.sort || { username: 1 } };
const params = [match, lookup, unwind, group, project, sort];
const params = [match, lookup, unwind, group, project, sort] as object[];
if (onlyCount) {
params.push({ $count: 'total' });
return this.col.aggregate(params);
......
import { BaseRaw } from './BaseRaw';
export class LivechatCustomFieldRaw extends BaseRaw {
}
import { BaseRaw } from './BaseRaw';
import { ILivechatCustomField } from '../../../../definition/ILivechatCustomField';
export class LivechatCustomFieldRaw extends BaseRaw<ILivechatCustomField> {
}
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { FindOneOptions, Cursor, FilterQuery, WriteOpResult } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { ILivechatDepartmentRecord } from '../../../../definition/ILivechatDepartmentRecord';
export class LivechatDepartmentRaw extends BaseRaw {
findInIds(departmentsIds, options) {
export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartmentRecord> {
findInIds(departmentsIds: string[], options: FindOneOptions<ILivechatDepartmentRecord>): Cursor<ILivechatDepartmentRecord> {
const query = { _id: { $in: departmentsIds } };
return this.find(query, options);
}
findByNameRegexWithExceptionsAndConditions(searchTerm, exceptions = [], conditions = {}, options = {}) {
findByNameRegexWithExceptionsAndConditions(searchTerm: string, exceptions: string[] = [], conditions: FilterQuery<ILivechatDepartmentRecord> = {}, options: FindOneOptions<ILivechatDepartmentRecord> = {}): Cursor<ILivechatDepartmentRecord> {
if (!Array.isArray(exceptions)) {
exceptions = [exceptions];
}
......@@ -26,17 +28,17 @@ export class LivechatDepartmentRaw extends BaseRaw {
return this.find(query, options);
}
findByBusinessHourId(businessHourId, options) {
findByBusinessHourId(businessHourId: string, options: FindOneOptions<ILivechatDepartmentRecord>): Cursor<ILivechatDepartmentRecord> {
const query = { businessHourId };
return this.find(query, options);
}
findEnabledByBusinessHourId(businessHourId, options) {
findEnabledByBusinessHourId(businessHourId: string, options: FindOneOptions<ILivechatDepartmentRecord>): Cursor<ILivechatDepartmentRecord> {
const query = { businessHourId, enabled: true };
return this.find(query, options);
}
addBusinessHourToDepartmentsByIds(ids = [], businessHourId) {
addBusinessHourToDepartmentsByIds(ids: string[] = [], businessHourId: string): Promise<WriteOpResult> {
const query = {
_id: { $in: ids },
};
......@@ -50,7 +52,7 @@ export class LivechatDepartmentRaw extends BaseRaw {
return this.col.update(query, update, { multi: true });
}
removeBusinessHourFromDepartmentsByIdsAndBusinessHourId(ids = [], businessHourId) {
removeBusinessHourFromDepartmentsByIdsAndBusinessHourId(ids: string[] = [], businessHourId: string): Promise<WriteOpResult> {
const query = {
_id: { $in: ids },
businessHourId,
......@@ -65,7 +67,7 @@ export class LivechatDepartmentRaw extends BaseRaw {
return this.col.update(query, update, { multi: true });
}
removeBusinessHourFromDepartmentsByBusinessHourId(businessHourId) {
removeBusinessHourFromDepartmentsByBusinessHourId(businessHourId: string): Promise<WriteOpResult> {
const query = {
businessHourId,
};
......
import { BaseRaw } from './BaseRaw';
export class LivechatInquiryRaw extends BaseRaw {
findOneQueuedByRoomId(rid) {
const query = {
rid,
status: 'queued',
};
return this.findOne(query);
}
findOneByRoomId(rid, options) {
const query = {
rid,
};
return this.findOne(query, options);
}
getDistinctQueuedDepartments() {
return this.col.distinct('department', { status: 'queued' });
}
}
import { FindOneOptions, MongoDistinctPreferences } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { ILivechatInquiryRecord, LivechatInquiryStatus } from '../../../../definition/IInquiry';
export class LivechatInquiryRaw extends BaseRaw<ILivechatInquiryRecord> {
findOneQueuedByRoomId(rid: string): Promise<ILivechatInquiryRecord & { status: LivechatInquiryStatus.QUEUED } | null> {
const query = {
rid,
status: LivechatInquiryStatus.QUEUED,
};
return this.findOne(query) as unknown as (Promise<(ILivechatInquiryRecord & { status: LivechatInquiryStatus.QUEUED }) | null>);
}
findOneByRoomId<T = ILivechatInquiryRecord>(rid: string, options: FindOneOptions<T extends ILivechatInquiryRecord ? ILivechatInquiryRecord: T>): Promise<T | null> {
const query = {
rid,
};
return this.findOne(query, options);
}
getDistinctQueuedDepartments(options: MongoDistinctPreferences): Promise<string[]> {
return this.col.distinct('department', { status: LivechatInquiryStatus.QUEUED }, options);
}
}
import { BaseRaw } from './BaseRaw';
export class LivechatTriggerRaw extends BaseRaw {
}
import { BaseRaw } from './BaseRaw';
import { ILivechatTrigger } from '../../../../definition/ILivechatTrigger';
export class LivechatTriggerRaw extends BaseRaw<ILivechatTrigger> {
}
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { AggregationCursor, Cursor, FilterQuery, FindOneOptions } from 'mongodb';
import { BaseRaw } from './BaseRaw';
import { ILivechatVisitor } from '../../../../definition/ILivechatVisitor';
export class LivechatVisitorsRaw extends BaseRaw {
getVisitorsBetweenDate({ start, end, department }) {
export class LivechatVisitorsRaw extends BaseRaw<ILivechatVisitor> {
getVisitorsBetweenDate({ start, end, department }: { start: Date; end: Date; department: string }): Cursor<ILivechatVisitor> {
const query = {
_updatedAt: {
$gte: new Date(start),
......@@ -12,10 +14,12 @@ export class LivechatVisitorsRaw extends BaseRaw {
...department && department !== 'undefined' && { department },
};
return this.find(query, { fields: { _id: 1 } });
return this.find(query, { projection: { _id: 1 } });
}
findByNameRegexWithExceptionsAndConditions(searchTerm, exceptions = [], conditions = {}, options = {}) {
findByNameRegexWithExceptionsAndConditions<P = ILivechatVisitor>(searchTerm: string, exceptions: string[] = [], conditions: FilterQuery<ILivechatVisitor> = {}, options: FindOneOptions<P extends ILivechatVisitor ? ILivechatVisitor : P> = {}): AggregationCursor<P & {
custom_name: string;
}> {
if (!Array.isArray(exceptions)) {
exceptions = [exceptions];
}
......@@ -32,24 +36,22 @@ export class LivechatVisitorsRaw extends BaseRaw {
},
};
const { fields, sort, offset, count } = options;
const { projection, sort, skip, limit } = options;
const project = {
$project: {
$project: { // TODO: move this logic to client
// eslint-disable-next-line @typescript-eslint/camelcase
custom_name: { $concat: ['$username', ' - ', '$name'] },
...fields,
...projection,
},
};
const order = { $sort: sort || { name: 1 } };
const params = [match, project, order];
if (offset) {
params.push({ $skip: offset });
}
if (count) {
params.push({ $limit: count });
}
const params: Record<string, unknown>[] = [
match,
order,
skip && { $skip: skip },
limit && { $limit: limit },
project].filter(Boolean) as Record<string, unknown>[];
return this.col.aggregate(params);
}
......@@ -58,7 +60,7 @@ export class LivechatVisitorsRaw extends BaseRaw {
* Find visitors by their email or phone or username or name
* @return [{object}] List of Visitors from db
*/
findVisitorsByEmailOrPhoneOrNameOrUsername(_emailOrPhoneOrNameOrUsername, options) {
findVisitorsByEmailOrPhoneOrNameOrUsername(_emailOrPhoneOrNameOrUsername: string, options: FindOneOptions<ILivechatVisitor>): Cursor<ILivechatVisitor> {
const filter = new RegExp(_emailOrPhoneOrNameOrUsername, 'i');
const query = {
$or: [{
......
import { IRocketChatRecord } from './IRocketChatRecord';
export interface IInquiry {
_id: string;
_updatedAt?: Date;
department?: string;
}
export enum LivechatInquiryStatus {
QUEUED = 'queued',
TAKEN = 'taken',
READY = 'ready'
}
export interface IVisitor {
_id: string;
username: string;
token: string;
status: string;
}
export interface ILivechatInquiryRecord extends IRocketChatRecord {
rid: string;
name: string;
ts: Date;
message: string;
status: LivechatInquiryStatus;
v: IVisitor;
t: 'l';
queueOrder: number;
estimatedWaitingTimeQueue: number;
estimatedServiceTimeAt: string;
department: string;
estimatedInactivityCloseTimeAt: Date;
}
import { IRocketChatRecord } from './IRocketChatRecord';
export interface ILivechatAgentActivity extends IRocketChatRecord {
agentId: string;
date: number;
lastStartedAt: Date;
availableTime: number;
serviceHistory: IServiceHistory[];
lastStoppedAt?: Date;
}
export interface IServiceHistory {
startedAt: Date;
stoppedAt: Date;
}
import { IRocketChatRecord } from './IRocketChatRecord';
export interface ILivechatCustomField extends IRocketChatRecord {
label: string;
scope: 'visitor' | 'room';
visibility: string;
type?: string;
regexp?: string;
required?: boolean;
defaultValue?: string;
options?: string;
public?: boolean;
}
......@@ -2,14 +2,16 @@ export interface ILivechatDepartment {
_id: string;
name: string;
enabled: boolean;
description: string;
description?: string;
showOnRegistration: boolean;
showOnOfflineForm: boolean;
requestTagBeforeClosingChat: boolean;
requestTagBeforeClosingChat?: boolean;
email: string;
chatClosingTags: string[];
chatClosingTags?: string[];
offlineMessageChannelName: string;
numAgents: number;
_updatedAt?: Date;
businessHourId?: string;
// extra optional fields
[k: string]: any;
}
......@@ -4,4 +4,6 @@ export interface ILivechatDepartmentAgents {
departmentEnabled: boolean;
agentId: string;
username: string;
count: number;
order: number;
}
......@@ -5,13 +5,15 @@ export interface ILivechatDepartmentRecord extends IRocketChatRecord {
_id: string;
name: string;
enabled: boolean;
description: string;
description?: string;
showOnRegistration: boolean;
showOnOfflineForm: boolean;
requestTagBeforeClosingChat: boolean;
requestTagBeforeClosingChat?: boolean;
email: string;
chatClosingTags: string[];
chatClosingTags?: string[];
offlineMessageChannelName: string;
numAgents: number;
businessHourId?: string;
// extra optional fields
[k: string]: any;
}
import { IRocketChatRecord } from './IRocketChatRecord';
export enum ILivechatTriggerType {
TIME_ON_SITE = 'time-on-site',
PAGE_URL = 'page-url',
CHAT_OPENED_BY_VISITOR = 'chat-opened-by-visitor'
}
export interface ILivechatTriggerCondition {
name: ILivechatTriggerType;
value?: string | number;
}
export interface ILivechatTriggerAction {
name: 'send-message';
params?: {
sender: 'queue' | 'custom';
msg: string;
name: string;
};
}
export interface ILivechatTrigger extends IRocketChatRecord {
name: string;
description: string;
enabled: boolean;
runOnce: boolean;
conditions: ILivechatTriggerCondition[];
actions: ILivechatTriggerAction[];
}
import { IRocketChatRecord } from './IRocketChatRecord';
export interface IVisitorPhone {
phoneNumber: string;
}
export interface IVisitorLastChat {
_id: string;
ts: string;
}
export interface ILivechatVisitorConnectionData {
httpHeaders: {
[k: string]: string;
};
clientAddress: string;
}
export interface IVisitorEmail {
address: string;
}
export interface ILivechatVisitor extends IRocketChatRecord {
username: string;
ts: Date;
token: string;
department?: string;
name?: string;
phone?: (IVisitorPhone)[] | null;
lastChat?: IVisitorLastChat;
userAgent?: string;
ip?: string;
host?: string;
visitorEmails?: IVisitorEmail[];
}
......@@ -48,6 +48,7 @@ export interface IMessage extends IRocketChatRecord {
channels?: Array<ChannelName>;
u: Pick<IUser, '_id' | 'username' | 'name'>;
blocks?: MessageSurfaceLayout;
alias?: string;
md?: ReturnType<typeof parser>;
_hidden?: boolean;
......@@ -73,3 +74,13 @@ export interface IMessage extends IRocketChatRecord {
files?: FileProp[];
attachments?: MessageAttachment[];
}
export type IMessageInbox = IMessage & {
// email inbox fields
email?: {
references?: string[];
messageId?: string;
};
}
export const isIMessageInbox = (message: IMessage): message is IMessageInbox => 'email' in message;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment