chore: turn guild DojoComponents into a DocumentArray
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (18) (push) Successful in 46s
				
			
		
			
				
	
				Build / build (22) (push) Successful in 52s
				
			
		
			
				
	
				Build / build (20) (push) Successful in 56s
				
			
		
			
				
	
				Build / build (18) (pull_request) Successful in 54s
				
			
		
			
				
	
				Build / build (20) (pull_request) Successful in 55s
				
			
		
			
				
	
				Build / build (22) (pull_request) Successful in 58s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (18) (push) Successful in 46s
				
			Build / build (22) (push) Successful in 52s
				
			Build / build (20) (push) Successful in 56s
				
			Build / build (18) (pull_request) Successful in 54s
				
			Build / build (20) (pull_request) Successful in 55s
				
			Build / build (22) (pull_request) Successful in 58s
				
			and use .id for setDojoComponentMessage
This commit is contained in:
		
							parent
							
								
									d7ec259e2d
								
							
						
					
					
						commit
						dc8a9a21d9
					
				@ -9,7 +9,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the root.
 | 
					    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the root.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const idToNode: Record<string, INode> = {};
 | 
					    const idToNode: Record<string, INode> = {};
 | 
				
			||||||
    guild.DojoComponents!.forEach(x => {
 | 
					    guild.DojoComponents.forEach(x => {
 | 
				
			||||||
        idToNode[x._id.toString()] = {
 | 
					        idToNode[x._id.toString()] = {
 | 
				
			||||||
            component: x,
 | 
					            component: x,
 | 
				
			||||||
            parent: undefined,
 | 
					            parent: undefined,
 | 
				
			||||||
@ -18,7 +18,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let oldRoot: INode | undefined;
 | 
					    let oldRoot: INode | undefined;
 | 
				
			||||||
    guild.DojoComponents!.forEach(x => {
 | 
					    guild.DojoComponents.forEach(x => {
 | 
				
			||||||
        const node = idToNode[x._id.toString()];
 | 
					        const node = idToNode[x._id.toString()];
 | 
				
			||||||
        if (x.pi) {
 | 
					        if (x.pi) {
 | 
				
			||||||
            idToNode[x.pi.toString()].children.push(node);
 | 
					            idToNode[x.pi.toString()].children.push(node);
 | 
				
			||||||
@ -47,7 +47,7 @@ export const changeDojoRootController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        );
 | 
					        );
 | 
				
			||||||
        top.children.forEach(x => stack.push(x));
 | 
					        top.children.forEach(x => stack.push(x));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    guild.DojoComponents!.forEach(x => {
 | 
					    guild.DojoComponents.forEach(x => {
 | 
				
			||||||
        x._id = idMap[x._id.toString()];
 | 
					        x._id = idMap[x._id.toString()];
 | 
				
			||||||
        if (x.pi) {
 | 
					        if (x.pi) {
 | 
				
			||||||
            x.pi = idMap[x.pi.toString()];
 | 
					            x.pi = idMap[x.pi.toString()];
 | 
				
			||||||
 | 
				
			|||||||
@ -13,15 +13,15 @@ export const getGuildDojoController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Populate dojo info if not present
 | 
					    // Populate dojo info if not present
 | 
				
			||||||
    if (!guild.DojoComponents || guild.DojoComponents.length == 0) {
 | 
					    if (guild.DojoComponents.length == 0) {
 | 
				
			||||||
        guild.DojoComponents = [
 | 
					        guild.DojoComponents.push([
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                _id: new Types.ObjectId(),
 | 
					                _id: new Types.ObjectId(),
 | 
				
			||||||
                pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
 | 
					                pf: "/Lotus/Levels/ClanDojo/DojoHall.level",
 | 
				
			||||||
                ppf: "",
 | 
					                ppf: "",
 | 
				
			||||||
                CompletionTime: new Date(Date.now())
 | 
					                CompletionTime: new Date(Date.now())
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        ];
 | 
					        ]);
 | 
				
			||||||
        await guild.save();
 | 
					        await guild.save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,8 +5,8 @@ import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
				
			|||||||
export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
 | 
					export const queueDojoComponentDestructionController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const guild = await getGuildForRequest(req);
 | 
					    const guild = await getGuildForRequest(req);
 | 
				
			||||||
    const componentId = req.query.componentId as string;
 | 
					    const componentId = req.query.componentId as string;
 | 
				
			||||||
    const component = guild.DojoComponents!.splice(
 | 
					    const component = guild.DojoComponents.splice(
 | 
				
			||||||
        guild.DojoComponents!.findIndex(x => x._id.toString() === componentId),
 | 
					        guild.DojoComponents.findIndex(x => x._id.toString() === componentId),
 | 
				
			||||||
        1
 | 
					        1
 | 
				
			||||||
    )[0];
 | 
					    )[0];
 | 
				
			||||||
    const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
 | 
					    const room = Object.values(ExportDojoRecipes.rooms).find(x => x.resultType == component.pf);
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@ import { getDojoClient, getGuildForRequest } from "@/src/services/guildService";
 | 
				
			|||||||
export const setDojoComponentMessageController: RequestHandler = async (req, res) => {
 | 
					export const setDojoComponentMessageController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const guild = await getGuildForRequest(req);
 | 
					    const guild = await getGuildForRequest(req);
 | 
				
			||||||
    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the message.
 | 
					    // At this point, we know that a member of the guild is making this request. Assuming they are allowed to change the message.
 | 
				
			||||||
    const component = guild.DojoComponents!.find(x => x._id.equals(req.query.componentId as string))!;
 | 
					    const component = guild.DojoComponents.id(req.query.componentId as string)!;
 | 
				
			||||||
    const payload = JSON.parse(String(req.body)) as SetDojoComponentMessageRequest;
 | 
					    const payload = JSON.parse(String(req.body)) as SetDojoComponentMessageRequest;
 | 
				
			||||||
    if ("Name" in payload) {
 | 
					    if ("Name" in payload) {
 | 
				
			||||||
        component.Name = payload.Name;
 | 
					        component.Name = payload.Name;
 | 
				
			||||||
 | 
				
			|||||||
@ -20,7 +20,7 @@ export const startDojoRecipeController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        guild.DojoEnergy += room.energy;
 | 
					        guild.DojoEnergy += room.energy;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    guild.DojoComponents!.push({
 | 
					    guild.DojoComponents.push({
 | 
				
			||||||
        _id: new Types.ObjectId(),
 | 
					        _id: new Types.ObjectId(),
 | 
				
			||||||
        pf: request.PlacedComponent.pf,
 | 
					        pf: request.PlacedComponent.pf,
 | 
				
			||||||
        ppf: request.PlacedComponent.ppf,
 | 
					        ppf: request.PlacedComponent.ppf,
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,7 @@ import {
 | 
				
			|||||||
    ITechProjectDatabase,
 | 
					    ITechProjectDatabase,
 | 
				
			||||||
    ITechProjectClient
 | 
					    ITechProjectClient
 | 
				
			||||||
} from "@/src/types/guildTypes";
 | 
					} from "@/src/types/guildTypes";
 | 
				
			||||||
import { model, Schema } from "mongoose";
 | 
					import { Document, Model, model, Schema, Types } from "mongoose";
 | 
				
			||||||
import { typeCountSchema } from "./inventoryModels/inventoryModel";
 | 
					import { typeCountSchema } from "./inventoryModels/inventoryModel";
 | 
				
			||||||
import { toMongoDate } from "../helpers/inventoryHelpers";
 | 
					import { toMongoDate } from "../helpers/inventoryHelpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -44,7 +44,7 @@ techProjectSchema.set("toJSON", {
 | 
				
			|||||||
const guildSchema = new Schema<IGuildDatabase>(
 | 
					const guildSchema = new Schema<IGuildDatabase>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Name: { type: String, required: true },
 | 
					        Name: { type: String, required: true },
 | 
				
			||||||
        DojoComponents: [dojoComponentSchema],
 | 
					        DojoComponents: { type: [dojoComponentSchema], default: [] },
 | 
				
			||||||
        DojoCapacity: { type: Number, default: 100 },
 | 
					        DojoCapacity: { type: Number, default: 100 },
 | 
				
			||||||
        DojoEnergy: { type: Number, default: 5 },
 | 
					        DojoEnergy: { type: Number, default: 5 },
 | 
				
			||||||
        TechProjects: { type: [techProjectSchema], default: undefined }
 | 
					        TechProjects: { type: [techProjectSchema], default: undefined }
 | 
				
			||||||
@ -52,4 +52,23 @@ const guildSchema = new Schema<IGuildDatabase>(
 | 
				
			|||||||
    { id: false }
 | 
					    { id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const Guild = model<IGuildDatabase>("Guild", guildSchema);
 | 
					type GuildDocumentProps = {
 | 
				
			||||||
 | 
					    DojoComponents: Types.DocumentArray<IDojoComponentDatabase>;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eslint-disable-next-line @typescript-eslint/ban-types
 | 
				
			||||||
 | 
					type GuildModel = Model<IGuildDatabase, {}, GuildDocumentProps>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const Guild = model<IGuildDatabase, GuildModel>("Guild", guildSchema);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// eslint-disable-next-line @typescript-eslint/ban-types
 | 
				
			||||||
 | 
					export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
 | 
				
			||||||
 | 
					    Omit<
 | 
				
			||||||
 | 
					        IGuildDatabase & {
 | 
				
			||||||
 | 
					            _id: Types.ObjectId;
 | 
				
			||||||
 | 
					        } & {
 | 
				
			||||||
 | 
					            __v: number;
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        keyof GuildDocumentProps
 | 
				
			||||||
 | 
					    > &
 | 
				
			||||||
 | 
					    GuildDocumentProps;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,10 +1,9 @@
 | 
				
			|||||||
import { Request } from "express";
 | 
					import { Request } from "express";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { getInventory } from "@/src/services/inventoryService";
 | 
					import { getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { Guild } from "@/src/models/guildModel";
 | 
					import { Guild, TGuildDatabaseDocument } from "@/src/models/guildModel";
 | 
				
			||||||
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
					import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { IDojoClient, IDojoComponentClient, IGuildDatabase } from "@/src/types/guildTypes";
 | 
					import { IDojoClient, IDojoComponentClient } from "@/src/types/guildTypes";
 | 
				
			||||||
import { Document, Types } from "mongoose";
 | 
					 | 
				
			||||||
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
 | 
					import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
 | 
					export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
 | 
				
			||||||
@ -41,7 +40,7 @@ export const getDojoClient = (guild: TGuildDatabaseDocument, status: number): ID
 | 
				
			|||||||
        DojoRequestStatus: status,
 | 
					        DojoRequestStatus: status,
 | 
				
			||||||
        DojoComponents: []
 | 
					        DojoComponents: []
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    guild.DojoComponents!.forEach(dojoComponent => {
 | 
					    guild.DojoComponents.forEach(dojoComponent => {
 | 
				
			||||||
        const clientComponent: IDojoComponentClient = {
 | 
					        const clientComponent: IDojoComponentClient = {
 | 
				
			||||||
            id: toOid(dojoComponent._id),
 | 
					            id: toOid(dojoComponent._id),
 | 
				
			||||||
            pf: dojoComponent.pf,
 | 
					            pf: dojoComponent.pf,
 | 
				
			||||||
@ -62,12 +61,3 @@ export const getDojoClient = (guild: TGuildDatabaseDocument, status: number): ID
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
    return dojo;
 | 
					    return dojo;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					 | 
				
			||||||
// eslint-disable-next-line @typescript-eslint/ban-types
 | 
					 | 
				
			||||||
export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
 | 
					 | 
				
			||||||
    IGuildDatabase &
 | 
					 | 
				
			||||||
    Required<{
 | 
					 | 
				
			||||||
        _id: Types.ObjectId;
 | 
					 | 
				
			||||||
    }> & {
 | 
					 | 
				
			||||||
        __v: number;
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@ export interface IGuild {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export interface IGuildDatabase extends IGuild {
 | 
					export interface IGuildDatabase extends IGuild {
 | 
				
			||||||
    _id: Types.ObjectId;
 | 
					    _id: Types.ObjectId;
 | 
				
			||||||
    DojoComponents?: IDojoComponentDatabase[];
 | 
					    DojoComponents: IDojoComponentDatabase[];
 | 
				
			||||||
    DojoCapacity: number;
 | 
					    DojoCapacity: number;
 | 
				
			||||||
    DojoEnergy: number;
 | 
					    DojoEnergy: number;
 | 
				
			||||||
    TechProjects?: ITechProjectDatabase[];
 | 
					    TechProjects?: ITechProjectDatabase[];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user