This commit is contained in:
Master 2023-06-05 13:13:28 +08:00
commit 4d27bdca2b
10 changed files with 4910 additions and 4879 deletions

View File

@ -1,6 +1,4 @@
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
@ -8,15 +6,9 @@ const getShipController: RequestHandler = async (req, res) => {
const accountId = req.query.accountId;
const ship = await Ship.findOne({ ShipOwnerId: accountId });
if (!ship) {
// previously registered account
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);
};

View File

@ -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 };

View File

@ -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) => {

View File

@ -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;
}

View 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": []
}
}