diff --git a/src/controllers/api/confirmGuildInvitationController.ts b/src/controllers/api/confirmGuildInvitationController.ts index 070c9c28..7331af03 100644 --- a/src/controllers/api/confirmGuildInvitationController.ts +++ b/src/controllers/api/confirmGuildInvitationController.ts @@ -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: [ { diff --git a/src/controllers/api/getGuildLogController.ts b/src/controllers/api/getGuildLogController.ts index 4d859a65..9d4b82c5 100644 --- a/src/controllers/api/getGuildLogController.ts +++ b/src/controllers/api/getGuildLogController.ts @@ -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), diff --git a/src/controllers/api/removeFromGuildController.ts b/src/controllers/api/removeFromGuildController.ts index c28700e4..3b886099 100644 --- a/src/controllers/api/removeFromGuildController.ts +++ b/src/controllers/api/removeFromGuildController.ts @@ -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", diff --git a/src/models/guildModel.ts b/src/models/guildModel.ts index ec2a8159..195fe611 100644 --- a/src/models/guildModel.ts +++ b/src/models/guildModel.ts @@ -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( +const guildLogEntryStringSchema = new Schema( { dateTime: Date, entryType: Number, @@ -115,7 +115,7 @@ const guildLogTechChangeSchema = new Schema( { _id: false } ); -const guildLogClassChangeSchema = new Schema( +const guildLogEntryNumberSchema = new Schema( { dateTime: Date, entryType: Number, @@ -146,8 +146,9 @@ const guildSchema = new Schema( 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 } ); diff --git a/src/types/guildTypes.ts b/src/types/guildTypes.ts index df7f7031..e62cacc5 100644 --- a/src/types/guildTypes.ts +++ b/src/types/guildTypes.ts @@ -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