2025-03-10 16:40:40 -07:00
|
|
|
import { Guild, GuildMember } from "@/src/models/guildModel";
|
|
|
|
import { Account } from "@/src/models/loginModel";
|
2025-03-14 07:09:28 -07:00
|
|
|
import { fillInInventoryDataForGuildMember, hasGuildPermission } from "@/src/services/guildService";
|
2025-03-10 16:40:40 -07:00
|
|
|
import { createMessage } from "@/src/services/inboxService";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
|
|
|
|
import { IOid } from "@/src/types/commonTypes";
|
2025-03-14 07:09:28 -07:00
|
|
|
import { GuildPermission, IGuildMemberClient } from "@/src/types/guildTypes";
|
2025-03-10 16:40:40 -07:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { ExportFlavour } from "warframe-public-export-plus";
|
|
|
|
|
|
|
|
export const addToGuildController: RequestHandler = async (req, res) => {
|
|
|
|
const payload = JSON.parse(String(req.body)) as IAddToGuildRequest;
|
|
|
|
|
|
|
|
const account = await Account.findOne({ DisplayName: payload.UserName });
|
|
|
|
if (!account) {
|
|
|
|
res.status(400).json("Username does not exist");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-03-24 11:32:08 -07:00
|
|
|
const guild = (await Guild.findById(payload.GuildId.$oid, "Name"))!;
|
2025-03-14 07:09:28 -07:00
|
|
|
const senderAccount = await getAccountForRequest(req);
|
|
|
|
if (!(await hasGuildPermission(guild, senderAccount._id.toString(), GuildPermission.Recruiter))) {
|
|
|
|
res.status(400).json("Invalid permission");
|
|
|
|
}
|
2025-03-10 16:40:40 -07:00
|
|
|
|
|
|
|
if (
|
|
|
|
await GuildMember.exists({
|
|
|
|
accountId: account._id,
|
|
|
|
guildId: payload.GuildId.$oid
|
|
|
|
})
|
|
|
|
) {
|
|
|
|
res.status(400).json("User already invited to clan");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await GuildMember.insertOne({
|
|
|
|
accountId: account._id,
|
|
|
|
guildId: payload.GuildId.$oid,
|
|
|
|
status: 2 // outgoing invite
|
|
|
|
});
|
|
|
|
|
|
|
|
const senderInventory = await getInventory(senderAccount._id.toString(), "ActiveAvatarImageType");
|
|
|
|
await createMessage(account._id.toString(), [
|
|
|
|
{
|
|
|
|
sndr: getSuffixedName(senderAccount),
|
|
|
|
msg: "/Lotus/Language/Menu/Mailbox_ClanInvite_Body",
|
|
|
|
arg: [
|
|
|
|
{
|
|
|
|
Key: "clan",
|
2025-03-11 10:31:56 -07:00
|
|
|
Tag: guild.Name
|
2025-03-10 16:40:40 -07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
sub: "/Lotus/Language/Menu/Mailbox_ClanInvite_Title",
|
|
|
|
icon: ExportFlavour[senderInventory.ActiveAvatarImageType].icon,
|
|
|
|
contextInfo: payload.GuildId.$oid,
|
|
|
|
highPriority: true,
|
|
|
|
acceptAction: "GUILD_INVITE",
|
|
|
|
declineAction: "GUILD_INVITE",
|
|
|
|
hasAccountAction: true
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const member: IGuildMemberClient = {
|
|
|
|
_id: { $oid: account._id.toString() },
|
|
|
|
DisplayName: account.DisplayName,
|
|
|
|
Rank: 7,
|
|
|
|
Status: 2
|
|
|
|
};
|
|
|
|
await fillInInventoryDataForGuildMember(member);
|
|
|
|
res.json({ NewMember: member });
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IAddToGuildRequest {
|
|
|
|
UserName: string;
|
|
|
|
GuildId: IOid;
|
|
|
|
}
|