From 448f84238d19594d71d6d4fd6aebf0f9e6912aed Mon Sep 17 00:00:00 2001 From: ingalls Date: Fri, 11 Oct 2024 14:30:47 -0600 Subject: [PATCH] Mock a list logs endpoint --- api/routes/marti-mission-logs.ts | 44 +++++++++++++++++++ .../src/components/CloudTAK/Menu/Mission.vue | 3 +- .../CloudTAK/Menu/Mission/MissionLogs.vue | 21 ++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/api/routes/marti-mission-logs.ts b/api/routes/marti-mission-logs.ts index e72dfddbf..118254f48 100644 --- a/api/routes/marti-mission-logs.ts +++ b/api/routes/marti-mission-logs.ts @@ -3,6 +3,7 @@ import { StandardResponse, GenericMartiResponse } from '../lib/types.js'; import Schema from '@openaddresses/batch-schema'; import Err from '@openaddresses/batch-error'; import { MissionOptions } from '../lib/api/mission.js'; +import { MissionLog } from '../lib/api/mission-log.js'; import Auth from '../lib/auth.js'; import Config from '../lib/config.js'; import TAKAPI, { @@ -10,6 +11,49 @@ import TAKAPI, { } from '../lib/tak-api.js'; export default async function router(schema: Schema, config: Config) { + await schema.post('/marti/missions/:name/log', { + name: 'List Logs', + group: 'MartiMissionLog', + params: Type.Object({ + name: Type.String(), + }), + description: 'Helper API to add a log to a mission', + body: Type.Object({ + content: Type.String() + }), + res: Type.Object({ + total: Type.Integer(), + items: Type.Array(MissionLog) + }) + }, async (req, res) => { + try { + const user = await Auth.as_user(config, req); + + const auth = (await config.models.Profile.from(user.email)).auth; + const creatorUid = user.email; + const api = await TAKAPI.init(new URL(String(config.server.api)), new APIAuthCertificate(auth.cert, auth.key)); + + const opts: Static = req.headers['missionauthorization'] + ? { token: String(req.headers['missionauthorization']) } + : await config.conns.subscription(user.email, req.params.name) + + const mission = await api.Mission.get( + req.params.name, + { + logs: true + }, + opts + ); + + return res.json({ + total: (mission.logs || []).length, + items: mission.logs || [] + }); + } catch (err) { + return Err.respond(err, res); + } + }); + await schema.post('/marti/missions/:name/log', { name: 'Create Log', group: 'MartiMissionLog', diff --git a/api/web/src/components/CloudTAK/Menu/Mission.vue b/api/web/src/components/CloudTAK/Menu/Mission.vue index db189e2d8..ec76b5f95 100644 --- a/api/web/src/components/CloudTAK/Menu/Mission.vue +++ b/api/web/src/components/CloudTAK/Menu/Mission.vue @@ -263,8 +263,7 @@ export default { try { this.loading.mission = true; const url = stdurl(`/api/marti/missions/${this.$route.params.mission}`); - url.searchParams.append('changes', 'false'); - url.searchParams.append('logs', 'true'); + this.mission = await std(url, { headers: { MissionAuthorization: this.token diff --git a/api/web/src/components/CloudTAK/Menu/Mission/MissionLogs.vue b/api/web/src/components/CloudTAK/Menu/Mission/MissionLogs.vue index 52bb9a098..ac349edb0 100644 --- a/api/web/src/components/CloudTAK/Menu/Mission/MissionLogs.vue +++ b/api/web/src/components/CloudTAK/Menu/Mission/MissionLogs.vue @@ -4,11 +4,11 @@ :back='false' :border='false' :loading='loading.logs' - :none='!mission.logs.length && createLog === false' + :none='!logs.length && createLog === false' >
@@ -87,12 +87,29 @@ export default { data: function() { return { createLog: '', + logs: [], loading: { logs: false, }, } }, + mounted: async function() { + await this.fetchLogs() + }, methods: { + fetchLogs: async function(log) { + this.loading.logs = true; + const list = await std(`/api/marti/missions/${this.mission.name}/log`, { + method: 'GET', + headers: { + MissionAuthorization: this.token + }, + }); + + this.logs = list.data; + + this.loading.logs = false; + }, deleteLog: async function(log) { this.loading.logs = true; await std(`/api/marti/missions/${this.mission.name}/log/${log.id}`, {