Skip to content

Commit

Permalink
Mock a list logs endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 11, 2024
1 parent b17496f commit 448f842
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
44 changes: 44 additions & 0 deletions api/routes/marti-mission-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,57 @@ 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, {
APIAuthCertificate,
} 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<typeof MissionOptions> = 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',
Expand Down
3 changes: 1 addition & 2 deletions api/web/src/components/CloudTAK/Menu/Mission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions api/web/src/components/CloudTAK/Menu/Mission/MissionLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
:back='false'
:border='false'
:loading='loading.logs'
:none='!mission.logs.length && createLog === false'
:none='!logs.length && createLog === false'
>
<div class='rows px-2'>
<div
v-for='log in mission.logs'
v-for='log in logs'
:key='log.id'
class='col-12'
>
Expand Down Expand Up @@ -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}`, {
Expand Down

0 comments on commit 448f842

Please sign in to comment.