forked from OpenWF/SpaceNinjaServer
		
	Add Ship (#13)
This commit is contained in:
		
							parent
							
								
									c6687e3b4d
								
							
						
					
					
						commit
						6520284cba
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -3,3 +3,4 @@
 | 
			
		||||
 | 
			
		||||
/.env
 | 
			
		||||
/static/data/*
 | 
			
		||||
yarn.lock
 | 
			
		||||
 | 
			
		||||
@ -5,5 +5,7 @@
 | 
			
		||||
  "version": "33.0.14",
 | 
			
		||||
  "worldSeed": "GWvLyHiw7/Qr/60056xmAmDrn0Y9et2S3BYlLSkLDNBMtumSr3KxWV8He5Jz72yYq3tsY+cd53QeTf+bb54+llGTbYiQF+64BtiLWMVhWP1IUaP4SxWHXojlpQC13op/udHI1whc+8zrxEzzZmv/QlpvigAAbjBDtwu97Df0vgn+YrOKi4G3OhgIkTRocAAzD1P/BGbT8gaKE01H8rXl3+Gq6jCA1O1v800SL6DwKOgMsXVvWp7g2n/tPxJe/j9bmu4XFG0bSa5y5hikLKxvntA/5ut+iogv4MyMBe+TydVxjPqNbkKnby5l4KAL+3inpuPraeg4jcNMt0AwKG8NIQ==",
 | 
			
		||||
  "skipStoryModeChoice": true,
 | 
			
		||||
  "skipTutorial": true
 | 
			
		||||
  "skipTutorial": true,
 | 
			
		||||
  "testMission": true,
 | 
			
		||||
  "testQuestKey": true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,22 @@
 | 
			
		||||
import { Account } from "@/src/models/loginModel";
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import { createShip } from "@/src/services/shipService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import getShip from "@/static/fixed_responses/getShip.json";
 | 
			
		||||
 | 
			
		||||
const getShipController: RequestHandler = (_req, res) => {
 | 
			
		||||
    res.json(getShip);
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
const getShipController: RequestHandler = async (_req, res) => {
 | 
			
		||||
    const accountId = _req.query.accountId;
 | 
			
		||||
    const ship = await Ship.findOne({ ShipOwnerId: accountId });
 | 
			
		||||
    if (!ship) {
 | 
			
		||||
        const account = await Account.findOne({ _id: accountId });
 | 
			
		||||
        if (account) {
 | 
			
		||||
            await createShip(account._id);
 | 
			
		||||
            const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
 | 
			
		||||
            res.json(new_ship);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    res.json(ship);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export { getShipController };
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,9 @@
 | 
			
		||||
import { toInventoryResponse } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { Inventory } from "@/src/models/inventoryModel";
 | 
			
		||||
import { Request, RequestHandler, Response } from "express";
 | 
			
		||||
import config from "@/config.json";
 | 
			
		||||
import testMissions from "@/static/fixed_responses/testMissions.json";
 | 
			
		||||
import testQuestKeys from "@/static/fixed_responses/testQuestKeys.json";
 | 
			
		||||
 | 
			
		||||
const inventoryController: RequestHandler = async (request: Request, response: Response) => {
 | 
			
		||||
    const accountId = request.query.accountId;
 | 
			
		||||
@ -23,6 +26,9 @@ const inventoryController: RequestHandler = async (request: Request, response: R
 | 
			
		||||
 | 
			
		||||
    const inventoreResponse = toInventoryResponse(inventoryJSON);
 | 
			
		||||
 | 
			
		||||
    if (config.testMission) inventoreResponse.Missions = testMissions;
 | 
			
		||||
    if (config.testQuestKey) inventoreResponse.QuestKeys = testQuestKeys;
 | 
			
		||||
 | 
			
		||||
    response.json(inventoreResponse);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -9,6 +9,7 @@ import { createAccount, isCorrectPassword } from "@/src/services/loginService";
 | 
			
		||||
import { ILoginResponse } from "@/src/types/loginTypes";
 | 
			
		||||
import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static";
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
const loginController: RequestHandler = async (request, response) => {
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
 | 
			
		||||
    const body = JSON.parse(request.body); // parse octet stream of json data to json object
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,6 @@
 | 
			
		||||
import { Document, Schema, model } from "mongoose";
 | 
			
		||||
import { IInventoryDatabase, IInventoryResponse, ISuitDatabase, ISuitDocument, Oid } from "../types/inventoryTypes";
 | 
			
		||||
import { Schema, model } from "mongoose";
 | 
			
		||||
import { IInventoryDatabase, ISuitDatabase } from "../types/inventoryTypes";
 | 
			
		||||
import { Oid } from "../types/commonTypes";
 | 
			
		||||
 | 
			
		||||
const polaritySchema = new Schema({
 | 
			
		||||
    Slot: Number,
 | 
			
		||||
@ -65,7 +66,7 @@ const suitSchema = new Schema({
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
suitSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject: ISuitDocument) {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
 | 
			
		||||
        returnedObject.ItemId = { $oid: returnedObject._id.toString() } satisfies Oid;
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
@ -246,7 +247,7 @@ const inventorySchema = new Schema({
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
inventorySchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject: ISuitDocument) {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
        delete returnedObject.__v;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										46
									
								
								src/models/shipModel.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/models/shipModel.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
			
		||||
import { Schema, model } from "mongoose";
 | 
			
		||||
import { IShipDatabase } from "../types/shipTypes";
 | 
			
		||||
import { Oid } from "../types/commonTypes";
 | 
			
		||||
 | 
			
		||||
const roomSchema = new Schema({
 | 
			
		||||
    Name: String,
 | 
			
		||||
    MaxCapacity: Number
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
roomSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const shipSchema = new Schema({
 | 
			
		||||
    Rooms: [roomSchema],
 | 
			
		||||
    Features: [Schema.Types.Mixed],
 | 
			
		||||
    ContentUrlSignature: String
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const apartmentSchema = new Schema({
 | 
			
		||||
    Rooms: [roomSchema],
 | 
			
		||||
    FavouriteLoadouts: [Schema.Types.Mixed]
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const shipDatabaseSchema = new Schema({
 | 
			
		||||
    ShipOwnerId: String,
 | 
			
		||||
    Ship: shipSchema,
 | 
			
		||||
    Apartment: apartmentSchema
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
shipDatabaseSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
 | 
			
		||||
        returnedObject.Ship.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
        delete returnedObject.Ship._id;
 | 
			
		||||
        delete returnedObject.Apartment._id;
 | 
			
		||||
        delete returnedObject.__v;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const Ship = model<IShipDatabase>("Ship", shipDatabaseSchema);
 | 
			
		||||
 | 
			
		||||
export { Ship };
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
import { Account } from "@/src/models/loginModel";
 | 
			
		||||
import { createInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { IDatabaseAccount } from "@/src/types/loginTypes";
 | 
			
		||||
import { createShip } from "./shipService";
 | 
			
		||||
 | 
			
		||||
const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
 | 
			
		||||
    return requestPassword === databasePassword;
 | 
			
		||||
@ -11,6 +12,7 @@ const createAccount = async (accountData: IDatabaseAccount) => {
 | 
			
		||||
    try {
 | 
			
		||||
        await account.save();
 | 
			
		||||
        await createInventory(account._id);
 | 
			
		||||
        await createShip(account._id);
 | 
			
		||||
        return account.toJSON();
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        if (error instanceof Error) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								src/services/shipService.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/services/shipService.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import new_ship from "@/static/fixed_responses/postShip.json";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
 | 
			
		||||
const createShip = async (accountOwnerId: Types.ObjectId) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const ship = new Ship({ ...new_ship, ShipOwnerId: accountOwnerId });
 | 
			
		||||
        await ship.save();
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        if (error instanceof Error) {
 | 
			
		||||
            throw new Error(`error creating inventory" ${error.message}`);
 | 
			
		||||
        }
 | 
			
		||||
        throw new Error("error creating inventory that is not of instance Error");
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export { createShip };
 | 
			
		||||
							
								
								
									
										3
									
								
								src/types/commonTypes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/types/commonTypes.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
export interface Oid {
 | 
			
		||||
    $oid: string;
 | 
			
		||||
}
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
			
		||||
 | 
			
		||||
import { Document, Types } from "mongoose";
 | 
			
		||||
import { Oid } from "./commonTypes";
 | 
			
		||||
 | 
			
		||||
export interface IInventoryDatabase extends IInventoryResponse {
 | 
			
		||||
    accountOwnerId: Types.ObjectId;
 | 
			
		||||
@ -187,10 +188,6 @@ export interface AdultOperatorLoadOut {
 | 
			
		||||
    ItemId: Oid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface Oid {
 | 
			
		||||
    $oid: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface Color {
 | 
			
		||||
    t0?: number;
 | 
			
		||||
    t1?: number;
 | 
			
		||||
@ -995,9 +992,9 @@ export interface PlayerSkills {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface QuestKey {
 | 
			
		||||
    Progress: Progress[];
 | 
			
		||||
    unlock: boolean;
 | 
			
		||||
    Completed: boolean;
 | 
			
		||||
    Progress?: Progress[];
 | 
			
		||||
    unlock?: boolean;
 | 
			
		||||
    Completed?: boolean;
 | 
			
		||||
    ItemType: string;
 | 
			
		||||
    CompletionDate?: Date;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										29
									
								
								src/types/shipTypes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/types/shipTypes.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
			
		||||
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import { Oid } from "./inventoryTypes";
 | 
			
		||||
 | 
			
		||||
export type IShipDatabase = IShipResponse;
 | 
			
		||||
 | 
			
		||||
export interface IShipResponse {
 | 
			
		||||
    ShipOwnerId: Types.ObjectId;
 | 
			
		||||
    Ship: IShipClass;
 | 
			
		||||
    Apartment: IApartmentClass;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IShipClass {
 | 
			
		||||
    Rooms: IRoomsClass[];
 | 
			
		||||
    ShipId: Oid;
 | 
			
		||||
    Features: string[];
 | 
			
		||||
    ContentUrlSignature: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IRoomsClass {
 | 
			
		||||
    Name: string;
 | 
			
		||||
    MaxCapacity: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IApartmentClass {
 | 
			
		||||
    Rooms: IRoomsClass[];
 | 
			
		||||
    FavouriteLoadouts: string[];
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								static/fixed_responses/postShip.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								static/fixed_responses/postShip.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
{
 | 
			
		||||
    "ShipOwnerId": "removed",
 | 
			
		||||
    "Ship": {
 | 
			
		||||
        "Features": [
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/EarthNavigationFeatureItem",
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem",
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/SocialMenuFeatureItem",
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/ModsFeatureItem",
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/FoundryFeatureItem",
 | 
			
		||||
            "/Lotus/Types/Items/ShipFeatureItems/MercuryNavigationFeatureItem"
 | 
			
		||||
        ],
 | 
			
		||||
        "ShipId": { "$oid": "removed" },
 | 
			
		||||
        "Rooms": [
 | 
			
		||||
            { "Name": "AlchemyRoom", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "BridgeRoom", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "LisetRoom", "MaxCapacity": 1000 },
 | 
			
		||||
            { "Name": "OperatorChamberRoom", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "OutsideRoom", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "PersonalQuartersRoom", "MaxCapacity": 1600 }
 | 
			
		||||
        ],
 | 
			
		||||
        "ContentUrlSignature": "removed"
 | 
			
		||||
    },
 | 
			
		||||
    "Apartment": {
 | 
			
		||||
        "Rooms": [
 | 
			
		||||
            { "Name": "ElevatorLanding", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "ApartmentRoomA", "MaxCapacity": 1000 },
 | 
			
		||||
            { "Name": "ApartmentRoomB", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "ApartmentRoomC", "MaxCapacity": 1600 },
 | 
			
		||||
            { "Name": "DuviriHallway", "MaxCapacity": 1600 }
 | 
			
		||||
        ],
 | 
			
		||||
        "FavouriteLoadouts": []
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1471
									
								
								static/fixed_responses/testMissions.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1471
									
								
								static/fixed_responses/testMissions.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										11
									
								
								static/fixed_responses/testQuestKeys.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								static/fixed_responses/testQuestKeys.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
[
 | 
			
		||||
    {
 | 
			
		||||
        "ItemType": "/Lotus/Types/Keys/InfestedIntroQuest/InfestedIntroQuestKeyChain"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "ItemType": "/Lotus/Types/Keys/KubrowQuest/KubrowQuestKeyChain"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        "ItemType": "/Lotus/Types/Keys/DuviriQuest/DuviriQuestKeyChain"
 | 
			
		||||
    }
 | 
			
		||||
]
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user