update
This commit is contained in:
commit
57d1ab01d6
@ -1,23 +1,15 @@
|
|||||||
import { RequestHandler } from "express";
|
import { RequestHandler } from "express";
|
||||||
|
|
||||||
import { Account } from "@/src/models/loginModel";
|
|
||||||
import { Ship } from "@/src/models/shipModel";
|
import { Ship } from "@/src/models/shipModel";
|
||||||
|
|
||||||
import { createShip } from "@/src/services/shipService";
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
const getShipController: RequestHandler = async (req, res) => {
|
const getShipController: RequestHandler = async (req, res) => {
|
||||||
const accountId = req.query.accountId;
|
const accountId = req.query.accountId;
|
||||||
const ship = await Ship.findOne({ ShipOwnerId: accountId });
|
const ship = await Ship.findOne({ ShipOwnerId: accountId });
|
||||||
if (!ship) {
|
if (!ship) {
|
||||||
const account = await Account.findOne({ _id: accountId });
|
res.status(500).json({ error: "error finding a corresponding ship" });
|
||||||
if (account) {
|
|
||||||
await createShip(account._id);
|
|
||||||
const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
|
|
||||||
res.json(new_ship);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
res.json(ship);
|
res.json(ship);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Schema, model } from "mongoose";
|
import { Schema, model } from "mongoose";
|
||||||
import { IInventoryDatabase, ISuitDatabase } from "../types/inventoryTypes";
|
import { IInventoryDatabase, ISuitDatabase } from "../types/inventoryTypes";
|
||||||
import { Oid } from "../types/commonTypes";
|
import { Oid } from "../types/commonTypes";
|
||||||
|
import { generateOid } from "../helpers/general";
|
||||||
|
|
||||||
const polaritySchema = new Schema({
|
const polaritySchema = new Schema({
|
||||||
Slot: Number,
|
Slot: Number,
|
||||||
|
@ -1,46 +1,53 @@
|
|||||||
import { Schema, model } from "mongoose";
|
import { Schema, model } from "mongoose";
|
||||||
import { IShipDatabase } from "../types/shipTypes";
|
import { IShip } from "../types/shipTypes";
|
||||||
import { Oid } from "../types/commonTypes";
|
import { Oid } from "../types/commonTypes";
|
||||||
|
|
||||||
const roomSchema = new Schema({
|
const roomSchema = new Schema(
|
||||||
|
{
|
||||||
Name: String,
|
Name: String,
|
||||||
MaxCapacity: Number
|
MaxCapacity: Number
|
||||||
});
|
},
|
||||||
|
{ _id: false }
|
||||||
roomSchema.set("toJSON", {
|
);
|
||||||
transform(_document, returnedObject) {
|
|
||||||
delete returnedObject._id;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const shipSchema = new Schema({
|
const shipSchema = new Schema({
|
||||||
Rooms: [roomSchema],
|
Rooms: [roomSchema],
|
||||||
Features: [Schema.Types.Mixed],
|
Features: [String],
|
||||||
ContentUrlSignature: 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({
|
const apartmentSchema = new Schema({
|
||||||
Rooms: [roomSchema],
|
Rooms: [roomSchema],
|
||||||
FavouriteLoadouts: [Schema.Types.Mixed]
|
FavouriteLoadouts: [Schema.Types.Mixed]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
apartmentSchema.set("toJSON", {
|
||||||
|
transform(_document, returnedObject) {
|
||||||
|
delete returnedObject._id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const shipDatabaseSchema = new Schema({
|
const shipDatabaseSchema = new Schema({
|
||||||
ShipOwnerId: String,
|
ShipOwnerId: Schema.Types.ObjectId,
|
||||||
Ship: shipSchema,
|
Ship: shipSchema,
|
||||||
Apartment: apartmentSchema
|
Apartment: apartmentSchema
|
||||||
});
|
});
|
||||||
|
|
||||||
shipDatabaseSchema.set("toJSON", {
|
shipDatabaseSchema.set("toJSON", {
|
||||||
transform(_document, returnedObject) {
|
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._id;
|
||||||
delete returnedObject.Ship._id;
|
|
||||||
delete returnedObject.Apartment._id;
|
|
||||||
delete returnedObject.__v;
|
delete returnedObject.__v;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const Ship = model<IShipDatabase>("Ship", shipDatabaseSchema);
|
const Ship = model<IShip>("Ship", shipDatabaseSchema);
|
||||||
|
|
||||||
export { Ship };
|
export { Ship };
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Ship } from "@/src/models/shipModel";
|
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";
|
import { Types } from "mongoose";
|
||||||
|
|
||||||
const createShip = async (accountOwnerId: Types.ObjectId) => {
|
const createShip = async (accountOwnerId: Types.ObjectId) => {
|
||||||
@ -8,9 +8,9 @@ const createShip = async (accountOwnerId: Types.ObjectId) => {
|
|||||||
await ship.save();
|
await ship.save();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof 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 */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { Oid } from "./inventoryTypes";
|
import { Oid } from "@/src/types/commonTypes";
|
||||||
|
|
||||||
export type IShipDatabase = IShipResponse;
|
export interface IShip {
|
||||||
|
|
||||||
export interface IShipResponse {
|
|
||||||
ShipOwnerId: Types.ObjectId;
|
ShipOwnerId: Types.ObjectId;
|
||||||
Ship: IShipClass;
|
Ship: IShipClassResponse;
|
||||||
Apartment: IApartmentClass;
|
Apartment: IApartmentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IShipClass {
|
export interface IShipClassResponse extends IShipClassDatabase {
|
||||||
Rooms: IRoomsClass[];
|
|
||||||
ShipId: Oid;
|
ShipId: Oid;
|
||||||
|
}
|
||||||
|
export interface IShipClassDatabase {
|
||||||
|
Rooms: IRoomsClass[];
|
||||||
Features: string[];
|
Features: string[];
|
||||||
ContentUrlSignature: string;
|
ContentUrlSignature: string;
|
||||||
}
|
}
|
||||||
|
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