forked from OpenWF/SpaceNinjaServer
		
	feat: track TechChanges in clan log (#1160)
Re #1152 Reviewed-on: OpenWF/SpaceNinjaServer#1160
This commit is contained in:
		
							parent
							
								
									42799fee7b
								
							
						
					
					
						commit
						073eddc050
					
				@ -18,6 +18,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                StandingsUpdates: [],
 | 
					                StandingsUpdates: [],
 | 
				
			||||||
                ClassChanges: []
 | 
					                ClassChanges: []
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					            guild.TechChanges?.forEach(entry => {
 | 
				
			||||||
 | 
					                log.TechChanges.push({
 | 
				
			||||||
 | 
					                    dateTime: toMongoDate(entry.dateTime),
 | 
				
			||||||
 | 
					                    entryType: entry.entryType,
 | 
				
			||||||
 | 
					                    details: entry.details
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
            guild.ClassChanges?.forEach(entry => {
 | 
					            guild.ClassChanges?.forEach(entry => {
 | 
				
			||||||
                log.ClassChanges.push({
 | 
					                log.ClassChanges.push({
 | 
				
			||||||
                    dateTime: toMongoDate(entry.dateTime),
 | 
					                    dateTime: toMongoDate(entry.dateTime),
 | 
				
			||||||
 | 
				
			|||||||
@ -13,8 +13,9 @@ import {
 | 
				
			|||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
					import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { config } from "@/src/services/configService";
 | 
					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 { TGuildDatabaseDocument } from "@/src/models/guildModel";
 | 
				
			||||||
 | 
					import { toMongoDate } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const guildTechController: RequestHandler = async (req, res) => {
 | 
					export const guildTechController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    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 data = JSON.parse(String(req.body)) as TGuildTechRequest;
 | 
				
			||||||
    const action = data.Action.split(",")[0];
 | 
					    const action = data.Action.split(",")[0];
 | 
				
			||||||
    if (action == "Sync") {
 | 
					    if (action == "Sync") {
 | 
				
			||||||
        res.json({
 | 
					        let needSave = false;
 | 
				
			||||||
            TechProjects: guild.toJSON().TechProjects
 | 
					        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") {
 | 
					    } else if (action == "Start") {
 | 
				
			||||||
        const recipe = ExportDojoRecipes.research[data.RecipeType!];
 | 
					        const recipe = ExportDojoRecipes.research[data.RecipeType!];
 | 
				
			||||||
        guild.TechProjects ??= [];
 | 
					        guild.TechProjects ??= [];
 | 
				
			||||||
@ -42,6 +63,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                        State: 0
 | 
					                        State: 0
 | 
				
			||||||
                    }) - 1
 | 
					                    }) - 1
 | 
				
			||||||
                ];
 | 
					                ];
 | 
				
			||||||
 | 
					            setTechLogState(guild, techProject.ItemType, 5);
 | 
				
			||||||
            if (config.noDojoResearchCosts) {
 | 
					            if (config.noDojoResearchCosts) {
 | 
				
			||||||
                processFundedProject(guild, techProject, recipe);
 | 
					                processFundedProject(guild, techProject, recipe);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -159,10 +181,35 @@ const processFundedProject = (
 | 
				
			|||||||
    recipe: IDojoResearch
 | 
					    recipe: IDojoResearch
 | 
				
			||||||
): void => {
 | 
					): void => {
 | 
				
			||||||
    techProject.State = 1;
 | 
					    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) {
 | 
					    if (recipe.guildXpValue) {
 | 
				
			||||||
        guild.XP += 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 =
 | 
					type TGuildTechRequest =
 | 
				
			||||||
 | 
				
			|||||||
@ -2,15 +2,14 @@ import {
 | 
				
			|||||||
    IGuildDatabase,
 | 
					    IGuildDatabase,
 | 
				
			||||||
    IDojoComponentDatabase,
 | 
					    IDojoComponentDatabase,
 | 
				
			||||||
    ITechProjectDatabase,
 | 
					    ITechProjectDatabase,
 | 
				
			||||||
    ITechProjectClient,
 | 
					 | 
				
			||||||
    IDojoDecoDatabase,
 | 
					    IDojoDecoDatabase,
 | 
				
			||||||
    ILongMOTD,
 | 
					    ILongMOTD,
 | 
				
			||||||
    IGuildMemberDatabase,
 | 
					    IGuildMemberDatabase,
 | 
				
			||||||
    IGuildLogClassChange
 | 
					    IGuildLogClassChange,
 | 
				
			||||||
 | 
					    IGuildLogTechChange
 | 
				
			||||||
} 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";
 | 
				
			||||||
import { toMongoDate } from "../helpers/inventoryHelpers";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const dojoDecoSchema = new Schema<IDojoDecoDatabase>({
 | 
					const dojoDecoSchema = new Schema<IDojoDecoDatabase>({
 | 
				
			||||||
    Type: String,
 | 
					    Type: String,
 | 
				
			||||||
@ -51,17 +50,6 @@ const techProjectSchema = new Schema<ITechProjectDatabase>(
 | 
				
			|||||||
    { _id: false }
 | 
					    { _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>(
 | 
					const longMOTDSchema = new Schema<ILongMOTD>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        message: String,
 | 
					        message: String,
 | 
				
			||||||
@ -70,6 +58,15 @@ const longMOTDSchema = new Schema<ILongMOTD>(
 | 
				
			|||||||
    { _id: false }
 | 
					    { _id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        dateTime: Date,
 | 
				
			||||||
 | 
					        entryType: Number,
 | 
				
			||||||
 | 
					        details: String
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    { _id: false }
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
 | 
					const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        dateTime: Date,
 | 
					        dateTime: Date,
 | 
				
			||||||
@ -100,6 +97,7 @@ const guildSchema = new Schema<IGuildDatabase>(
 | 
				
			|||||||
        CeremonyContributors: { type: [Types.ObjectId], default: undefined },
 | 
					        CeremonyContributors: { type: [Types.ObjectId], default: undefined },
 | 
				
			||||||
        CeremonyResetDate: Date,
 | 
					        CeremonyResetDate: Date,
 | 
				
			||||||
        CeremonyEndo: Number,
 | 
					        CeremonyEndo: Number,
 | 
				
			||||||
 | 
					        TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
 | 
				
			||||||
        ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
 | 
					        ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    { id: false }
 | 
					    { id: false }
 | 
				
			||||||
 | 
				
			|||||||
@ -47,6 +47,7 @@ export interface IGuildDatabase {
 | 
				
			|||||||
    CeremonyContributors?: Types.ObjectId[];
 | 
					    CeremonyContributors?: Types.ObjectId[];
 | 
				
			||||||
    CeremonyResetDate?: Date;
 | 
					    CeremonyResetDate?: Date;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    TechChanges?: IGuildLogTechChange[];
 | 
				
			||||||
    ClassChanges?: IGuildLogClassChange[];
 | 
					    ClassChanges?: IGuildLogClassChange[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -163,6 +164,12 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
 | 
				
			|||||||
    CompletionDate?: Date;
 | 
					    CompletionDate?: Date;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IGuildLogTechChange {
 | 
				
			||||||
 | 
					    dateTime: Date;
 | 
				
			||||||
 | 
					    entryType: number;
 | 
				
			||||||
 | 
					    details: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IGuildLogClassChange {
 | 
					export interface IGuildLogClassChange {
 | 
				
			||||||
    dateTime: Date;
 | 
					    dateTime: Date;
 | 
				
			||||||
    entryType: number;
 | 
					    entryType: number;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user