diff --git a/src/controllers/api/getGuildLogController.ts b/src/controllers/api/getGuildLogController.ts index 47c94b63..67940fde 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 f9a2e9fb..fab5cf0b 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 04131d65..d2865165 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 23d28b36..30057c76 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 ee10656b..f563e281 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