feat: track TechChanges in clan log
All checks were successful
Build / build (22) (push) Successful in 40s
Build / build (20) (push) Successful in 1m1s
Build / build (18) (push) Successful in 1m10s
Build / build (22) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m2s
Build / build (18) (pull_request) Successful in 1m4s
All checks were successful
Build / build (22) (push) Successful in 40s
Build / build (20) (push) Successful in 1m1s
Build / build (18) (push) Successful in 1m10s
Build / build (22) (pull_request) Successful in 43s
Build / build (20) (pull_request) Successful in 1m2s
Build / build (18) (pull_request) Successful in 1m4s
This commit is contained in:
parent
02ce0f57a6
commit
00d4cc2fd2
@ -18,6 +18,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
|
||||
StandingsUpdates: [],
|
||||
ClassChanges: []
|
||||
};
|
||||
guild.TechChanges?.forEach(entry => {
|
||||
log.TechChanges.push({
|
||||
dateTime: toMongoDate(entry.dateTime),
|
||||
entryType: entry.entryType,
|
||||
details: entry.details
|
||||
});
|
||||
});
|
||||
guild.ClassChanges?.forEach(entry => {
|
||||
log.ClassChanges.push({
|
||||
dateTime: toMongoDate(entry.dateTime),
|
||||
|
@ -13,8 +13,9 @@ import {
|
||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
import { config } from "@/src/services/configService";
|
||||
import { ITechProjectDatabase } from "@/src/types/guildTypes";
|
||||
import { ITechProjectClient, ITechProjectDatabase } from "@/src/types/guildTypes";
|
||||
import { TGuildDatabaseDocument } from "@/src/models/guildModel";
|
||||
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
|
||||
|
||||
export const guildTechController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
@ -23,9 +24,29 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
||||
const data = JSON.parse(String(req.body)) as TGuildTechRequest;
|
||||
const action = data.Action.split(",")[0];
|
||||
if (action == "Sync") {
|
||||
res.json({
|
||||
TechProjects: guild.toJSON().TechProjects
|
||||
});
|
||||
let needSave = false;
|
||||
const techProjects: ITechProjectClient[] = [];
|
||||
if (guild.TechProjects) {
|
||||
for (const project of guild.TechProjects) {
|
||||
const techProject: ITechProjectClient = {
|
||||
ItemType: project.ItemType,
|
||||
ReqCredits: project.ReqCredits,
|
||||
ReqItems: project.ReqItems,
|
||||
State: project.State
|
||||
};
|
||||
if (project.CompletionDate) {
|
||||
techProject.CompletionDate = toMongoDate(project.CompletionDate);
|
||||
if (Date.now() >= project.CompletionDate.getTime()) {
|
||||
needSave ||= setTechLogState(guild, project.ItemType, 4, project.CompletionDate);
|
||||
}
|
||||
}
|
||||
techProjects.push(techProject);
|
||||
}
|
||||
}
|
||||
if (needSave) {
|
||||
await guild.save();
|
||||
}
|
||||
res.json({ TechProjects: techProjects });
|
||||
} else if (action == "Start") {
|
||||
const recipe = ExportDojoRecipes.research[data.RecipeType!];
|
||||
guild.TechProjects ??= [];
|
||||
@ -42,6 +63,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
||||
State: 0
|
||||
}) - 1
|
||||
];
|
||||
setTechLogState(guild, techProject.ItemType, 5);
|
||||
if (config.noDojoResearchCosts) {
|
||||
processFundedProject(guild, techProject, recipe);
|
||||
}
|
||||
@ -159,10 +181,35 @@ const processFundedProject = (
|
||||
recipe: IDojoResearch
|
||||
): void => {
|
||||
techProject.State = 1;
|
||||
techProject.CompletionDate = new Date(new Date().getTime() + (config.noDojoResearchTime ? 0 : recipe.time) * 1000);
|
||||
techProject.CompletionDate = new Date(Date.now() + (config.noDojoResearchTime ? 0 : recipe.time) * 1000);
|
||||
if (recipe.guildXpValue) {
|
||||
guild.XP += recipe.guildXpValue;
|
||||
}
|
||||
setTechLogState(guild, techProject.ItemType, config.noDojoResearchTime ? 4 : 3, techProject.CompletionDate);
|
||||
};
|
||||
|
||||
const setTechLogState = (
|
||||
guild: TGuildDatabaseDocument,
|
||||
type: string,
|
||||
state: number,
|
||||
dateTime: Date | undefined = undefined
|
||||
): boolean => {
|
||||
guild.TechChanges ??= [];
|
||||
const entry = guild.TechChanges.find(x => x.details == type);
|
||||
if (entry) {
|
||||
if (entry.entryType == state) {
|
||||
return false;
|
||||
}
|
||||
entry.dateTime = dateTime ?? new Date();
|
||||
entry.entryType = state;
|
||||
} else {
|
||||
guild.TechChanges.push({
|
||||
dateTime: dateTime ?? new Date(),
|
||||
entryType: state,
|
||||
details: type
|
||||
});
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
type TGuildTechRequest =
|
||||
|
@ -2,15 +2,14 @@ import {
|
||||
IGuildDatabase,
|
||||
IDojoComponentDatabase,
|
||||
ITechProjectDatabase,
|
||||
ITechProjectClient,
|
||||
IDojoDecoDatabase,
|
||||
ILongMOTD,
|
||||
IGuildMemberDatabase,
|
||||
IGuildLogClassChange
|
||||
IGuildLogClassChange,
|
||||
IGuildLogTechChange
|
||||
} from "@/src/types/guildTypes";
|
||||
import { Document, Model, model, Schema, Types } from "mongoose";
|
||||
import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
|
||||
import { toMongoDate } from "../helpers/inventoryHelpers";
|
||||
|
||||
const dojoDecoSchema = new Schema<IDojoDecoDatabase>({
|
||||
Type: String,
|
||||
@ -51,17 +50,6 @@ const techProjectSchema = new Schema<ITechProjectDatabase>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
techProjectSchema.set("toJSON", {
|
||||
virtuals: true,
|
||||
transform(_doc, obj) {
|
||||
const db = obj as ITechProjectDatabase;
|
||||
const client = obj as ITechProjectClient;
|
||||
if (db.CompletionDate) {
|
||||
client.CompletionDate = toMongoDate(db.CompletionDate);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const longMOTDSchema = new Schema<ILongMOTD>(
|
||||
{
|
||||
message: String,
|
||||
@ -70,6 +58,15 @@ const longMOTDSchema = new Schema<ILongMOTD>(
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
|
||||
{
|
||||
dateTime: Date,
|
||||
entryType: Number,
|
||||
details: String
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
|
||||
{
|
||||
dateTime: Date,
|
||||
@ -100,6 +97,7 @@ const guildSchema = new Schema<IGuildDatabase>(
|
||||
CeremonyContributors: { type: [Types.ObjectId], default: undefined },
|
||||
CeremonyResetDate: Date,
|
||||
CeremonyEndo: Number,
|
||||
TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
|
||||
ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
|
||||
},
|
||||
{ id: false }
|
||||
|
@ -47,6 +47,7 @@ export interface IGuildDatabase {
|
||||
CeremonyContributors?: Types.ObjectId[];
|
||||
CeremonyResetDate?: Date;
|
||||
|
||||
TechChanges?: IGuildLogTechChange[];
|
||||
ClassChanges?: IGuildLogClassChange[];
|
||||
}
|
||||
|
||||
@ -163,6 +164,12 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
|
||||
CompletionDate?: Date;
|
||||
}
|
||||
|
||||
export interface IGuildLogTechChange {
|
||||
dateTime: Date;
|
||||
entryType: number;
|
||||
details: string;
|
||||
}
|
||||
|
||||
export interface IGuildLogClassChange {
|
||||
dateTime: Date;
|
||||
entryType: number;
|
||||
|
Loading…
x
Reference in New Issue
Block a user