forked from OpenWF/SpaceNinjaServer
chore: use model.findById where possible (#1315)
Reviewed-on: OpenWF/SpaceNinjaServer#1315
This commit is contained in:
parent
4afc8bc8c6
commit
2ec2b0278a
@ -18,7 +18,7 @@ export const addToGuildController: RequestHandler = async (req, res) => {
|
|||||||
return;
|
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);
|
const senderAccount = await getAccountForRequest(req);
|
||||||
if (!(await hasGuildPermission(guild, senderAccount._id.toString(), GuildPermission.Recruiter))) {
|
if (!(await hasGuildPermission(guild, senderAccount._id.toString(), GuildPermission.Recruiter))) {
|
||||||
res.status(400).json("Invalid permission");
|
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)
|
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 ??= [];
|
||||||
guild.RosterActivity.push({
|
guild.RosterActivity.push({
|
||||||
|
@ -11,7 +11,7 @@ import { Types } from "mongoose";
|
|||||||
export const contributeGuildClassController: RequestHandler = async (req, res) => {
|
export const contributeGuildClassController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const payload = getJSONfromString<IContributeGuildClassRequest>(String(req.body));
|
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.
|
// First contributor initiates ceremony and locks the pending class.
|
||||||
if (!guild.CeremonyContributors) {
|
if (!guild.CeremonyContributors) {
|
||||||
|
@ -9,7 +9,7 @@ const getGuildController: RequestHandler = async (req, res) => {
|
|||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId, "GuildId");
|
const inventory = await getInventory(accountId, "GuildId");
|
||||||
if (inventory.GuildId) {
|
if (inventory.GuildId) {
|
||||||
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
const guild = await Guild.findById(inventory.GuildId);
|
||||||
if (guild) {
|
if (guild) {
|
||||||
// Handle guilds created before we added discriminators
|
// Handle guilds created before we added discriminators
|
||||||
if (guild.Name.indexOf("#") == -1) {
|
if (guild.Name.indexOf("#") == -1) {
|
||||||
|
@ -6,7 +6,7 @@ import { getDojoClient } from "@/src/services/guildService";
|
|||||||
export const getGuildDojoController: RequestHandler = async (req, res) => {
|
export const getGuildDojoController: RequestHandler = async (req, res) => {
|
||||||
const guildId = req.query.guildId as string;
|
const guildId = req.query.guildId as string;
|
||||||
|
|
||||||
const guild = await Guild.findOne({ _id: guildId });
|
const guild = await Guild.findById(guildId);
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
res.status(404).end();
|
res.status(404).end();
|
||||||
return;
|
return;
|
||||||
|
@ -9,7 +9,7 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
|
|||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId, "GuildId");
|
const inventory = await getInventory(accountId, "GuildId");
|
||||||
if (inventory.GuildId) {
|
if (inventory.GuildId) {
|
||||||
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
const guild = await Guild.findById(inventory.GuildId);
|
||||||
if (guild) {
|
if (guild) {
|
||||||
const log: Record<string, IGuildLogEntryClient[]> = {
|
const log: Record<string, IGuildLogEntryClient[]> = {
|
||||||
RoomChanges: [],
|
RoomChanges: [],
|
||||||
|
@ -4,7 +4,7 @@ import { Account } from "@/src/models/loginModel";
|
|||||||
|
|
||||||
const logoutController: RequestHandler = async (req, res) => {
|
const logoutController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const account = await Account.findOne({ _id: accountId });
|
const account = await Account.findById(accountId);
|
||||||
if (account) {
|
if (account) {
|
||||||
account.Nonce = 0;
|
account.Nonce = 0;
|
||||||
await account.save();
|
await account.save();
|
||||||
|
@ -42,7 +42,7 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
|
|||||||
|
|
||||||
guild.RosterActivity ??= [];
|
guild.RosterActivity ??= [];
|
||||||
if (isKick) {
|
if (isKick) {
|
||||||
const kickee = (await Account.findOne({ _id: payload.userId }))!;
|
const kickee = (await Account.findById(payload.userId))!;
|
||||||
guild.RosterActivity.push({
|
guild.RosterActivity.push({
|
||||||
dateTime: new Date(),
|
dateTime: new Date(),
|
||||||
entryType: 12,
|
entryType: 12,
|
||||||
|
@ -8,7 +8,7 @@ import { RequestHandler } from "express";
|
|||||||
export const setGuildMotdController: RequestHandler = async (req, res) => {
|
export const setGuildMotdController: RequestHandler = async (req, res) => {
|
||||||
const account = await getAccountForRequest(req);
|
const account = await getAccountForRequest(req);
|
||||||
const inventory = await getInventory(account._id.toString(), "GuildId");
|
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))) {
|
if (!(await hasGuildPermission(guild, account._id, GuildPermission.Herald))) {
|
||||||
res.status(400).json("Invalid permission");
|
res.status(400).json("Invalid permission");
|
||||||
return;
|
return;
|
||||||
|
@ -12,7 +12,7 @@ export const getAccountInfoController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
const guildMember = await GuildMember.findOne({ accountId: account._id, status: 0 }, "guildId rank");
|
const guildMember = await GuildMember.findOne({ accountId: account._id, status: 0 }, "guildId rank");
|
||||||
if (guildMember) {
|
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.GuildId = guildMember.guildId.toString();
|
||||||
info.GuildPermissions = guild.Ranks[guildMember.rank].Permissions;
|
info.GuildPermissions = guild.Ranks[guildMember.rank].Permissions;
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,13 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
|
|||||||
res.status(400).end();
|
res.status(400).end();
|
||||||
return;
|
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) {
|
if (!account) {
|
||||||
res.status(400).send("No account or guild ID specified");
|
res.status(400).send("No account or guild ID specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const inventory = (await Inventory.findOne({ accountOwnerId: account._id }))!;
|
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 = {
|
const result: IPlayerProfileViewingDataResult = {
|
||||||
AccountId: toOid(account._id),
|
AccountId: toOid(account._id),
|
||||||
@ -88,7 +88,7 @@ export const getProfileViewingDataController: RequestHandler = async (req, res)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inventory.GuildId) {
|
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.GuildId = toOid(inventory.GuildId);
|
||||||
result.GuildName = guild.Name;
|
result.GuildName = guild.Name;
|
||||||
result.GuildTier = guild.Tier;
|
result.GuildTier = guild.Tier;
|
||||||
|
@ -37,7 +37,7 @@ export const getGuildForRequestEx = async (
|
|||||||
if (!inventory.GuildId || inventory.GuildId.toString() != guildId) {
|
if (!inventory.GuildId || inventory.GuildId.toString() != guildId) {
|
||||||
throw new Error("Account is not in the guild that it has sent a request for");
|
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) {
|
if (!guild) {
|
||||||
throw new Error("Account thinks it is in a guild that doesn't exist");
|
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>> => {
|
export const getMessage = async (messageId: string): Promise<HydratedDocument<IMessageDatabase>> => {
|
||||||
const message = await Inbox.findOne({ _id: messageId });
|
const message = await Inbox.findById(messageId);
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
throw new Error(`Message not found ${messageId}`);
|
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> => {
|
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) {
|
if (!ship) {
|
||||||
throw new Error(`error finding a ship with id ${shipId.toString()}`);
|
throw new Error(`error finding a ship with id ${shipId.toString()}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user