返回提交历史
Modified
src/controllers/api/getShipController.ts
+4
-11
Modified
src/models/shipModel.ts
+24
-17
Modified
src/services/shipService.ts
+3
-3
Modified
src/types/shipTypes.ts
+7
-7
Deleted
static/fixed_responses/postShip.json
+0
-33
Added
static/fixed_responses/ship.json
+32
-0
XFEstudio/SpaceNinjaServer
fix some ship things. (#16)
a91f9692
代码差异
6 个文件
+70
-71
@@ -1,20 +1,13 @@
1
import { Account } from "@/src/models/loginModel";
2
1
import { Ship } from "@/src/models/shipModel";
3
import { createShip } from "@/src/services/shipService";
4
2
import { RequestHandler } from "express";
5
3
6
4
// eslint-disable-next-line @typescript-eslint/no-misused-promises
7
const getShipController: RequestHandler = async (_req, res) => {
8
const accountId = _req.query.accountId;
5
const getShipController: RequestHandler = async (req, res) => {
6
const accountId = req.query.accountId;
9
7
const ship = await Ship.findOne({ ShipOwnerId: accountId });
10
8
if (!ship) {
11
const account = await Account.findOne({ _id: accountId });
12
if (account) {
13
await createShip(account._id);
14
const new_ship = await Ship.findOne({ ShipOwnerId: accountId });
15
res.json(new_ship);
16
return;
17
}
9
res.status(500).json({ error: "error finding a corresponding ship" });
10
return;
18
11
}
19
12
res.json(ship);
20
13
};
@@ -1,46 +1,53 @@
1
1
import { Schema, model } from "mongoose";
2
import { IShipDatabase } from "../types/shipTypes";
2
import { IShip } from "../types/shipTypes";
3
3
import { Oid } from "../types/commonTypes";
4
4
5
const roomSchema = new Schema({
6
Name: String,
7
MaxCapacity: Number
5
const roomSchema = new Schema(
6
{
7
Name: String,
8
MaxCapacity: Number
9
},
10
{ _id: false }
11
);
12
13
const shipSchema = new Schema({
14
Rooms: [roomSchema],
15
Features: [String],
16
ContentUrlSignature: String
8
17
});
9
18
10
roomSchema.set("toJSON", {
19
shipSchema.set("toJSON", {
11
20
transform(_document, returnedObject) {
21
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
22
returnedObject.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
12
23
delete returnedObject._id;
13
24
}
14
25
});
15
26
16
const shipSchema = new Schema({
17
Rooms: [roomSchema],
18
Features: [Schema.Types.Mixed],
19
ContentUrlSignature: String
20
});
21
22
27
const apartmentSchema = new Schema({
23
28
Rooms: [roomSchema],
24
29
FavouriteLoadouts: [Schema.Types.Mixed]
25
30
});
26
31
32
apartmentSchema.set("toJSON", {
33
transform(_document, returnedObject) {
34
delete returnedObject._id;
35
}
36
});
37
27
38
const shipDatabaseSchema = new Schema({
28
ShipOwnerId: String,
39
ShipOwnerId: Schema.Types.ObjectId,
29
40
Ship: shipSchema,
30
41
Apartment: apartmentSchema
31
42
});
32
43
33
44
shipDatabaseSchema.set("toJSON", {
34
45
transform(_document, returnedObject) {
35
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
36
returnedObject.Ship.ShipId = { $oid: returnedObject._id.toString() } satisfies Oid;
37
46
delete returnedObject._id;
38
delete returnedObject.Ship._id;
39
delete returnedObject.Apartment._id;
40
47
delete returnedObject.__v;
41
48
}
42
49
});
43
50
44
const Ship = model<IShipDatabase>("Ship", shipDatabaseSchema);
51
const Ship = model<IShip>("Ship", shipDatabaseSchema);
45
52
46
53
export { Ship };
@@ -1,5 +1,5 @@
1
1
import { Ship } from "@/src/models/shipModel";
2
import new_ship from "@/static/fixed_responses/postShip.json";
2
import new_ship from "@/static/fixed_responses/ship.json";
3
3
import { Types } from "mongoose";
4
4
5
5
const createShip = async (accountOwnerId: Types.ObjectId) => {
@@ -8,9 +8,9 @@ const createShip = async (accountOwnerId: Types.ObjectId) => {
8
8
await ship.save();
9
9
} catch (error) {
10
10
if (error instanceof Error) {
11
throw new Error(`error creating inventory" ${error.message}`);
11
throw new Error(`error creating ship" ${error.message}`);
12
12
}
13
throw new Error("error creating inventory that is not of instance Error");
13
throw new Error("error creating ship that is not of instance Error");
14
14
}
15
15
};
16
16
@@ -1,19 +1,19 @@
1
1
/* eslint-disable @typescript-eslint/no-explicit-any */
2
2
3
3
import { Types } from "mongoose";
4
import { Oid } from "./inventoryTypes";
4
import { Oid } from "@/src/types/commonTypes";
5
5
6
export type IShipDatabase = IShipResponse;
7
8
export interface IShipResponse {
6
export interface IShip {
9
7
ShipOwnerId: Types.ObjectId;
10
Ship: IShipClass;
8
Ship: IShipClassResponse;
11
9
Apartment: IApartmentClass;
12
10
}
13
11
14
export interface IShipClass {
15
Rooms: IRoomsClass[];
12
export interface IShipClassResponse extends IShipClassDatabase {
16
13
ShipId: Oid;
14
}
15
export interface IShipClassDatabase {
16
Rooms: IRoomsClass[];
17
17
Features: string[];
18
18
ContentUrlSignature: string;
19
19
}
@@ -1,33 +0,0 @@
1
{
2
"ShipOwnerId": "removed",
3
"Ship": {
4
"Features": [
5
"/Lotus/Types/Items/ShipFeatureItems/EarthNavigationFeatureItem",
6
"/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem",
7
"/Lotus/Types/Items/ShipFeatureItems/SocialMenuFeatureItem",
8
"/Lotus/Types/Items/ShipFeatureItems/ModsFeatureItem",
9
"/Lotus/Types/Items/ShipFeatureItems/FoundryFeatureItem",
10
"/Lotus/Types/Items/ShipFeatureItems/MercuryNavigationFeatureItem"
11
],
12
"ShipId": { "$oid": "removed" },
13
"Rooms": [
14
{ "Name": "AlchemyRoom", "MaxCapacity": 1600 },
15
{ "Name": "BridgeRoom", "MaxCapacity": 1600 },
16
{ "Name": "LisetRoom", "MaxCapacity": 1000 },
17
{ "Name": "OperatorChamberRoom", "MaxCapacity": 1600 },
18
{ "Name": "OutsideRoom", "MaxCapacity": 1600 },
19
{ "Name": "PersonalQuartersRoom", "MaxCapacity": 1600 }
20
],
21
"ContentUrlSignature": "removed"
22
},
23
"Apartment": {
24
"Rooms": [
25
{ "Name": "ElevatorLanding", "MaxCapacity": 1600 },
26
{ "Name": "ApartmentRoomA", "MaxCapacity": 1000 },
27
{ "Name": "ApartmentRoomB", "MaxCapacity": 1600 },
28
{ "Name": "ApartmentRoomC", "MaxCapacity": 1600 },
29
{ "Name": "DuviriHallway", "MaxCapacity": 1600 }
30
],
31
"FavouriteLoadouts": []
32
}
33
}
@@ -0,0 +1,32 @@
1
{
2
"Ship": {
3
"Features": [
4
"/Lotus/Types/Items/ShipFeatureItems/EarthNavigationFeatureItem",
5
"/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem",
6
"/Lotus/Types/Items/ShipFeatureItems/SocialMenuFeatureItem",
7
"/Lotus/Types/Items/ShipFeatureItems/ModsFeatureItem",
8
"/Lotus/Types/Items/ShipFeatureItems/FoundryFeatureItem",
9
"/Lotus/Types/Items/ShipFeatureItems/MercuryNavigationFeatureItem"
10
],
11
"ShipId": { "$oid": "removed" },
12
"Rooms": [
13
{ "Name": "AlchemyRoom", "MaxCapacity": 1600 },
14
{ "Name": "BridgeRoom", "MaxCapacity": 1600 },
15
{ "Name": "LisetRoom", "MaxCapacity": 1000 },
16
{ "Name": "OperatorChamberRoom", "MaxCapacity": 1600 },
17
{ "Name": "OutsideRoom", "MaxCapacity": 1600 },
18
{ "Name": "PersonalQuartersRoom", "MaxCapacity": 1600 }
19
],
20
"ContentUrlSignature": "removed"
21
},
22
"Apartment": {
23
"Rooms": [
24
{ "Name": "ElevatorLanding", "MaxCapacity": 1600 },
25
{ "Name": "ApartmentRoomA", "MaxCapacity": 1000 },
26
{ "Name": "ApartmentRoomB", "MaxCapacity": 1600 },
27
{ "Name": "ApartmentRoomC", "MaxCapacity": 1600 },
28
{ "Name": "DuviriHallway", "MaxCapacity": 1600 }
29
],
30
"FavouriteLoadouts": []
31
}
32
}