XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
UTF-8
import { RequestHandler } from "express";
import { IDojoComponentClient } from "@/src/types/guildTypes";
import { getGuildForRequest } from "@/src/services/guildService";
import { Types } from "mongoose";

interface IStartDojoRecipeRequest {
    PlacedComponent: IDojoComponentClient;
    Revision: number;
}

// eslint-disable-next-line @typescript-eslint/no-misused-promises
export const startDojoRecipeController: RequestHandler = async (req, res) => {
    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 start a build.
    const request = JSON.parse(String(req.body)) as IStartDojoRecipeRequest;
    guild.DojoComponents!.push({
        _id: new Types.ObjectId(),
        pf: request.PlacedComponent.pf,
        ppf: request.PlacedComponent.ppf,
        pi: new Types.ObjectId(request.PlacedComponent.pi!.$id),
        op: request.PlacedComponent.op,
        pp: request.PlacedComponent.pp,
        CompletionTime: new Date(Date.now()) // TOOD: Omit this field & handle the "Collecting Materials" state.
    });
    await guild.save();
    res.json({
        DojoRequestStatus: 0
    });
};