From 818e09d4af2d2ed7068f37f06c423d01f5e6a0d0 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 16 Mar 2025 08:16:11 -0700 Subject: [PATCH] fix: only track clan log dateTime once contributions are done (#1210) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1210 --- src/controllers/api/getGuildLogController.ts | 4 +-- src/controllers/api/guildTechController.ts | 8 ++---- .../api/startDojoRecipeController.ts | 1 - src/models/guildModel.ts | 26 +++++++++++++------ src/types/guildTypes.ts | 16 ++++++++---- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/controllers/api/getGuildLogController.ts b/src/controllers/api/getGuildLogController.ts index 47c94b631..67940fde7 100644 --- a/src/controllers/api/getGuildLogController.ts +++ b/src/controllers/api/getGuildLogController.ts @@ -20,14 +20,14 @@ export const getGuildLogController: RequestHandler = async (req, res) => { }; guild.RoomChanges?.forEach(entry => { log.RoomChanges.push({ - dateTime: toMongoDate(entry.dateTime), + dateTime: toMongoDate(entry.dateTime ?? new Date()), entryType: entry.entryType, details: entry.details }); }); guild.TechChanges?.forEach(entry => { log.TechChanges.push({ - dateTime: toMongoDate(entry.dateTime), + dateTime: toMongoDate(entry.dateTime ?? new Date()), entryType: entry.entryType, details: entry.details }); diff --git a/src/controllers/api/guildTechController.ts b/src/controllers/api/guildTechController.ts index f9a2e9fb1..fab5cf0b5 100644 --- a/src/controllers/api/guildTechController.ts +++ b/src/controllers/api/guildTechController.ts @@ -216,10 +216,6 @@ export const guildTechController: RequestHandler = async (req, res) => { const project = guild.TechProjects!.find(x => x.ItemType == data.RecipeType)!; project.State = 0; guild.ActiveDojoColorResearch = data.RecipeType; - const entry = guild.TechChanges?.find(x => x.details == data.RecipeType); - if (entry) { - entry.dateTime = new Date(); - } await guild.save(); res.end(); } else { @@ -252,11 +248,11 @@ const setTechLogState = ( if (entry.entryType == state) { return false; } - entry.dateTime = dateTime ?? new Date(); + entry.dateTime = dateTime; entry.entryType = state; } else { guild.TechChanges.push({ - dateTime: dateTime ?? new Date(), + dateTime: dateTime, entryType: state, details: type }); diff --git a/src/controllers/api/startDojoRecipeController.ts b/src/controllers/api/startDojoRecipeController.ts index 04131d656..d2865165b 100644 --- a/src/controllers/api/startDojoRecipeController.ts +++ b/src/controllers/api/startDojoRecipeController.ts @@ -39,7 +39,6 @@ export const startDojoRecipeController: RequestHandler = async (req, res) => { guild.RoomChanges ??= []; guild.RoomChanges.push({ - dateTime: new Date(), entryType: 2, details: request.PlacedComponent.pf, componentId: componentId diff --git a/src/models/guildModel.ts b/src/models/guildModel.ts index 23d28b362..30057c762 100644 --- a/src/models/guildModel.ts +++ b/src/models/guildModel.ts @@ -6,9 +6,10 @@ import { ILongMOTD, IGuildMemberDatabase, IGuildLogEntryNumber, - IGuildLogEntryString, IGuildRank, - IGuildLogRoomChange + IGuildLogRoomChange, + IGuildLogEntryRoster, + IGuildLogEntryContributable } from "@/src/types/guildTypes"; import { Document, Model, model, Schema, Types } from "mongoose"; import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel"; @@ -108,7 +109,17 @@ const defaultRanks: IGuildRank[] = [ } ]; -const guildLogEntryStringSchema = new Schema( +const guildLogRoomChangeSchema = new Schema( + { + dateTime: Date, + entryType: Number, + details: String, + componentId: Types.ObjectId + }, + { _id: false } +); + +const guildLogEntryContributableSchema = new Schema( { dateTime: Date, entryType: Number, @@ -117,12 +128,11 @@ const guildLogEntryStringSchema = new Schema( { _id: false } ); -const guildLogRoomChangeSchema = new Schema( +const guildLogEntryRosterSchema = new Schema( { dateTime: Date, entryType: Number, - details: String, - componentId: Types.ObjectId + details: String }, { _id: false } ); @@ -161,8 +171,8 @@ const guildSchema = new Schema( CeremonyResetDate: Date, CeremonyEndo: Number, RoomChanges: { type: [guildLogRoomChangeSchema], default: undefined }, - TechChanges: { type: [guildLogEntryStringSchema], default: undefined }, - RosterActivity: { type: [guildLogEntryStringSchema], default: undefined }, + TechChanges: { type: [guildLogEntryContributableSchema], default: undefined }, + RosterActivity: { type: [guildLogEntryRosterSchema], default: undefined }, ClassChanges: { type: [guildLogEntryNumberSchema], default: undefined } }, { id: false } diff --git a/src/types/guildTypes.ts b/src/types/guildTypes.ts index ee10656b8..f563e281f 100644 --- a/src/types/guildTypes.ts +++ b/src/types/guildTypes.ts @@ -50,8 +50,8 @@ export interface IGuildDatabase { CeremonyResetDate?: Date; RoomChanges?: IGuildLogRoomChange[]; - TechChanges?: IGuildLogEntryString[]; - RosterActivity?: IGuildLogEntryString[]; + TechChanges?: IGuildLogEntryContributable[]; + RosterActivity?: IGuildLogEntryRoster[]; ClassChanges?: IGuildLogEntryNumber[]; } @@ -190,16 +190,22 @@ export interface ITechProjectDatabase extends Omit