2025-03-12 01:08:15 -07:00
|
|
|
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
|
|
|
import { Guild } from "@/src/models/guildModel";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { IMongoDate } from "@/src/types/commonTypes";
|
2024-05-16 01:34:38 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
|
2025-03-12 01:08:15 -07:00
|
|
|
export const getGuildLogController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-03-16 08:16:49 -07:00
|
|
|
const inventory = await getInventory(accountId, "GuildId");
|
2025-03-12 01:08:15 -07:00
|
|
|
if (inventory.GuildId) {
|
|
|
|
const guild = await Guild.findOne({ _id: inventory.GuildId });
|
|
|
|
if (guild) {
|
2025-03-12 05:10:26 -07:00
|
|
|
const log: Record<string, IGuildLogEntryClient[]> = {
|
|
|
|
RoomChanges: [],
|
|
|
|
TechChanges: [],
|
|
|
|
RosterActivity: [],
|
|
|
|
StandingsUpdates: [],
|
|
|
|
ClassChanges: []
|
|
|
|
};
|
2025-03-14 02:07:08 -07:00
|
|
|
guild.RoomChanges?.forEach(entry => {
|
|
|
|
log.RoomChanges.push({
|
2025-03-16 08:16:11 -07:00
|
|
|
dateTime: toMongoDate(entry.dateTime ?? new Date()),
|
2025-03-14 02:07:08 -07:00
|
|
|
entryType: entry.entryType,
|
|
|
|
details: entry.details
|
|
|
|
});
|
|
|
|
});
|
2025-03-12 07:59:20 -07:00
|
|
|
guild.TechChanges?.forEach(entry => {
|
|
|
|
log.TechChanges.push({
|
2025-03-16 08:16:11 -07:00
|
|
|
dateTime: toMongoDate(entry.dateTime ?? new Date()),
|
2025-03-12 07:59:20 -07:00
|
|
|
entryType: entry.entryType,
|
|
|
|
details: entry.details
|
|
|
|
});
|
|
|
|
});
|
2025-03-13 10:46:08 -07:00
|
|
|
guild.RosterActivity?.forEach(entry => {
|
|
|
|
log.RosterActivity.push({
|
|
|
|
dateTime: toMongoDate(entry.dateTime),
|
|
|
|
entryType: entry.entryType,
|
|
|
|
details: entry.details
|
|
|
|
});
|
|
|
|
});
|
2025-03-12 01:08:15 -07:00
|
|
|
guild.ClassChanges?.forEach(entry => {
|
|
|
|
log.ClassChanges.push({
|
|
|
|
dateTime: toMongoDate(entry.dateTime),
|
|
|
|
entryType: entry.entryType,
|
|
|
|
details: entry.details
|
|
|
|
});
|
|
|
|
});
|
2025-03-12 05:10:26 -07:00
|
|
|
res.json(log);
|
|
|
|
return;
|
2025-03-12 01:08:15 -07:00
|
|
|
}
|
|
|
|
}
|
2025-03-12 05:10:26 -07:00
|
|
|
res.sendStatus(200);
|
2024-05-16 01:34:38 +02:00
|
|
|
};
|
2025-03-12 01:08:15 -07:00
|
|
|
|
|
|
|
interface IGuildLogEntryClient {
|
|
|
|
dateTime: IMongoDate;
|
|
|
|
entryType: number;
|
|
|
|
details: number | string;
|
|
|
|
}
|