diff --git a/apps/meteor/app/api/server/lib/messages.ts b/apps/meteor/app/api/server/lib/messages.ts index 50f3df5e7688..d6955ce7b933 100644 --- a/apps/meteor/app/api/server/lib/messages.ts +++ b/apps/meteor/app/api/server/lib/messages.ts @@ -23,7 +23,7 @@ export async function findMentionedMessages({ if (!room || !(await canAccessRoomAsync(room, { _id: uid }))) { throw new Error('error-not-allowed'); } - const user: IUser | null = await Users.findOneById(uid, { fields: { username: 1 } }); + const user = await Users.findOneById>(uid, { projection: { username: 1 } }); if (!user) { throw new Error('invalid-user'); } @@ -62,7 +62,7 @@ export async function findStarredMessages({ if (!room || !(await canAccessRoomAsync(room, { _id: uid }))) { throw new Error('error-not-allowed'); } - const user = await Users.findOneById(uid, { fields: { username: 1 } }); + const user = await Users.findOneById>(uid, { projection: { username: 1 } }); if (!user) { throw new Error('invalid-user'); } diff --git a/apps/meteor/app/api/server/lib/rooms.ts b/apps/meteor/app/api/server/lib/rooms.ts index 2c189cdd3fd9..fa69e6af4be2 100644 --- a/apps/meteor/app/api/server/lib/rooms.ts +++ b/apps/meteor/app/api/server/lib/rooms.ts @@ -31,7 +31,7 @@ export async function findAdminRooms({ const typesToRemove = ['discussions', 'teams']; const showTypes = Array.isArray(types) ? types.filter((type) => !typesToRemove.includes(type)) : []; const options = { - fields: adminFields, + projection: adminFields, sort: sort || { default: -1, name: 1 }, skip: offset, limit: count, @@ -63,14 +63,14 @@ export async function findAdminRoom({ uid, rid }: { uid: string; rid: string }): throw new Error('error-not-authorized'); } - return Rooms.findOneById(rid, { fields: adminFields }); + return Rooms.findOneById(rid, { projection: adminFields }); } export async function findChannelAndPrivateAutocomplete({ uid, selector }: { uid: string; selector: { name: string } }): Promise<{ items: IRoom[]; }> { const options = { - fields: { + projection: { _id: 1, fname: 1, name: 1, @@ -101,7 +101,7 @@ export async function findAdminRoomsAutocomplete({ uid, selector }: { uid: strin throw new Error('error-not-authorized'); } const options = { - fields: { + projection: { _id: 1, fname: 1, name: 1, @@ -138,7 +138,7 @@ export async function findChannelAndPrivateAutocompleteWithPagination({ .map((item: Pick) => item.rid); const options = { - fields: { + projection: { _id: 1, fname: 1, name: 1, @@ -164,7 +164,7 @@ export async function findRoomsAvailableForTeams({ uid, name }: { uid: string; n items: IRoom[]; }> { const options = { - fields: { + projection: { _id: 1, fname: 1, name: 1, diff --git a/apps/meteor/app/livechat/server/lib/Livechat.js b/apps/meteor/app/livechat/server/lib/Livechat.js index d365e7c95fd0..218576effe4d 100644 --- a/apps/meteor/app/livechat/server/lib/Livechat.js +++ b/apps/meteor/app/livechat/server/lib/Livechat.js @@ -371,7 +371,7 @@ export const Livechat = { }); } - const user = await LivechatVisitors.getVisitorByToken(token, { fields: { _id: 1 } }); + const user = await LivechatVisitors.getVisitorByToken(token, { projection: { _id: 1 } }); if (user) { return LivechatVisitors.updateById(user._id, updateUser); } diff --git a/apps/meteor/ee/app/livechat-enterprise/server/api/lib/inquiries.js b/apps/meteor/ee/app/livechat-enterprise/server/api/lib/inquiries.js index 5f8572e2208c..351bbe06b5b7 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/api/lib/inquiries.js +++ b/apps/meteor/ee/app/livechat-enterprise/server/api/lib/inquiries.js @@ -7,7 +7,7 @@ export async function setPriorityToInquiry({ userId, roomId, priority }) { if (!(await hasPermissionAsync(userId, 'manage-livechat-priorities')) && !(await hasPermissionAsync(userId, 'view-l-room'))) { throw new Error('error-not-authorized'); } - const inquiry = await LivechatInquiry.findOneByRoomId(roomId, { fields: { status: 1 } }); + const inquiry = await LivechatInquiry.findOneByRoomId(roomId, { projection: { status: 1 } }); if (!inquiry || inquiry.status !== 'queued') { throw new Error('error-invalid-inquiry'); } @@ -17,5 +17,5 @@ export async function setPriorityToInquiry({ userId, roomId, priority }) { throw new Error('error-invalid-priority'); } - LivechatEnterprise.updateRoomPriority(roomId, await Users.findOneById(userId, { fields: { username: 1 } }), priorityData); + LivechatEnterprise.updateRoomPriority(roomId, await Users.findOneById(userId, { projection: { username: 1 } }), priorityData); } diff --git a/apps/meteor/ee/app/livechat-enterprise/server/permissions.ts b/apps/meteor/ee/app/livechat-enterprise/server/permissions.ts index 0ccf0c141fbc..95e07f940180 100644 --- a/apps/meteor/ee/app/livechat-enterprise/server/permissions.ts +++ b/apps/meteor/ee/app/livechat-enterprise/server/permissions.ts @@ -7,7 +7,7 @@ export const createPermissions = async (): Promise => { const livechatManagerRole = 'livechat-manager'; const adminRole = 'admin'; - const monitorRole = await Roles.findOneById(livechatMonitorRole, { fields: { _id: 1 } }); + const monitorRole = await Roles.findOneById(livechatMonitorRole, { projection: { _id: 1 } }); if (!monitorRole) { await createOrUpdateProtectedRoleAsync(livechatMonitorRole, { name: livechatMonitorRole, diff --git a/apps/meteor/server/models/raw/BaseRaw.ts b/apps/meteor/server/models/raw/BaseRaw.ts index 13a66352ba04..083d1ef0e80d 100644 --- a/apps/meteor/server/models/raw/BaseRaw.ts +++ b/apps/meteor/server/models/raw/BaseRaw.ts @@ -101,16 +101,16 @@ export abstract class BaseRaw = undefined> impleme private ensureDefaultFields

(options: FindOptions

): FindOptions

; private ensureDefaultFields

(options?: any): FindOptions

| undefined | FindOptions { + if (options.fields) { + warnFields("Using 'fields' in models is deprecated.", options); + } + if (this.defaultFields === undefined) { return options; } const { fields: deprecatedFields, projection, ...rest } = options || {}; - if (deprecatedFields) { - warnFields("Using 'fields' in models is deprecated.", options); - } - const fields = { ...deprecatedFields, ...projection }; return { diff --git a/apps/meteor/server/models/raw/Users.js b/apps/meteor/server/models/raw/Users.js index 780366acb3be..8585675e06a0 100644 --- a/apps/meteor/server/models/raw/Users.js +++ b/apps/meteor/server/models/raw/Users.js @@ -1002,7 +1002,7 @@ export class UsersRaw extends BaseRaw { }; const options = { - fields: { _id: 1 }, + projection: { _id: 1 }, }; const found = await this.findOne(query, options);