diff --git a/src/controllers/api/createGuildController.ts b/src/controllers/api/createGuildController.ts index 8905fb11..dc0930b2 100644 --- a/src/controllers/api/createGuildController.ts +++ b/src/controllers/api/createGuildController.ts @@ -1,9 +1,8 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; -import { Inventory } from "@/src/models/inventoryModels/inventoryModel"; import { Guild, GuildMember } from "@/src/models/guildModel"; -import { addRecipes } from "@/src/services/inventoryService"; +import { updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService"; export const createGuildController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); @@ -23,22 +22,7 @@ export const createGuildController: RequestHandler = async (req, res) => { rank: 0 }); - // Update inventory - const inventory = await Inventory.findOne({ accountOwnerId: accountId }); - if (inventory) { - // Set GuildId - inventory.GuildId = guild._id; - - // Give clan key blueprint - addRecipes(inventory, [ - { - ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", - ItemCount: 1 - } - ]); - - await inventory.save(); - } + await updateInventoryForConfirmedGuildJoin(accountId, guild._id); res.json(guild); }; diff --git a/src/services/guildService.ts b/src/services/guildService.ts index a8cd3bd3..2a62ed06 100644 --- a/src/services/guildService.ts +++ b/src/services/guildService.ts @@ -1,6 +1,6 @@ import { Request } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; -import { getInventory } from "@/src/services/inventoryService"; +import { addRecipes, getInventory } from "@/src/services/inventoryService"; import { Guild, TGuildDatabaseDocument } from "@/src/models/guildModel"; import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel"; import { @@ -196,12 +196,27 @@ export const processDojoBuildMaterialsGathered = (guild: TGuildDatabaseDocument, }; export const fillInInventoryDataForGuildMember = async (member: IGuildMemberClient): Promise => { - const inventory = (await Inventory.findOne( - { - accountOwnerId: member._id.$oid - }, - "PlayerLevel ActiveAvatarImageType" - ))!; + const inventory = await getInventory(member._id.$oid, "PlayerLevel ActiveAvatarImageType"); member.PlayerLevel = config.spoofMasteryRank == -1 ? inventory.PlayerLevel : config.spoofMasteryRank; member.ActiveAvatarImageType = inventory.ActiveAvatarImageType; }; + +export const updateInventoryForConfirmedGuildJoin = async ( + accountId: string, + guildId: Types.ObjectId +): Promise => { + const inventory = await getInventory(accountId); + + // Set GuildId + inventory.GuildId = guildId; + + // Give clan key blueprint + addRecipes(inventory, [ + { + ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint", + ItemCount: 1 + } + ]); + + await inventory.save(); +};