AstroCol/src/lib/db/systems.ts

45 lines
1.2 KiB
TypeScript

import { ObjectId } from "mongodb";
import { Systems } from "./mongodb";
import DBSystem from "../../types/db/DBSystem";
export const getAllSystems = async () => {
return await (await Systems()).find({}).toArray() as DBSystem[];
}
export const getSystemById = async (id: ObjectId) => {
return await (await Systems()).findOne({
_id: id
}) as DBSystem;
}
export const createSystem = async (system: DBSystem) => {
const systems = await Systems();
return await systems.insertOne(system);
}
export const updateSystemStructures = async (systemId: ObjectId, structures: Array<{ id: string, level: number }>) => {
const systems = await Systems();
await systems.updateOne({ _id: systemId }, {
$set: {
structures
}
});
}
export const updateSystemResources = async (systemId: ObjectId, resources: Array<any>) => {
const systems = await Systems();
await systems.updateOne({ _id: systemId }, {
$set: {
resources
}
});
}
export const updateSystemShips = async (systemId: ObjectId, ships: Array<any>) => {
const systems = await Systems();
await systems.updateOne({ _id: systemId }, {
$set: {
ships
}
});
}