feat: track RosterActivity in clan log (#1173)

Reviewed-on: OpenWF/SpaceNinjaServer#1173
This commit is contained in:
Sainan 2025-03-13 10:46:08 -07:00
parent 3a995ef6d1
commit 6508d16190
5 changed files with 60 additions and 15 deletions

View File

@ -1,22 +1,36 @@
import { Guild, GuildMember } from "@/src/models/guildModel";
import { getGuildClient, updateInventoryForConfirmedGuildJoin } from "@/src/services/guildService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
import { RequestHandler } from "express";
import { Types } from "mongoose";
export const confirmGuildInvitationController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const account = await getAccountForRequest(req);
const guildMember = await GuildMember.findOne({
accountId: accountId,
accountId: account._id,
guildId: req.query.clanId as string
});
if (guildMember) {
guildMember.status = 0;
await guildMember.save();
await updateInventoryForConfirmedGuildJoin(accountId, new Types.ObjectId(req.query.clanId as string));
await updateInventoryForConfirmedGuildJoin(
account._id.toString(),
new Types.ObjectId(req.query.clanId as string)
);
const guild = (await Guild.findOne({ _id: req.query.clanId as string }))!;
guild.RosterActivity ??= [];
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 6,
details: getSuffixedName(account)
});
await guild.save();
res.json({
...(await getGuildClient(guild, accountId)),
...(await getGuildClient(guild, account._id.toString())),
InventoryChanges: {
Recipes: [
{

View File

@ -25,6 +25,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
details: entry.details
});
});
guild.RosterActivity?.forEach(entry => {
log.RosterActivity.push({
dateTime: toMongoDate(entry.dateTime),
entryType: entry.entryType,
details: entry.details
});
});
guild.ClassChanges?.forEach(entry => {
log.ClassChanges.push({
dateTime: toMongoDate(entry.dateTime),

View File

@ -1,9 +1,12 @@
import { GuildMember } from "@/src/models/guildModel";
import { Account } from "@/src/models/loginModel";
import { getGuildForRequest } from "@/src/services/guildService";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
import { RequestHandler } from "express";
export const removeFromGuildController: RequestHandler = async (req, res) => {
const account = await getAccountForRequest(req);
const guild = await getGuildForRequest(req);
// TODO: Check permissions
const payload = JSON.parse(String(req.body)) as IRemoveFromGuildRequest;
@ -32,6 +35,25 @@ export const removeFromGuildController: RequestHandler = async (req, res) => {
}
await GuildMember.deleteOne({ _id: guildMember._id });
guild.RosterActivity ??= [];
if (account._id.equals(payload.userId)) {
// Leave
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 7,
details: getSuffixedName(account)
});
} else {
// Kick
const kickee = (await Account.findOne({ _id: payload.userId }))!;
guild.RosterActivity.push({
dateTime: new Date(),
entryType: 12,
details: getSuffixedName(kickee) + "," + getSuffixedName(account)
});
}
await guild.save();
res.json({
_id: payload.userId,
ItemToRemove: "/Lotus/Types/Keys/DojoKey",

View File

@ -5,8 +5,8 @@ import {
IDojoDecoDatabase,
ILongMOTD,
IGuildMemberDatabase,
IGuildLogClassChange,
IGuildLogTechChange,
IGuildLogEntryNumber,
IGuildLogEntryString,
IGuildRank
} from "@/src/types/guildTypes";
import { Document, Model, model, Schema, Types } from "mongoose";
@ -106,7 +106,7 @@ const defaultRanks: IGuildRank[] = [
}
];
const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
const guildLogEntryStringSchema = new Schema<IGuildLogEntryString>(
{
dateTime: Date,
entryType: Number,
@ -115,7 +115,7 @@ const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
{ _id: false }
);
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
const guildLogEntryNumberSchema = new Schema<IGuildLogEntryNumber>(
{
dateTime: Date,
entryType: Number,
@ -146,8 +146,9 @@ const guildSchema = new Schema<IGuildDatabase>(
CeremonyContributors: { type: [Types.ObjectId], default: undefined },
CeremonyResetDate: Date,
CeremonyEndo: Number,
TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
TechChanges: { type: [guildLogEntryStringSchema], default: undefined },
RosterActivity: { type: [guildLogEntryStringSchema], default: undefined },
ClassChanges: { type: [guildLogEntryNumberSchema], default: undefined }
},
{ id: false }
);

View File

@ -48,8 +48,9 @@ export interface IGuildDatabase {
CeremonyContributors?: Types.ObjectId[];
CeremonyResetDate?: Date;
TechChanges?: IGuildLogTechChange[];
ClassChanges?: IGuildLogClassChange[];
TechChanges?: IGuildLogEntryString[];
RosterActivity?: IGuildLogEntryString[];
ClassChanges?: IGuildLogEntryNumber[];
}
export interface ILongMOTD {
@ -186,13 +187,13 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
CompletionDate?: Date;
}
export interface IGuildLogTechChange {
export interface IGuildLogEntryString {
dateTime: Date;
entryType: number;
details: string;
}
export interface IGuildLogClassChange {
export interface IGuildLogEntryNumber {
dateTime: Date;
entryType: number;
details: number;