2025-03-10 16:40:40 -07:00
|
|
|
import { Guild, GuildMember } from "@/src/models/guildModel";
|
|
|
|
import { getGuildClient, updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService";
|
2025-03-13 10:46:08 -07:00
|
|
|
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
2025-03-10 16:40:40 -07:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { Types } from "mongoose";
|
|
|
|
|
|
|
|
export const confirmGuildInvitationController: RequestHandler = async (req, res) => {
|
2025-03-13 10:46:08 -07:00
|
|
|
const account = await getAccountForRequest(req);
|
2025-03-10 16:40:40 -07:00
|
|
|
const guildMember = await GuildMember.findOne({
|
2025-03-13 10:46:08 -07:00
|
|
|
accountId: account._id,
|
2025-03-10 16:40:40 -07:00
|
|
|
guildId: req.query.clanId as string
|
|
|
|
});
|
|
|
|
if (guildMember) {
|
|
|
|
guildMember.status = 0;
|
|
|
|
await guildMember.save();
|
2025-03-13 10:46:08 -07:00
|
|
|
|
|
|
|
await updateInventoryForConfirmedGuildJoin(
|
|
|
|
account._id.toString(),
|
|
|
|
new Types.ObjectId(req.query.clanId as string)
|
|
|
|
);
|
|
|
|
|
2025-03-24 11:32:08 -07:00
|
|
|
const guild = (await Guild.findById(req.query.clanId as string))!;
|
2025-03-13 10:46:08 -07:00
|
|
|
|
|
|
|
guild.RosterActivity ??= [];
|
|
|
|
guild.RosterActivity.push({
|
|
|
|
dateTime: new Date(),
|
|
|
|
entryType: 6,
|
|
|
|
details: getSuffixedName(account)
|
|
|
|
});
|
|
|
|
await guild.save();
|
|
|
|
|
2025-03-10 16:40:40 -07:00
|
|
|
res.json({
|
2025-03-13 10:46:08 -07:00
|
|
|
...(await getGuildClient(guild, account._id.toString())),
|
2025-03-10 16:40:40 -07:00
|
|
|
InventoryChanges: {
|
|
|
|
Recipes: [
|
|
|
|
{
|
|
|
|
ItemType: "/Lotus/Types/Keys/DojoKeyBlueprint",
|
|
|
|
ItemCount: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.end();
|
|
|
|
}
|
|
|
|
};
|