Skip to content

Commit

Permalink
chore: Move models to package (#34154)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego authored Dec 27, 2024
1 parent 9af2c11 commit 1184b83
Show file tree
Hide file tree
Showing 212 changed files with 461 additions and 701 deletions.
3 changes: 1 addition & 2 deletions _templates/service/new/service.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
to: ee/apps/<%= name %>/src/service.ts
---
import { api, getConnection, getTrashCollection } from '@rocket.chat/core-services';
import { registerServiceModels } from '@rocket.chat/models';
import { broker } from '@rocket.chat/network-broker';
import { startTracing } from '@rocket.chat/tracing';
import polka from 'polka';

import { registerServiceModels } from '../../../../apps/meteor/ee/server/lib/registerServiceModels';

const PORT = process.env.PORT || <%= h.random() %>;

(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AtLeast, ILivechatAgentStatus, ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHoursModel, IUsersModel } from '@rocket.chat/model-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';
import type { IWorkHoursCronJobsWrapper } from '@rocket.chat/models';
import moment from 'moment-timezone';
import type { UpdateFilter } from 'mongodb';

import type { IWorkHoursCronJobsWrapper } from '../../../../server/models/raw/LivechatBusinessHours';
import { notifyOnUserChange } from '../../../lib/server/lib/notifyListener';

export interface IBusinessHourBehavior {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/statistics/server/lib/SAUMonitor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { ISession, ISessionDevice, ISocketConnectionLogged, IUser } from '@rocket.chat/core-typings';
import { cronJobs } from '@rocket.chat/cron';
import { Logger } from '@rocket.chat/logger';
import { Sessions, Users } from '@rocket.chat/models';
import { Sessions, Users, aggregates } from '@rocket.chat/models';
import mem from 'mem';
import { Meteor } from 'meteor/meteor';
import UAParser from 'ua-parser-js';

import { UAParserMobile, UAParserDesktop } from './UAParserCustom';
import { getMostImportantRole } from '../../../../lib/roles/getMostImportantRole';
import { getClientAddress } from '../../../../server/lib/getClientAddress';
import { aggregates } from '../../../../server/models/raw/Sessions';
import { sauEvents } from '../../../../server/services/sauMonitor/events';

type DateObj = { day: number; month: number; year: number };
Expand Down
66 changes: 0 additions & 66 deletions apps/meteor/ee/server/lib/registerServiceModels.ts

This file was deleted.

6 changes: 0 additions & 6 deletions apps/meteor/ee/server/models/LivechatPriority.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/AuditLog.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { RocketChatRecordDeleted, IAuditLog } from '@rocket.chat/core-typings';
import { BaseRaw } from '@rocket.chat/models';
import type { Collection, Db } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

export class AuditLogRaw extends BaseRaw<IAuditLog> {
constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<IAuditLog>>) {
super(db, 'audit_log', trash);
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/CannedResponse.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { IOmnichannelCannedResponse } from '@rocket.chat/core-typings';
import type { ICannedResponseModel } from '@rocket.chat/model-typings';
import { BaseRaw } from '@rocket.chat/models';
import type { Db, DeleteResult, FindCursor, FindOptions, IndexDescription, UpdateFilter } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

// TODO need to define type for CannedResponse object
export class CannedResponseRaw extends BaseRaw<IOmnichannelCannedResponse> implements ICannedResponseModel {
constructor(db: Db) {
Expand Down
4 changes: 1 addition & 3 deletions apps/meteor/ee/server/models/raw/LivechatDepartment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ILivechatDepartment, RocketChatRecordDeleted, LivechatDepartmentDTO } from '@rocket.chat/core-typings';
import type { ILivechatDepartmentModel } from '@rocket.chat/model-typings';
import { LivechatUnit } from '@rocket.chat/models';
import { LivechatUnit, LivechatDepartmentRaw } from '@rocket.chat/models';
import type {
Collection,
DeleteResult,
Expand All @@ -14,8 +14,6 @@ import type {
AggregationCursor,
} from 'mongodb';

import { LivechatDepartmentRaw } from '../../../../server/models/raw/LivechatDepartment';

declare module '@rocket.chat/model-typings' {
interface ILivechatDepartmentModel {
removeDepartmentFromForwardListById(departmentId: string): Promise<void>;
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/LivechatDepartmentAgents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ILivechatDepartmentAgents } from '@rocket.chat/core-typings';

import { LivechatDepartmentAgentsRaw } from '../../../../server/models/raw/LivechatDepartmentAgents';
import { LivechatDepartmentAgentsRaw } from '@rocket.chat/models';

export class LivechatDepartmentAgents extends LivechatDepartmentAgentsRaw {
findAgentsByAgentIdAndBusinessHourId(agentId: string, businessHourId: string): Promise<ILivechatDepartmentAgents[]> {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/LivechatInquiry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ILivechatInquiryRecord, ILivechatPriority } from '@rocket.chat/core-typings';
import { DEFAULT_SLA_CONFIG, LivechatPriorityWeight } from '@rocket.chat/core-typings';
import type { ILivechatInquiryModel } from '@rocket.chat/model-typings';
import { LivechatInquiryRaw } from '@rocket.chat/models';
import type { ModifyResult, UpdateResult, Document } from 'mongodb';

import { LivechatInquiryRaw } from '../../../../server/models/raw/LivechatInquiry';

declare module '@rocket.chat/model-typings' {
interface ILivechatInquiryModel {
setSlaForRoom(rid: string, sla: { estimatedWaitingTimeQueue: number; slaId: string }): Promise<ModifyResult<ILivechatInquiryRecord>>;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/models/raw/LivechatRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type {
import { LivechatPriorityWeight, DEFAULT_SLA_CONFIG } from '@rocket.chat/core-typings';
import type { FindPaginated, ILivechatRoomsModel } from '@rocket.chat/model-typings';
import type { Updater } from '@rocket.chat/models';
import { LivechatRoomsRaw } from '@rocket.chat/models';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import type { FindCursor, UpdateResult, Document, FindOptions, Db, Collection, Filter, AggregationCursor, UpdateOptions } from 'mongodb';

import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
import { LivechatRoomsRaw } from '../../../../server/models/raw/LivechatRooms';

declare module '@rocket.chat/model-typings' {
interface ILivechatRoomsModel {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/LivechatTag.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ILivechatTag } from '@rocket.chat/core-typings';
import type { ILivechatTagModel } from '@rocket.chat/model-typings';
import { BaseRaw } from '@rocket.chat/models';
import type { Db, DeleteResult, FindCursor, FindOptions, IndexDescription } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

export class LivechatTagRaw extends BaseRaw<ILivechatTag> implements ILivechatTagModel {
constructor(db: Db) {
super(db, 'livechat_tag');
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/LivechatUnit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { IOmnichannelBusinessUnit, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { FindPaginated, ILivechatUnitModel } from '@rocket.chat/model-typings';
import { LivechatUnitMonitors, LivechatDepartment, LivechatRooms } from '@rocket.chat/models';
import { LivechatUnitMonitors, LivechatDepartment, LivechatRooms, BaseRaw } from '@rocket.chat/models';
import type { FindOptions, Filter, FindCursor, Db, FilterOperators, UpdateResult, DeleteResult, Document, UpdateFilter } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';
import { getUnitsFromUser } from '../../../app/livechat-enterprise/server/lib/units';

const addQueryRestrictions = async (originalQuery: Filter<IOmnichannelBusinessUnit> = {}) => {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/LivechatUnitMonitors.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { ILivechatUnitMonitor } from '@rocket.chat/core-typings';
import type { ILivechatUnitMonitorsModel } from '@rocket.chat/model-typings';
import { BaseRaw } from '@rocket.chat/models';
import type { Db, FindCursor, UpdateResult, DeleteResult, IndexDescription } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

export class LivechatUnitMonitorsRaw extends BaseRaw<ILivechatUnitMonitor> implements ILivechatUnitMonitorsModel {
constructor(db: Db) {
super(db, 'livechat_unit_monitors');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/models/raw/ReadReceipts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IUser, IMessage, ReadReceipt, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { IReadReceiptsModel } from '@rocket.chat/model-typings';
import { BaseRaw } from '@rocket.chat/models';
import type { Collection, FindCursor, Db, IndexDescription, DeleteResult, Filter, UpdateResult, Document } from 'mongodb';

import { otrSystemMessages } from '../../../../app/otr/lib/constants';
import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

export class ReadReceiptsRaw extends BaseRaw<ReadReceipt> implements IReadReceiptsModel {
constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<ReadReceipt>>) {
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/models/raw/ServiceLevelAgreements.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { IOmnichannelServiceLevelAgreements } from '@rocket.chat/core-typings';
import type { IOmnichannelServiceLevelAgreementsModel } from '@rocket.chat/model-typings/src';
import { BaseRaw } from '@rocket.chat/models';
import type { Db, IndexDescription } from 'mongodb';

import { BaseRaw } from '../../../../server/models/raw/BaseRaw';

export class ServiceLevelAgreements extends BaseRaw<IOmnichannelServiceLevelAgreements> implements IOmnichannelServiceLevelAgreementsModel {
constructor(db: Db) {
super(db, 'omnichannel_service_level_agreements');
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/models/raw/Users.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RocketChatRecordDeleted, IUser } from '@rocket.chat/core-typings';
import { UsersRaw } from '@rocket.chat/models';
import type { Db, Collection } from 'mongodb';

import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
import { UsersRaw } from '../../../../server/models/raw/Users';

type AgentMetadata = {
'agentId'?: string;
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/ee/server/models/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { License } from '@rocket.chat/license';
// To facilitate our lives with the stream
// Collection will be registered on CE too
// No functionality will be imported tho, just the service registration
import('./LivechatPriority');
import('./OmnichannelServiceLevelAgreements');
import('./AuditLog');
import('./ReadReceipts');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { registerModel } from '@rocket.chat/models';
import { registerModel, BaseRaw } from '@rocket.chat/models';
import { expect } from 'chai';
import { before, describe, it } from 'mocha';
import sinon from 'sinon';

import { BaseRaw } from '../../../../../../server/models/raw/BaseRaw';
import { BeforeSaveCannedResponse } from '../../../../../server/hooks/messages/BeforeSaveCannedResponse';

const createMessage = (msg?: string, extra: any = {}) => ({
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/server/database/trash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TrashRaw } from '@rocket.chat/models';

import { db } from './utils';
import { TrashRaw } from '../models/raw/Trash';

const Trash = new TrashRaw(db);
export const trashCollection = Trash.col;
2 changes: 1 addition & 1 deletion apps/meteor/server/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './tracing';
import './models/startup';
import './models';
/**
* ./settings uses top level await, in theory the settings creation
* and the startup should be done in parallel
Expand Down
Loading

0 comments on commit 1184b83

Please sign in to comment.