add updateInventoryForConfirmedGuildJoin

This commit is contained in:
Sainan 2025-03-10 19:41:36 +01:00
parent dccb88db6d
commit 4ba1adb2e3
2 changed files with 24 additions and 25 deletions

View File

@ -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);
};

View File

@ -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<void> => {
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<void> => {
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();
};