Basic purchasing + custom purchasing API #20
@ -1,21 +1,14 @@
 | 
			
		||||
import { Account } from "@/src/models/loginModel";
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import { createShip } from "@/src/services/shipService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
			
		||||
const getShipController: RequestHandler = async (_req, res) => {
 | 
			
		||||
    const accountId = _req.query.accountId;
 | 
			
		||||
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);
 | 
			
		||||
        res.status(500).json({ error: "error finding a corresponding ship" });
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
    res.json(ship);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,46 +1,53 @@
 | 
			
		||||
import { Schema, model } from "mongoose";
 | 
			
		||||
import { IShipDatabase } from "../types/shipTypes";
 | 
			
		||||
import { IShip } from "../types/shipTypes";
 | 
			
		||||
import { Oid } from "../types/commonTypes";
 | 
			
		||||
 | 
			
		||||
const roomSchema = new Schema({
 | 
			
		||||
const roomSchema = new Schema(
 | 
			
		||||
    {
 | 
			
		||||
        Name: String,
 | 
			
		||||
        MaxCapacity: Number
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
roomSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
    },
 | 
			
		||||
    { _id: false }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
const shipSchema = new Schema({
 | 
			
		||||
    Rooms: [roomSchema],
 | 
			
		||||
    Features: [Schema.Types.Mixed],
 | 
			
		||||
    Features: [String],
 | 
			
		||||
    ContentUrlSignature: String
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
shipSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
 | 
			
		||||
        returnedObject.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const apartmentSchema = new Schema({
 | 
			
		||||
    Rooms: [roomSchema],
 | 
			
		||||
    FavouriteLoadouts: [Schema.Types.Mixed]
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
apartmentSchema.set("toJSON", {
 | 
			
		||||
    transform(_document, returnedObject) {
 | 
			
		||||
        delete returnedObject._id;
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
const shipDatabaseSchema = new Schema({
 | 
			
		||||
    ShipOwnerId: String,
 | 
			
		||||
    ShipOwnerId: Schema.Types.ObjectId,
 | 
			
		||||
    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);
 | 
			
		||||
const Ship = model<IShip>("Ship", shipDatabaseSchema);
 | 
			
		||||
 | 
			
		||||
export { Ship };
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
import { Ship } from "@/src/models/shipModel";
 | 
			
		||||
import new_ship from "@/static/fixed_responses/postShip.json";
 | 
			
		||||
import new_ship from "@/static/fixed_responses/ship.json";
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
 | 
			
		||||
const createShip = async (accountOwnerId: Types.ObjectId) => {
 | 
			
		||||
@ -8,9 +8,9 @@ const createShip = async (accountOwnerId: Types.ObjectId) => {
 | 
			
		||||
        await ship.save();
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        if (error instanceof Error) {
 | 
			
		||||
            throw new Error(`error creating inventory" ${error.message}`);
 | 
			
		||||
            throw new Error(`error creating ship" ${error.message}`);
 | 
			
		||||
        }
 | 
			
		||||
        throw new Error("error creating inventory that is not of instance Error");
 | 
			
		||||
        throw new Error("error creating ship that is not of instance Error");
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,19 +1,19 @@
 | 
			
		||||
/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
			
		||||
 | 
			
		||||
import { Types } from "mongoose";
 | 
			
		||||
import { Oid } from "./inventoryTypes";
 | 
			
		||||
import { Oid } from "@/src/types/commonTypes";
 | 
			
		||||
 | 
			
		||||
export type IShipDatabase = IShipResponse;
 | 
			
		||||
 | 
			
		||||
export interface IShipResponse {
 | 
			
		||||
export interface IShip {
 | 
			
		||||
    ShipOwnerId: Types.ObjectId;
 | 
			
		||||
    Ship: IShipClass;
 | 
			
		||||
    Ship: IShipClassResponse;
 | 
			
		||||
    Apartment: IApartmentClass;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IShipClass {
 | 
			
		||||
    Rooms: IRoomsClass[];
 | 
			
		||||
export interface IShipClassResponse extends IShipClassDatabase {
 | 
			
		||||
    ShipId: Oid;
 | 
			
		||||
}
 | 
			
		||||
export interface IShipClassDatabase {
 | 
			
		||||
    Rooms: IRoomsClass[];
 | 
			
		||||
    Features: string[];
 | 
			
		||||
    ContentUrlSignature: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,33 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
    "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": []
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								static/fixed_responses/ship.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								static/fixed_responses/ship.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,32 @@
 | 
			
		||||
{
 | 
			
		||||
  "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": []
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user