feat: track ClassChanges in clan log
All checks were successful
Build / build (20) (push) Successful in 42s
Build / build (22) (push) Successful in 1m3s
Build / build (18) (push) Successful in 1m12s
Build / build (18) (pull_request) Successful in 48s
Build / build (22) (pull_request) Successful in 1m3s
Build / build (20) (pull_request) Successful in 1m0s

This commit is contained in:
Sainan 2025-03-11 16:38:45 +01:00
parent 38dfe14776
commit 911823b9e1
4 changed files with 56 additions and 5 deletions

View File

@ -20,6 +20,12 @@ export const contributeGuildClassController: RequestHandler = async (req, res) =
for (let i = guild.Class; i != guild.CeremonyClass; ++i) { for (let i = guild.Class; i != guild.CeremonyClass; ++i) {
guild.CeremonyEndo += (i + 1) * 1000; guild.CeremonyEndo += (i + 1) * 1000;
} }
guild.ClassChanges ??= [];
guild.ClassChanges.push({
dateTime: new Date(),
entryType: 13,
details: guild.CeremonyClass
});
} }
guild.CeremonyContributors.push(new Types.ObjectId(accountId)); guild.CeremonyContributors.push(new Types.ObjectId(accountId));

View File

@ -1,11 +1,37 @@
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"; import { RequestHandler } from "express";
export const getGuildLogController: RequestHandler = (_req, res) => { export const getGuildLogController: RequestHandler = async (req, res) => {
res.json({ const log: Record<string, IGuildLogEntryClient[]> = {
RoomChanges: [], RoomChanges: [],
TechChanges: [], TechChanges: [],
RosterActivity: [], RosterActivity: [],
StandingsUpdates: [], StandingsUpdates: [],
ClassChanges: [] 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;
}

View File

@ -5,7 +5,8 @@ import {
ITechProjectClient, ITechProjectClient,
IDojoDecoDatabase, IDojoDecoDatabase,
ILongMOTD, ILongMOTD,
IGuildMemberDatabase IGuildMemberDatabase,
IGuildLogClassChange
} from "@/src/types/guildTypes"; } from "@/src/types/guildTypes";
import { Document, Model, model, Schema, Types } from "mongoose"; import { Document, Model, model, Schema, Types } from "mongoose";
import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel"; import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
@ -69,6 +70,15 @@ const longMOTDSchema = new Schema<ILongMOTD>(
{ _id: false } { _id: false }
); );
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
{
dateTime: Date,
entryType: Number,
details: Number
},
{ _id: false }
);
const guildSchema = new Schema<IGuildDatabase>( const guildSchema = new Schema<IGuildDatabase>(
{ {
Name: { type: String, required: true, unique: true }, Name: { type: String, required: true, unique: true },
@ -89,7 +99,8 @@ const guildSchema = new Schema<IGuildDatabase>(
CeremonyClass: Number, CeremonyClass: Number,
CeremonyContributors: { type: [Types.ObjectId], default: undefined }, CeremonyContributors: { type: [Types.ObjectId], default: undefined },
CeremonyResetDate: Date, CeremonyResetDate: Date,
CeremonyEndo: Number CeremonyEndo: Number,
ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
}, },
{ id: false } { id: false }
); );

View File

@ -46,6 +46,8 @@ export interface IGuildDatabase {
CeremonyEndo?: number; CeremonyEndo?: number;
CeremonyContributors?: Types.ObjectId[]; CeremonyContributors?: Types.ObjectId[];
CeremonyResetDate?: Date; CeremonyResetDate?: Date;
ClassChanges?: IGuildLogClassChange[];
} }
export interface ILongMOTD { export interface ILongMOTD {
@ -160,3 +162,9 @@ export interface ITechProjectClient {
export interface ITechProjectDatabase extends Omit<ITechProjectClient, "CompletionDate"> { export interface ITechProjectDatabase extends Omit<ITechProjectClient, "CompletionDate"> {
CompletionDate?: Date; CompletionDate?: Date;
} }
export interface IGuildLogClassChange {
dateTime: Date;
entryType: number;
details: number;
}