Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Change some places still using fields to projection #26308

Merged
merged 1 commit into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pick<IUser, 'username'>>(uid, { projection: { username: 1 } });
if (!user) {
throw new Error('invalid-user');
}
Expand Down Expand Up @@ -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<Pick<IUser, 'username'>>(uid, { projection: { username: 1 } });
if (!user) {
throw new Error('invalid-user');
}
Expand Down
12 changes: 6 additions & 6 deletions apps/meteor/app/api/server/lib/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function findChannelAndPrivateAutocompleteWithPagination({
.map((item: Pick<ISubscription, 'rid'>) => item.rid);

const options = {
fields: {
projection: {
_id: 1,
fname: 1,
name: 1,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const createPermissions = async (): Promise<void> => {
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,
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/server/models/raw/BaseRaw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ export abstract class BaseRaw<T, C extends DefaultFields<T> = undefined> impleme
private ensureDefaultFields<P>(options: FindOptions<P>): FindOptions<P>;

private ensureDefaultFields<P>(options?: any): FindOptions<P> | undefined | FindOptions<T> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ export class UsersRaw extends BaseRaw {
};

const options = {
fields: { _id: 1 },
projection: { _id: 1 },
};

const found = await this.findOne(query, options);
Expand Down