feat: alliance motd
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (20) (push) Successful in 35s
				
			
		
			
				
	
				Build / build (18) (push) Successful in 1m10s
				
			
		
			
				
	
				Build / build (18) (pull_request) Successful in 37s
				
			
		
			
				
	
				Build / build (22) (push) Successful in 1m7s
				
			
		
			
				
	
				Build / build (20) (pull_request) Successful in 1m8s
				
			
		
			
				
	
				Build / build (22) (pull_request) Successful in 1m9s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (20) (push) Successful in 35s
				
			Build / build (18) (push) Successful in 1m10s
				
			Build / build (18) (pull_request) Successful in 37s
				
			Build / build (22) (push) Successful in 1m7s
				
			Build / build (20) (pull_request) Successful in 1m8s
				
			Build / build (22) (pull_request) Successful in 1m9s
				
			This commit is contained in:
		
							parent
							
								
									d4d887a5a4
								
							
						
					
					
						commit
						e3530f3f98
					
				@ -1,21 +1,44 @@
 | 
				
			|||||||
import { Guild } from "@/src/models/guildModel";
 | 
					import { Alliance, Guild, GuildMember } from "@/src/models/guildModel";
 | 
				
			||||||
import { hasGuildPermission } from "@/src/services/guildService";
 | 
					import { hasGuildPermissionEx } from "@/src/services/guildService";
 | 
				
			||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					import { getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
 | 
					import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
 | 
				
			||||||
import { GuildPermission } from "@/src/types/guildTypes";
 | 
					import { GuildPermission, ILongMOTD } from "@/src/types/guildTypes";
 | 
				
			||||||
import { RequestHandler } from "express";
 | 
					import { RequestHandler } from "express";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const setGuildMotdController: RequestHandler = async (req, res) => {
 | 
					export const setGuildMotdController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const account = await getAccountForRequest(req);
 | 
					    const account = await getAccountForRequest(req);
 | 
				
			||||||
    const inventory = await getInventory(account._id.toString(), "GuildId");
 | 
					    const inventory = await getInventory(account._id.toString(), "GuildId");
 | 
				
			||||||
    const guild = (await Guild.findById(inventory.GuildId!))!;
 | 
					    const guild = (await Guild.findById(inventory.GuildId!))!;
 | 
				
			||||||
    if (!(await hasGuildPermission(guild, account._id, GuildPermission.Herald))) {
 | 
					    const member = (await GuildMember.findOne({ accountId: account._id, guildId: guild._id }))!;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const IsLongMOTD = "longMOTD" in req.query;
 | 
				
			||||||
 | 
					    const MOTD = req.body ? String(req.body) : undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ("alliance" in req.query) {
 | 
				
			||||||
 | 
					        if (member.rank > 1) {
 | 
				
			||||||
            res.status(400).json("Invalid permission");
 | 
					            res.status(400).json("Invalid permission");
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const IsLongMOTD = "longMOTD" in req.query;
 | 
					        const alliance = (await Alliance.findById(guild.AllianceId!))!;
 | 
				
			||||||
    const MOTD = req.body ? String(req.body) : undefined;
 | 
					        const motd = MOTD
 | 
				
			||||||
 | 
					            ? ({
 | 
				
			||||||
 | 
					                  message: MOTD,
 | 
				
			||||||
 | 
					                  authorName: getSuffixedName(account),
 | 
				
			||||||
 | 
					                  authorGuildName: guild.Name
 | 
				
			||||||
 | 
					              } satisfies ILongMOTD)
 | 
				
			||||||
 | 
					            : undefined;
 | 
				
			||||||
 | 
					        if (IsLongMOTD) {
 | 
				
			||||||
 | 
					            alliance.LongMOTD = motd;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            alliance.MOTD = motd;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        await alliance.save();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (!hasGuildPermissionEx(guild, member, GuildPermission.Herald)) {
 | 
				
			||||||
 | 
					            res.status(400).json("Invalid permission");
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (IsLongMOTD) {
 | 
					        if (IsLongMOTD) {
 | 
				
			||||||
            if (MOTD) {
 | 
					            if (MOTD) {
 | 
				
			||||||
@ -30,6 +53,7 @@ export const setGuildMotdController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
            guild.MOTD = MOTD ?? "";
 | 
					            guild.MOTD = MOTD ?? "";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        await guild.save();
 | 
					        await guild.save();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.json({ IsLongMOTD, MOTD });
 | 
					    res.json({ IsLongMOTD, MOTD });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -71,7 +71,8 @@ const techProjectSchema = new Schema<ITechProjectDatabase>(
 | 
				
			|||||||
const longMOTDSchema = new Schema<ILongMOTD>(
 | 
					const longMOTDSchema = new Schema<ILongMOTD>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        message: String,
 | 
					        message: String,
 | 
				
			||||||
        authorName: String
 | 
					        authorName: String,
 | 
				
			||||||
 | 
					        authorGuildName: String
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    { _id: false }
 | 
					    { _id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
				
			|||||||
@ -581,6 +581,8 @@ export const getAllianceClient = async (
 | 
				
			|||||||
    return {
 | 
					    return {
 | 
				
			||||||
        _id: toOid(alliance._id),
 | 
					        _id: toOid(alliance._id),
 | 
				
			||||||
        Name: alliance.Name,
 | 
					        Name: alliance.Name,
 | 
				
			||||||
 | 
					        MOTD: alliance.MOTD,
 | 
				
			||||||
 | 
					        LongMOTD: alliance.LongMOTD,
 | 
				
			||||||
        Clans: clans,
 | 
					        Clans: clans,
 | 
				
			||||||
        AllianceVault: {
 | 
					        AllianceVault: {
 | 
				
			||||||
            DojoRefundRegularCredits: alliance.VaultRegularCredits
 | 
					            DojoRefundRegularCredits: alliance.VaultRegularCredits
 | 
				
			||||||
 | 
				
			|||||||
@ -64,7 +64,7 @@ export interface IGuildDatabase {
 | 
				
			|||||||
export interface ILongMOTD {
 | 
					export interface ILongMOTD {
 | 
				
			||||||
    message: string;
 | 
					    message: string;
 | 
				
			||||||
    authorName: string;
 | 
					    authorName: string;
 | 
				
			||||||
    authorGuildName?: "";
 | 
					    authorGuildName?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 32 seems to be reserved
 | 
					// 32 seems to be reserved
 | 
				
			||||||
@ -320,4 +320,3 @@ export interface IAllianceMemberDatabase {
 | 
				
			|||||||
// TODO: GET /api/divvyAllianceVault.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0&allianceId=000000000000000000000069&credits=0
 | 
					// TODO: GET /api/divvyAllianceVault.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0&allianceId=000000000000000000000069&credits=0
 | 
				
			||||||
// TODO: GET /api/removeFromAlliance.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0
 | 
					// TODO: GET /api/removeFromAlliance.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=663e9be9f741eeb5782f9df0
 | 
				
			||||||
// TODO: GET /api/setAllianceGuildPermissions.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=000000000000000000000042&perms=2
 | 
					// TODO: GET /api/setAllianceGuildPermissions.php?accountId=6633b81e9dba0b714f28ff02&nonce=5702391171614479&ct=MSI&guildId=000000000000000000000042&perms=2
 | 
				
			||||||
// TODO: Handle alliance in setGuildMotd
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user