store mission Details to database
This commit is contained in:
parent
89b28b6e25
commit
b5a67d27fa
11 changed files with 256 additions and 90 deletions
147
package-lock.json
generated
147
package-lock.json
generated
|
@ -30,6 +30,7 @@
|
|||
"nodemailer": "^6.10.0",
|
||||
"pg": "^8.13.1",
|
||||
"qrcode": "^1.5.4",
|
||||
"quill-delta-to-html": "^0.12.1",
|
||||
"randomcolor": "^0.6.2",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rss-parser": "^3.13.0",
|
||||
|
@ -1051,15 +1052,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/call-bind": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz",
|
||||
"integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==",
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz",
|
||||
"integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.0",
|
||||
"es-define-property": "^1.0.0",
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2",
|
||||
"get-intrinsic": "^1.2.4",
|
||||
"set-function-length": "^1.2.1"
|
||||
"set-function-length": "^1.2.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
|
@ -1068,6 +1069,19 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/call-bind-apply-helpers": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
||||
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0",
|
||||
"function-bind": "^1.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/camelcase": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
||||
|
@ -1451,6 +1465,20 @@
|
|||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"gopd": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/eastasianwidth": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||
|
@ -1596,12 +1624,10 @@
|
|||
"optional": true
|
||||
},
|
||||
"node_modules/es-define-property": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz",
|
||||
"integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.2.4"
|
||||
},
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
||||
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
|
@ -1614,6 +1640,18 @@
|
|||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/es-object-atoms": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
||||
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es-errors": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz",
|
||||
|
@ -1874,15 +1912,21 @@
|
|||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
|
||||
"integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==",
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"call-bind-apply-helpers": "^1.0.2",
|
||||
"es-define-property": "^1.0.1",
|
||||
"es-errors": "^1.3.0",
|
||||
"es-object-atoms": "^1.1.1",
|
||||
"function-bind": "^1.1.2",
|
||||
"has-proto": "^1.0.1",
|
||||
"has-symbols": "^1.0.3",
|
||||
"hasown": "^2.0.0"
|
||||
"get-proto": "^1.0.1",
|
||||
"gopd": "^1.2.0",
|
||||
"has-symbols": "^1.1.0",
|
||||
"hasown": "^2.0.2",
|
||||
"math-intrinsics": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
|
@ -1891,6 +1935,19 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
||||
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dunder-proto": "^1.0.1",
|
||||
"es-object-atoms": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/github-from-package": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz",
|
||||
|
@ -1916,11 +1973,12 @@
|
|||
}
|
||||
},
|
||||
"node_modules/gopd": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
||||
"integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==",
|
||||
"dependencies": {
|
||||
"get-intrinsic": "^1.1.3"
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
||||
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
|
@ -1973,21 +2031,11 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-proto": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz",
|
||||
"integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-symbols": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
|
||||
"integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==",
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
||||
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
|
@ -2334,6 +2382,13 @@
|
|||
"integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isequal": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
|
||||
"integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
|
||||
"deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.isinteger": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz",
|
||||
|
@ -2523,6 +2578,15 @@
|
|||
"node": ">= 10"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
|
@ -3480,6 +3544,15 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/quill-delta-to-html": {
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/quill-delta-to-html/-/quill-delta-to-html-0.12.1.tgz",
|
||||
"integrity": "sha512-QhpeMk9+5ge3HYbL5A0Ewz3pXCsbemqGvIF/kw5D6D4V68AtcUp7yt9xNUkzOk/0IQz43hKy3IkzBzRhLIE+oA==",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"lodash.isequal": "^4.5.0"
|
||||
}
|
||||
},
|
||||
"node_modules/randomcolor": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/randomcolor/-/randomcolor-0.6.2.tgz",
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
"nodemailer": "^6.10.0",
|
||||
"pg": "^8.13.1",
|
||||
"qrcode": "^1.5.4",
|
||||
"quill-delta-to-html": "^0.12.1",
|
||||
"randomcolor": "^0.6.2",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rss-parser": "^3.13.0",
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
export interface UpdateMissionCommand {
|
||||
id: string;
|
||||
title: string;
|
||||
keyword?: string;
|
||||
commandId?: string | null;
|
||||
secretaryId?: string | null;
|
||||
mission_start?: Date | null;
|
||||
mission_end?: Date | null;
|
||||
keyword: string;
|
||||
location: string;
|
||||
others: string;
|
||||
rescued: number;
|
||||
recovered: number;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface DeleteMissionCommand {
|
||||
|
|
|
@ -30,14 +30,11 @@ export default abstract class MissionCommandHandler {
|
|||
* @param {UpdateMissionCommand} updateMission
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
static async update(updateMission: UpdateMissionCommand): Promise<void> {
|
||||
static async sync(updateMission: UpdateMissionCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.update(mission)
|
||||
.set({
|
||||
title: updateMission.title,
|
||||
keyword: updateMission.keyword,
|
||||
})
|
||||
.set(updateMission)
|
||||
.where("id = :id", { id: updateMission.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
|
|
|
@ -53,27 +53,6 @@ export async function createMission(req: Request, res: Response): Promise<any> {
|
|||
res.status(200).send(missionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description update mission by id
|
||||
* @param req {Request} Express req object
|
||||
* @param res {Response} Express res object
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
export async function updateMissionById(req: Request, res: Response): Promise<any> {
|
||||
const missionId = req.params.id;
|
||||
const title = req.body.code;
|
||||
const keyword = req.body.type || null;
|
||||
|
||||
let updateMission: UpdateMissionCommand = {
|
||||
id: missionId,
|
||||
title,
|
||||
keyword,
|
||||
};
|
||||
await MissionCommandHandler.update(updateMission);
|
||||
|
||||
res.sendStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description delete mission by id
|
||||
* @param req {Request} Express req object
|
||||
|
|
|
@ -40,7 +40,7 @@ export class mission {
|
|||
@Column({ type: "int", default: 0 })
|
||||
recovered: number;
|
||||
|
||||
@Column({ type: "text", default: "" })
|
||||
@Column({ type: "text", default: "[]" })
|
||||
description: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
|
|
|
@ -1,23 +1,55 @@
|
|||
import * as Y from "yjs";
|
||||
import { MissionMap } from "../storage/missionMap";
|
||||
import MissionService from "../service/operation/missionService";
|
||||
import { UpdateMissionCommand } from "../command/operation/mission/missionCommand";
|
||||
import MissionCommandHandler from "../command/operation/mission/missionCommandHandler";
|
||||
|
||||
export default abstract class MissionDocHelper {
|
||||
public static async populateDoc(missionId: string) {
|
||||
// get Data from database
|
||||
const mission = await MissionService.getFullById(missionId);
|
||||
|
||||
const doc = new Y.Doc();
|
||||
doc.getMap("form");
|
||||
doc.getText("editor");
|
||||
|
||||
// const ymap = ydoc.getMap('myMap');
|
||||
// ymap.set('titel', 'Mein Dokument');
|
||||
// ymap.set('inhalt', 'Hier ist der initiale Inhalt');
|
||||
// ymap.set('erstelltAm', new Date().toISOString());
|
||||
|
||||
// const yarray = ydoc.getArray('meineArray');
|
||||
// yarray.push(['Element 1', 'Element 2', 'Element 3']);
|
||||
|
||||
// const ytext = ydoc.getText('meinText');
|
||||
// ytext.insert(0, 'Hier ist ein initialer Text');
|
||||
doc.getMap("form").set("title", mission.title);
|
||||
doc.getMap("form").set("command", mission.commandId ?? "");
|
||||
doc.getMap("form").set("secretary", mission.secretaryId ?? "");
|
||||
doc.getMap("form").set("start", mission.mission_start?.toISOString() ?? "");
|
||||
doc.getMap("form").set("end", mission.mission_end?.toISOString() ?? "");
|
||||
doc.getMap("form").set("mission_short", mission.keyword);
|
||||
doc.getMap("form").set("location", mission.location);
|
||||
doc.getMap("form").set("others", mission.others);
|
||||
doc.getMap("form").set("rescued", mission.rescued.toString());
|
||||
doc.getMap("form").set("recovered", mission.recovered.toString());
|
||||
doc.getText("editor").applyDelta(JSON.parse(mission.description)); //.insert(0, mission.description);
|
||||
for (const vehicle of mission.vehicles) {
|
||||
doc.getMap<Y.Map<number | string>>("vehicle").set(vehicle.vehicleId, new Y.Map<string | number>());
|
||||
for (const key of ["driverId", "leaderId", "mileage_start", "mileage_end"] as (keyof typeof vehicle)[]) {
|
||||
doc
|
||||
.getMap<Y.Map<number | string>>("vehicle")
|
||||
.get(vehicle.vehicleId)
|
||||
.set<string | number>(key, vehicle[key].toString());
|
||||
}
|
||||
}
|
||||
for (const equipment of mission.equipments) {
|
||||
doc.getMap<Y.Map<number | string>>("equipment").set(equipment.equipmentId, new Y.Map<string | number>());
|
||||
for (const key of ["note"] as (keyof typeof equipment)[]) {
|
||||
doc
|
||||
.getMap<Y.Map<number | string>>("equipment")
|
||||
.get(equipment.equipmentId)
|
||||
.set<string | number>(key, equipment[key].toString());
|
||||
}
|
||||
}
|
||||
for (const contact of mission.contacts) {
|
||||
doc.getMap<Y.Map<number | string>>("contact").set(contact.contactId, new Y.Map<string | number>());
|
||||
for (const key of ["firstname", "lastname", "phone", "address", "note"] as (keyof typeof contact)[]) {
|
||||
doc
|
||||
.getMap<Y.Map<number | string>>("contact")
|
||||
.get(contact.contactId)
|
||||
.set<string | number>(key, contact[key].toString());
|
||||
}
|
||||
}
|
||||
for (const force of mission.forces) {
|
||||
doc.getMap<boolean>("presence").set(force.forceId, true);
|
||||
}
|
||||
|
||||
MissionMap.write(missionId, {
|
||||
missionId,
|
||||
|
@ -55,8 +87,60 @@ export default abstract class MissionDocHelper {
|
|||
}
|
||||
|
||||
public static async saveDoc(missionId: string, update: Uint8Array) {
|
||||
const oldMission = MissionMap.read(missionId);
|
||||
const oldVehicles = Array.from(oldMission.doc.getMap("presence").keys());
|
||||
const oldEquipments = Array.from(oldMission.doc.getMap("presence").keys());
|
||||
const oldContact = Array.from(oldMission.doc.getMap("presence").keys());
|
||||
const oldPresence = Array.from(oldMission.doc.getMap("presence").keys());
|
||||
|
||||
MissionMap.updateState(missionId, update);
|
||||
|
||||
const mission = MissionMap.read(missionId);
|
||||
const vehicles = Array.from(mission.doc.getMap("presence").keys());
|
||||
const equipments = Array.from(mission.doc.getMap("presence").keys());
|
||||
const contact = Array.from(mission.doc.getMap("presence").keys());
|
||||
const presence = Array.from(mission.doc.getMap("presence").keys());
|
||||
|
||||
const removedVehicles = oldVehicles.filter((item) => !vehicles.includes(item));
|
||||
const removedEquipments = oldEquipments.filter((item) => !equipments.includes(item));
|
||||
const removedContacts = oldContact.filter((item) => !contact.includes(item));
|
||||
const removedPresence = oldPresence.filter((item) => !presence.includes(item));
|
||||
|
||||
//editor.setContents(mission.doc.getText("editor").toDelta()); //new QuillDeltaToHtmlConverter(mission.doc.getText("editor").toDelta()).convert(),
|
||||
const missionDetails: UpdateMissionCommand = {
|
||||
id: missionId,
|
||||
title: mission.doc.getMap("form").toJSON().title,
|
||||
...(mission.doc.getMap("form").toJSON().command != ""
|
||||
? { commandId: mission.doc.getMap("form").toJSON().command }
|
||||
: { commandId: null }),
|
||||
...(mission.doc.getMap("form").toJSON().secretary != ""
|
||||
? { secretaryId: mission.doc.getMap("form").toJSON().secretary }
|
||||
: { secretaryId: null }),
|
||||
...(mission.doc.getMap("form").get("start") != ""
|
||||
? { mission_start: new Date(mission.doc.getMap("form").get("start") as string) }
|
||||
: { mission_start: null }),
|
||||
...(mission.doc.getMap("form").get("end") != ""
|
||||
? { mission_end: new Date(mission.doc.getMap("form").get("end") as string) }
|
||||
: { mission_end: null }),
|
||||
keyword: mission.doc.getMap("form").toJSON().mission_short,
|
||||
location: mission.doc.getMap("form").toJSON().location,
|
||||
others: mission.doc.getMap("form").toJSON().others,
|
||||
rescued: parseInt(mission.doc.getMap("form").toJSON().rescued),
|
||||
recovered: parseInt(mission.doc.getMap("form").toJSON().recovered),
|
||||
description: JSON.stringify(mission.doc.getText("editor").toDelta()),
|
||||
};
|
||||
const missionVehicles = mission.doc.getMap<Y.Map<string | number>>("vehicle").toJSON();
|
||||
const missionEquipment = mission.doc.getMap<Y.Map<string | number>>("equipment").toJSON();
|
||||
const missionContact = mission.doc.getMap<Y.Map<string | number>>("contact").toJSON();
|
||||
const missionPresence = mission.doc.getMap<Y.Map<string | number>>("presence").toJSON();
|
||||
|
||||
// store Data to database
|
||||
|
||||
// Object.keys(tmp).map(t => ({
|
||||
// id:t,
|
||||
// ...tmp[t]
|
||||
// }))
|
||||
|
||||
await MissionCommandHandler.sync(missionDetails);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ export const mission_table = new Table({
|
|||
{ name: "others", ...getTypeByORM("varchar"), default: getDefaultByORM("string") },
|
||||
{ name: "rescued", ...getTypeByORM("int"), default: getDefaultByORM("number", 0) },
|
||||
{ name: "recovered", ...getTypeByORM("int"), default: getDefaultByORM("number", 0) },
|
||||
{ name: "description", ...getTypeByORM("text"), default: getDefaultByORM("string") },
|
||||
{ name: "description", ...getTypeByORM("text"), default: getDefaultByORM("string", "[]") },
|
||||
{ name: "createdAt", ...getTypeByORM("datetime", false, 6), default: getDefaultByORM("currentTimestamp") },
|
||||
],
|
||||
});
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
deleteMissionById,
|
||||
getAllMissions,
|
||||
getMissionById,
|
||||
updateMissionById,
|
||||
} from "../../../controller/admin/operation/missionController";
|
||||
import PermissionHelper from "../../../helpers/permissionHelper";
|
||||
|
||||
|
@ -26,14 +25,6 @@ router.post(
|
|||
}
|
||||
);
|
||||
|
||||
router.patch(
|
||||
"/:id",
|
||||
PermissionHelper.passCheckMiddleware("update", "operation", "mission"),
|
||||
async (req: Request, res: Response) => {
|
||||
await updateMissionById(req, res);
|
||||
}
|
||||
);
|
||||
|
||||
router.delete(
|
||||
"/:id",
|
||||
PermissionHelper.passCheckMiddleware("delete", "operation", "mission"),
|
||||
|
|
|
@ -23,7 +23,8 @@ export default abstract class MissionService {
|
|||
}
|
||||
|
||||
return await query
|
||||
.orderBy("mission.createdAt")
|
||||
.orderBy("mission.mission_start")
|
||||
.addOrderBy("mission.createdAt")
|
||||
.getManyAndCount()
|
||||
.then((res) => {
|
||||
return res;
|
||||
|
@ -51,4 +52,34 @@ export default abstract class MissionService {
|
|||
throw new DatabaseActionException("SELECT", "mission", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get full mission by id
|
||||
* @param {string} id
|
||||
* @returns {Promise<mission>}
|
||||
*/
|
||||
static async getFullById(id: string): Promise<mission> {
|
||||
return dataSource
|
||||
.getRepository(mission)
|
||||
.createQueryBuilder("mission")
|
||||
.leftJoinAndSelect("mission.command", "command")
|
||||
.leftJoinAndSelect("mission.secretary", "secretary")
|
||||
.leftJoinAndSelect("mission.forces", "forces")
|
||||
.leftJoinAndSelect("forces.force", "force")
|
||||
.leftJoinAndSelect("mission.vehicles", "vehicles")
|
||||
.leftJoinAndSelect("vehicles.driver", "driver")
|
||||
.leftJoinAndSelect("vehicles.leader", "leader")
|
||||
.leftJoinAndSelect("vehicles.vehicle", "vehicle")
|
||||
.leftJoinAndSelect("mission.equipments", "equipments")
|
||||
.leftJoinAndSelect("equipments.equipment", "equipment")
|
||||
.leftJoinAndSelect("mission.contacts", "contacts")
|
||||
.where("mission.id = :id", { id: id })
|
||||
.getOneOrFail()
|
||||
.then((res) => {
|
||||
return res;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new DatabaseActionException("SELECT", "mission", err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ export default (io: Server, socket: Socket) => {
|
|||
answer: { status: "success" },
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return { type: "status-join:join", answer: { status: "failed", msg: error.message } };
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue