feat: addToGuild
This commit is contained in:
parent
4389b5d12c
commit
5cede0f3a7
75
src/controllers/api/addToGuildController.ts
Normal file
75
src/controllers/api/addToGuildController.ts
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import { Guild, GuildMember } from "@/src/models/guildModel";
|
||||||
|
import { Account } from "@/src/models/loginModel";
|
||||||
|
import { fillInInventoryDataForGuildMember } from "@/src/services/guildService";
|
||||||
|
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";
|
||||||
|
import { IGuildMemberClient } from "@/src/types/guildTypes";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
const guild = (await Guild.findOne({ _id: payload.GuildId.$oid }, "Name"))!;
|
||||||
|
// TODO: Check sender is allowed to send invites for this guild.
|
||||||
|
|
||||||
|
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 senderAccount = await getAccountForRequest(req);
|
||||||
|
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",
|
||||||
|
Tag: guild.Name + "#000"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
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;
|
||||||
|
}
|
@ -32,6 +32,10 @@ export interface IMessage {
|
|||||||
transmission?: string;
|
transmission?: string;
|
||||||
arg?: Arg[];
|
arg?: Arg[];
|
||||||
r?: boolean;
|
r?: boolean;
|
||||||
|
contextInfo?: string;
|
||||||
|
acceptAction?: string;
|
||||||
|
declineAction?: string;
|
||||||
|
hasAccountAction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Arg {
|
export interface Arg {
|
||||||
@ -100,7 +104,11 @@ const messageSchema = new Schema<IMessageDatabase>(
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
default: undefined
|
default: undefined
|
||||||
}
|
},
|
||||||
|
contextInfo: String,
|
||||||
|
acceptAction: String,
|
||||||
|
declineAction: String,
|
||||||
|
hasAccountAction: Boolean
|
||||||
},
|
},
|
||||||
{ timestamps: { createdAt: "date", updatedAt: false }, id: false }
|
{ timestamps: { createdAt: "date", updatedAt: false }, id: false }
|
||||||
);
|
);
|
||||||
|
@ -1249,7 +1249,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
|
|||||||
Drones: [droneSchema],
|
Drones: [droneSchema],
|
||||||
|
|
||||||
//Active profile ico
|
//Active profile ico
|
||||||
ActiveAvatarImageType: String,
|
ActiveAvatarImageType: { type: String, default: "/Lotus/Types/StoreItems/AvatarImages/AvatarImageDefault" },
|
||||||
|
|
||||||
// open location store like EidolonPlainsDiscoverable or OrbVallisCaveDiscoverable
|
// open location store like EidolonPlainsDiscoverable or OrbVallisCaveDiscoverable
|
||||||
DiscoveredMarkers: [Schema.Types.Mixed],
|
DiscoveredMarkers: [Schema.Types.Mixed],
|
||||||
|
@ -4,6 +4,7 @@ import { abortDojoComponentController } from "@/src/controllers/api/abortDojoCom
|
|||||||
import { abortDojoComponentDestructionController } from "@/src/controllers/api/abortDojoComponentDestructionController";
|
import { abortDojoComponentDestructionController } from "@/src/controllers/api/abortDojoComponentDestructionController";
|
||||||
import { activateRandomModController } from "@/src/controllers/api/activateRandomModController";
|
import { activateRandomModController } from "@/src/controllers/api/activateRandomModController";
|
||||||
import { addFriendImageController } from "@/src/controllers/api/addFriendImageController";
|
import { addFriendImageController } from "@/src/controllers/api/addFriendImageController";
|
||||||
|
import { addToGuildController } from "@/src/controllers/api/addToGuildController";
|
||||||
import { arcaneCommonController } from "@/src/controllers/api/arcaneCommonController";
|
import { arcaneCommonController } from "@/src/controllers/api/arcaneCommonController";
|
||||||
import { archonFusionController } from "@/src/controllers/api/archonFusionController";
|
import { archonFusionController } from "@/src/controllers/api/archonFusionController";
|
||||||
import { artifactsController } from "@/src/controllers/api/artifactsController";
|
import { artifactsController } from "@/src/controllers/api/artifactsController";
|
||||||
@ -150,6 +151,7 @@ apiRouter.get("/updateSession.php", updateSessionGetController);
|
|||||||
apiRouter.post("/abortDojoComponent.php", abortDojoComponentController);
|
apiRouter.post("/abortDojoComponent.php", abortDojoComponentController);
|
||||||
apiRouter.post("/activateRandomMod.php", activateRandomModController);
|
apiRouter.post("/activateRandomMod.php", activateRandomModController);
|
||||||
apiRouter.post("/addFriendImage.php", addFriendImageController);
|
apiRouter.post("/addFriendImage.php", addFriendImageController);
|
||||||
|
apiRouter.post("/addToGuild.php", addToGuildController);
|
||||||
apiRouter.post("/arcaneCommon.php", arcaneCommonController);
|
apiRouter.post("/arcaneCommon.php", arcaneCommonController);
|
||||||
apiRouter.post("/archonFusion.php", archonFusionController);
|
apiRouter.post("/archonFusion.php", archonFusionController);
|
||||||
apiRouter.post("/artifacts.php", artifactsController);
|
apiRouter.post("/artifacts.php", artifactsController);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user