chore: use model.findById where possible
All checks were successful
Build / build (22) (push) Successful in 46s
Build / build (20) (push) Successful in 1m13s
Build / build (18) (push) Successful in 1m29s
Build / build (18) (pull_request) Successful in 50s
Build / build (20) (pull_request) Successful in 1m12s
Build / build (22) (pull_request) Successful in 1m20s
All checks were successful
Build / build (22) (push) Successful in 46s
Build / build (20) (push) Successful in 1m13s
Build / build (18) (push) Successful in 1m29s
Build / build (18) (pull_request) Successful in 50s
Build / build (20) (pull_request) Successful in 1m12s
Build / build (22) (pull_request) Successful in 1m20s
This commit is contained in:
parent
0085c20e11
commit
621067c50a
@ -18,7 +18,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const guild = (await Guild.findOne({ _id: payload.GuildId.$oid }, "Name"))!;
|
||||
const guild = (await Guild.findById(payload.GuildId.$oid, "Name"))!;
|
||||
const senderAccount = await getAccountForRequest(req);
|
||||
if (!(await hasGuildPermission(guild, senderAccount._id.toString(), GuildPermission.Recruiter))) {
|
||||
res.status(400).json("Invalid permission");
|
||||
|
@ -19,7 +19,7 @@ export const confirmGuildInvitationController: RequestHandler = async (req, res)
|
||||
new Types.ObjectId(req.query.clanId as string)
|
||||
);
|
||||
|
||||
const guild = (await Guild.findOne({ _id: req.query.clanId as string }))!;
|
||||
const guild = (await Guild.findById(req.query.clanId as string))!;
|
||||
|
||||
guild.RosterActivity ??= [];
|
||||
guild.RosterActivity.push({
|
||||
|
@ -11,7 +11,7 @@ import { Types } from "mongoose";
|
||||
export const contributeGuildClassController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const payload = getJSONfromString<IContributeGuildClassRequest>(String(req.body));
|
||||
const guild = (await Guild.findOne({ _id: payload.GuildId }))!;
|
||||
const guild = (await Guild.findById(payload.GuildId))!;
|
||||
|
||||
// First contributor initiates ceremony and locks the pending class.
|
||||
if (!guild.CeremonyContributors) {
|
||||
|
@ -9,7 +9,7 @@ const getGuildController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId, "GuildId");
|
||||
if (inventory.GuildId) {
|
||||
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
||||
const guild = await Guild.findById(inventory.GuildId);
|
||||
if (guild) {
|
||||
// Handle guilds created before we added discriminators
|
||||
if (guild.Name.indexOf("#") == -1) {
|
||||
|
@ -6,7 +6,7 @@ import { getDojoClient } from "@/src/services/guildService";
|
||||
export const getGuildDojoController: RequestHandler = async (req, res) => {
|
||||
const guildId = req.query.guildId as string;
|
||||
|
||||
const guild = await Guild.findOne({ _id: guildId });
|
||||
const guild = await Guild.findById(guildId);
|
||||
if (!guild) {
|
||||
res.status(404).end();
|
||||
return;
|
||||
|
@ -9,7 +9,7 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const inventory = await getInventory(accountId, "GuildId");
|
||||
if (inventory.GuildId) {
|
||||
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
||||
const guild = await Guild.findById(inventory.GuildId);
|
||||
if (guild) {
|
||||
const log: Record<string, IGuildLogEntryClient[]> = {
|
||||
RoomChanges: [],
|
||||
|
@ -4,7 +4,7 @@ import { Account } from "@/src/models/loginModel";
|
||||
|
||||
const logoutController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const account = await Account.findOne({ _id: accountId });
|
||||
const account = await Account.findById(accountId);
|
||||
if (account) {
|
||||
account.Nonce = 0;
|
||||
await account.save();
|
||||
|
@ -42,7 +42,7 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
|
||||
|
||||
guild.RosterActivity ??= [];
|
||||
if (isKick) {
|
||||
const kickee = (await Account.findOne({ _id: payload.userId }))!;
|
||||
const kickee = (await Account.findById(payload.userId))!;
|
||||
guild.RosterActivity.push({
|
||||
dateTime: new Date(),
|
||||
entryType: 12,
|
||||
|
@ -8,7 +8,7 @@ import { RequestHandler } from "express";
|
||||
export const setGuildMotdController: RequestHandler = async (req, res) => {
|
||||
const account = await getAccountForRequest(req);
|
||||
const inventory = await getInventory(account._id.toString(), "GuildId");
|
||||
const guild = (await Guild.findOne({ _id: inventory.GuildId! }))!;
|
||||
const guild = (await Guild.findById(inventory.GuildId!))!;
|
||||
if (!(await hasGuildPermission(guild, account._id, GuildPermission.Herald))) {
|
||||
res.status(400).json("Invalid permission");
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ export const getAccountInfoController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
const guildMember = await GuildMember.findOne({ accountId: account._id, status: 0 }, "guildId rank");
|
||||
if (guildMember) {
|
||||
const guild = (await Guild.findOne({ _id: guildMember.guildId }, "Ranks"))!;
|
||||
const guild = (await Guild.findById(guildMember.guildId, "Ranks"))!;
|
||||
info.GuildId = guildMember.guildId.toString();
|
||||
info.GuildPermissions = guild.Ranks[guildMember.rank].Permissions;
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
|
||||
res.status(400).end();
|
||||
return;
|
||||
}
|
||||
const account = await Account.findOne({ _id: req.query.playerId as string }, "DisplayName");
|
||||
const account = await Account.findById(req.query.playerId as string, "DisplayName");
|
||||
if (!account) {
|
||||
res.status(400).send("No account or guild ID specified");
|
||||
return;
|
||||
}
|
||||
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
|
||||
const loadout = (await Loadout.findOne({ _id: inventory.LoadOutPresets }, "NORMAL"))!;
|
||||
const loadout = (await Loadout.findById(inventory.LoadOutPresets, "NORMAL"))!;
|
||||
|
||||
const result: IPlayerProfileViewingDataResult = {
|
||||
AccountId: toOid(account._id),
|
||||
@ -88,7 +88,7 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
|
||||
}
|
||||
}
|
||||
if (inventory.GuildId) {
|
||||
const guild = (await Guild.findOne({ _id: inventory.GuildId }, "Name Tier XP Class"))!;
|
||||
const guild = (await Guild.findById(inventory.GuildId, "Name Tier XP Class"))!;
|
||||
result.GuildId = toOid(inventory.GuildId);
|
||||
result.GuildName = guild.Name;
|
||||
result.GuildTier = guild.Tier;
|
||||
|
@ -37,7 +37,7 @@ export const getGuildForRequestEx = async (
|
||||
if (!inventory.GuildId || inventory.GuildId.toString() != guildId) {
|
||||
throw new Error("Account is not in the guild that it has sent a request for");
|
||||
}
|
||||
const guild = await Guild.findOne({ _id: guildId });
|
||||
const guild = await Guild.findById(guildId);
|
||||
if (!guild) {
|
||||
throw new Error("Account thinks it is in a guild that doesn't exist");
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ export const getAllMessagesSorted = async (accountId: string): Promise<HydratedD
|
||||
};
|
||||
|
||||
export const getMessage = async (messageId: string): Promise<HydratedDocument<IMessageDatabase>> => {
|
||||
const message = await Inbox.findOne({ _id: messageId });
|
||||
const message = await Inbox.findById(messageId);
|
||||
|
||||
if (!message) {
|
||||
throw new Error(`Message not found ${messageId}`);
|
||||
|
@ -21,7 +21,7 @@ export const createShip = async (
|
||||
};
|
||||
|
||||
export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = ""): Promise<TShipDatabaseDocument> => {
|
||||
const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
|
||||
const ship = await Ship.findById(shipId, fieldSelection);
|
||||
|
||||
if (!ship) {
|
||||
throw new Error(`error finding a ship with id ${shipId.toString()}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user