feat: setDojoComponentMessage #948
@ -1,8 +1,7 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import { Guild } from "@/src/models/guildModel";
 | 
			
		||||
import { IDojoClient, IDojoComponentClient } from "@/src/types/guildTypes";
 | 
			
		||||
import { toOid, toMongoDate } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { getDojoClient } from "@/src/services/guildService";
 | 
			
		||||
 | 
			
		||||
export const getGuildDojoController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const guildId = req.query.guildId as string;
 | 
			
		||||
@ -26,36 +25,5 @@ export const getGuildDojoController: RequestHandler = async (req, res) => {
 | 
			
		||||
        await guild.save();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const dojo: IDojoClient = {
 | 
			
		||||
        _id: { $oid: guildId },
 | 
			
		||||
        Name: guild.Name,
 | 
			
		||||
        Tier: 1,
 | 
			
		||||
        FixedContributions: true,
 | 
			
		||||
        DojoRevision: 1,
 | 
			
		||||
        RevisionTime: Math.round(Date.now() / 1000),
 | 
			
		||||
        Energy: guild.DojoEnergy,
 | 
			
		||||
        Capacity: guild.DojoCapacity,
 | 
			
		||||
        DojoRequestStatus: 0,
 | 
			
		||||
        DojoComponents: []
 | 
			
		||||
    };
 | 
			
		||||
    guild.DojoComponents.forEach(dojoComponent => {
 | 
			
		||||
        const clientComponent: IDojoComponentClient = {
 | 
			
		||||
            id: toOid(dojoComponent._id),
 | 
			
		||||
            pf: dojoComponent.pf,
 | 
			
		||||
            ppf: dojoComponent.ppf,
 | 
			
		||||
            Name: dojoComponent.Name,
 | 
			
		||||
            Message: dojoComponent.Message,
 | 
			
		||||
            DecoCapacity: 600
 | 
			
		||||
        };
 | 
			
		||||
        if (dojoComponent.pi) {
 | 
			
		||||
            clientComponent.pi = toOid(dojoComponent.pi);
 | 
			
		||||
            clientComponent.op = dojoComponent.op!;
 | 
			
		||||
            clientComponent.pp = dojoComponent.pp!;
 | 
			
		||||
        }
 | 
			
		||||
        if (dojoComponent.CompletionTime) {
 | 
			
		||||
            clientComponent.CompletionTime = toMongoDate(dojoComponent.CompletionTime);
 | 
			
		||||
        }
 | 
			
		||||
        dojo.DojoComponents.push(clientComponent);
 | 
			
		||||
    });
 | 
			
		||||
    res.json(dojo);
 | 
			
		||||
    res.json(getDojoClient(guild));
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -3,8 +3,9 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { Guild } from "@/src/models/guildModel";
 | 
			
		||||
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
			
		||||
import { IGuildDatabase } from "@/src/types/guildTypes";
 | 
			
		||||
import { IDojoClient, IDojoComponentClient, IGuildDatabase } from "@/src/types/guildTypes";
 | 
			
		||||
import { Document, Types } from "mongoose";
 | 
			
		||||
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
 | 
			
		||||
export const getGuildForRequest = async (req: Request): Promise<TGuildDatabaseDocument> => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
@ -27,8 +28,43 @@ export const getGuildForRequestEx = async (
 | 
			
		||||
    return guild;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const getDojoClient = (guild: TGuildDatabaseDocument): IDojoClient => {
 | 
			
		||||
    const dojo: IDojoClient = {
 | 
			
		||||
        _id: { $oid: guild._id.toString() },
 | 
			
		||||
        Name: guild.Name,
 | 
			
		||||
        Tier: 1,
 | 
			
		||||
        FixedContributions: true,
 | 
			
		||||
        DojoRevision: 1,
 | 
			
		||||
        RevisionTime: Math.round(Date.now() / 1000),
 | 
			
		||||
        Energy: guild.DojoEnergy,
 | 
			
		||||
        Capacity: guild.DojoCapacity,
 | 
			
		||||
        DojoRequestStatus: 0,
 | 
			
		||||
        DojoComponents: []
 | 
			
		||||
    };
 | 
			
		||||
    guild.DojoComponents!.forEach(dojoComponent => {
 | 
			
		||||
        const clientComponent: IDojoComponentClient = {
 | 
			
		||||
            id: toOid(dojoComponent._id),
 | 
			
		||||
            pf: dojoComponent.pf,
 | 
			
		||||
            ppf: dojoComponent.ppf,
 | 
			
		||||
            Name: dojoComponent.Name,
 | 
			
		||||
            Message: dojoComponent.Message,
 | 
			
		||||
            DecoCapacity: 600
 | 
			
		||||
        };
 | 
			
		||||
        if (dojoComponent.pi) {
 | 
			
		||||
            clientComponent.pi = toOid(dojoComponent.pi);
 | 
			
		||||
            clientComponent.op = dojoComponent.op!;
 | 
			
		||||
            clientComponent.pp = dojoComponent.pp!;
 | 
			
		||||
        }
 | 
			
		||||
        if (dojoComponent.CompletionTime) {
 | 
			
		||||
            clientComponent.CompletionTime = toMongoDate(dojoComponent.CompletionTime);
 | 
			
		||||
        }
 | 
			
		||||
        dojo.DojoComponents.push(clientComponent);
 | 
			
		||||
    });
 | 
			
		||||
    return dojo;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/ban-types
 | 
			
		||||
type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
 | 
			
		||||
export type TGuildDatabaseDocument = Document<unknown, {}, IGuildDatabase> &
 | 
			
		||||
    IGuildDatabase &
 | 
			
		||||
    Required<{
 | 
			
		||||
        _id: Types.ObjectId;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user