Add Ship #13
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -3,3 +3,4 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/.env
 | 
					/.env
 | 
				
			||||||
/static/data/*
 | 
					/static/data/*
 | 
				
			||||||
 | 
					yarn.lock
 | 
				
			||||||
 | 
				
			|||||||
@ -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 { RequestHandler } from "express";
 | 
				
			||||||
import getShip from "@/static/fixed_responses/getShip.json";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getShipController: RequestHandler = (_req, res) => {
 | 
					// eslint-disable-next-line @typescript-eslint/no-misused-promises
 | 
				
			||||||
    res.json(getShip);
 | 
					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);
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 Oh I saw, you added the new ship at createAccount() already. very nice. Then the logic for !getShip should not be needed. You can just remove all that is related to creating a new Ship here, because it should never happen that for an account there is no ship Oh I saw, you added the new ship at createAccount() already. very nice.
Then the logic for !getShip should not be needed. You can just remove all that is related to creating a new Ship here, because it should never happen that for an account there is no ship 
			
			
		 | 
				|||||||
 | 
					            const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
 | 
				
			||||||
 | 
					            res.json(new_ship);
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    res.json(ship);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { getShipController };
 | 
					export { getShipController };
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,7 @@ import { createAccount, isCorrectPassword } from "@/src/services/loginService";
 | 
				
			|||||||
import { ILoginResponse } from "@/src/types/loginTypes";
 | 
					import { ILoginResponse } from "@/src/types/loginTypes";
 | 
				
			||||||
import { DTLS, groups, HUB, IRC, Nonce, NRS, platformCDNs } from "@/static/fixed_responses/login_static";
 | 
					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) => {
 | 
					const loginController: RequestHandler = async (request, response) => {
 | 
				
			||||||
    // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
 | 
					    // 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
 | 
					    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 { Schema, model } from "mongoose";
 | 
				
			||||||
import { IInventoryDatabase, IInventoryResponse, ISuitDatabase, ISuitDocument, Oid } from "../types/inventoryTypes";
 | 
					import { IInventoryDatabase, ISuitDatabase } from "../types/inventoryTypes";
 | 
				
			||||||
 | 
					import { Oid } from "../types/commonTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const polaritySchema = new Schema({
 | 
					const polaritySchema = new Schema({
 | 
				
			||||||
    Slot: Number,
 | 
					    Slot: Number,
 | 
				
			||||||
@ -65,7 +66,7 @@ const suitSchema = new Schema({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
suitSchema.set("toJSON", {
 | 
					suitSchema.set("toJSON", {
 | 
				
			||||||
    transform(_document, returnedObject: ISuitDocument) {
 | 
					    transform(_document, returnedObject) {
 | 
				
			||||||
        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
 | 
					        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
 | 
				
			||||||
        returnedObject.ItemId = { $oid: returnedObject._id.toString() } satisfies Oid;
 | 
					        returnedObject.ItemId = { $oid: returnedObject._id.toString() } satisfies Oid;
 | 
				
			||||||
        delete returnedObject._id;
 | 
					        delete returnedObject._id;
 | 
				
			||||||
@ -246,7 +247,7 @@ const inventorySchema = new Schema({
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inventorySchema.set("toJSON", {
 | 
					inventorySchema.set("toJSON", {
 | 
				
			||||||
    transform(_document, returnedObject: ISuitDocument) {
 | 
					    transform(_document, returnedObject) {
 | 
				
			||||||
        delete returnedObject._id;
 | 
					        delete returnedObject._id;
 | 
				
			||||||
        delete returnedObject.__v;
 | 
					        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 { Account } from "@/src/models/loginModel";
 | 
				
			||||||
import { createInventory } from "@/src/services/inventoryService";
 | 
					import { createInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IDatabaseAccount } from "@/src/types/loginTypes";
 | 
					import { IDatabaseAccount } from "@/src/types/loginTypes";
 | 
				
			||||||
 | 
					import { createShip } from "./shipService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
 | 
					const isCorrectPassword = (requestPassword: string, databasePassword: string): boolean => {
 | 
				
			||||||
    return requestPassword === databasePassword;
 | 
					    return requestPassword === databasePassword;
 | 
				
			||||||
@ -11,6 +12,7 @@ const createAccount = async (accountData: IDatabaseAccount) => {
 | 
				
			|||||||
    try {
 | 
					    try {
 | 
				
			||||||
        await account.save();
 | 
					        await account.save();
 | 
				
			||||||
        await createInventory(account._id);
 | 
					        await createInventory(account._id);
 | 
				
			||||||
 | 
					        await createShip(account._id);
 | 
				
			||||||
        return account.toJSON();
 | 
					        return account.toJSON();
 | 
				
			||||||
    } catch (error) {
 | 
					    } catch (error) {
 | 
				
			||||||
        if (error instanceof 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}`);
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 error creating Ship! not inventory. error creating Ship! not inventory. 
			
			
		 | 
				|||||||
 | 
					        }
 | 
				
			||||||
 | 
					        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 */
 | 
					/* eslint-disable @typescript-eslint/no-explicit-any */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { Document, Types } from "mongoose";
 | 
					import { Document, Types } from "mongoose";
 | 
				
			||||||
 | 
					import { Oid } from "./commonTypes";
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 Please use non-relative imports everywhere Please use non-relative imports everywhere 
			
			
		 | 
				|||||||
 | 
					
 | 
				
			||||||
export interface IInventoryDatabase extends IInventoryResponse {
 | 
					export interface IInventoryDatabase extends IInventoryResponse {
 | 
				
			||||||
    accountOwnerId: Types.ObjectId;
 | 
					    accountOwnerId: Types.ObjectId;
 | 
				
			||||||
@ -187,10 +188,6 @@ export interface AdultOperatorLoadOut {
 | 
				
			|||||||
    ItemId: Oid;
 | 
					    ItemId: Oid;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface Oid {
 | 
					 | 
				
			||||||
    $oid: string;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export interface Color {
 | 
					export interface Color {
 | 
				
			||||||
    t0?: number;
 | 
					    t0?: number;
 | 
				
			||||||
    t1?: number;
 | 
					    t1?: number;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										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",
 | 
				
			||||||
| 
						
							
	
	
	
	
	
	
	
	 this field can be removed, as we add it here: this field can be removed, as we add it here:
const ship = new Ship({ ...new_ship, ShipOwnerId: accountOwnerId }); 
			
			
		 | 
				|||||||
 | 
					    "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
	
_variableName is only used to disable the eslint warning "unused variables".
Once you use a variable, remove the _