SpaceNinjaServer/src/controllers/api/getGuildLogController.ts
Sainan be6e5ce250
All checks were successful
Build / build (22) (push) Successful in 43s
Build / build (20) (push) Successful in 1m2s
Build / build (18) (push) Successful in 56s
Build Docker image / docker (push) Successful in 32s
feat: track ClassChanges in clan log (#1157)
Re #1152

Reviewed-on: #1157
2025-03-12 01:08:15 -07:00

38 lines
1.2 KiB
TypeScript

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";
import { RequestHandler } from "express";
export const getGuildLogController: RequestHandler = async (req, res) => {
const log: Record<string, IGuildLogEntryClient[]> = {
RoomChanges: [],
TechChanges: [],
RosterActivity: [],
StandingsUpdates: [],
ClassChanges: []
};
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
if (inventory.GuildId) {
const guild = await Guild.findOne({ _id: inventory.GuildId });
if (guild) {
guild.ClassChanges?.forEach(entry => {
log.ClassChanges.push({
dateTime: toMongoDate(entry.dateTime),
entryType: entry.entryType,
details: entry.details
});
});
}
}
res.json(log);
};
interface IGuildLogEntryClient {
dateTime: IMongoDate;
entryType: number;
details: number | string;
}