feat: track ClassChanges in clan log #1157
@ -20,6 +20,12 @@ export const contributeGuildClassController: RequestHandler = async (req, res) =
 | 
			
		||||
        for (let i = guild.Class; i != guild.CeremonyClass; ++i) {
 | 
			
		||||
            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));
 | 
			
		||||
 | 
			
		||||
@ -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";
 | 
			
		||||
 | 
			
		||||
export const getGuildLogController: RequestHandler = (_req, res) => {
 | 
			
		||||
    res.json({
 | 
			
		||||
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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,8 @@ import {
 | 
			
		||||
    ITechProjectClient,
 | 
			
		||||
    IDojoDecoDatabase,
 | 
			
		||||
    ILongMOTD,
 | 
			
		||||
    IGuildMemberDatabase
 | 
			
		||||
    IGuildMemberDatabase,
 | 
			
		||||
    IGuildLogClassChange
 | 
			
		||||
} from "@/src/types/guildTypes";
 | 
			
		||||
import { Document, Model, model, Schema, Types } from "mongoose";
 | 
			
		||||
import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
 | 
			
		||||
@ -69,6 +70,15 @@ const longMOTDSchema = new Schema<ILongMOTD>(
 | 
			
		||||
    { _id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
 | 
			
		||||
    {
 | 
			
		||||
        dateTime: Date,
 | 
			
		||||
        entryType: Number,
 | 
			
		||||
        details: Number
 | 
			
		||||
    },
 | 
			
		||||
    { _id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const guildSchema = new Schema<IGuildDatabase>(
 | 
			
		||||
    {
 | 
			
		||||
        Name: { type: String, required: true, unique: true },
 | 
			
		||||
@ -89,7 +99,8 @@ const guildSchema = new Schema<IGuildDatabase>(
 | 
			
		||||
        CeremonyClass: Number,
 | 
			
		||||
        CeremonyContributors: { type: [Types.ObjectId], default: undefined },
 | 
			
		||||
        CeremonyResetDate: Date,
 | 
			
		||||
        CeremonyEndo: Number
 | 
			
		||||
        CeremonyEndo: Number,
 | 
			
		||||
        ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
 | 
			
		||||
    },
 | 
			
		||||
    { id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
@ -46,6 +46,8 @@ export interface IGuildDatabase {
 | 
			
		||||
    CeremonyEndo?: number;
 | 
			
		||||
    CeremonyContributors?: Types.ObjectId[];
 | 
			
		||||
    CeremonyResetDate?: Date;
 | 
			
		||||
 | 
			
		||||
    ClassChanges?: IGuildLogClassChange[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface ILongMOTD {
 | 
			
		||||
@ -160,3 +162,9 @@ export interface ITechProjectClient {
 | 
			
		||||
export interface ITechProjectDatabase extends Omit<ITechProjectClient, "CompletionDate"> {
 | 
			
		||||
    CompletionDate?: Date;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IGuildLogClassChange {
 | 
			
		||||
    dateTime: Date;
 | 
			
		||||
    entryType: number;
 | 
			
		||||
    details: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user