Skip to content

Commit

Permalink
Merge pull request #389 from dfpc-coe/video-lease-pane
Browse files Browse the repository at this point in the history
Video Lease Renewal
  • Loading branch information
ingalls authored Oct 17, 2024
2 parents 783ecd4 + 51b6a88 commit f37ae1e
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 297 deletions.
18 changes: 16 additions & 2 deletions api/routes/video-lease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export default async function router(schema: Schema, config: Config) {
}),
body: Type.Object({
name: Type.Optional(Type.String()),
duration: Type.Optional(Type.Integer({
minimum: 0,
description: 'Duration in Seconds'
})),
}),
res: Type.Object({
lease: VideoLeaseResponse,
Expand All @@ -157,14 +161,24 @@ export default async function router(schema: Schema, config: Config) {
try {
const user = await Auth.as_user(config, req);

if (user.access !== AuthUserAccess.ADMIN && req.body.duration > 60 * 60 * 16) {
throw new Err(400, null, 'Only Administrators can request a lease > 16 hours')
}

let lease;
if (user.access === AuthUserAccess.ADMIN) {
lease = await config.models.VideoLease.commit(req.params.lease, req.body);
lease = await config.models.VideoLease.commit(req.params.lease, {
...req.body,
expiration: moment().add(req.body.duration, 'seconds').toISOString(),
});
} else {
lease = await config.models.VideoLease.from(req.params.lease);

if (lease.username === user.email) {
lease = await config.models.VideoLease.commit(req.params.lease, req.body);
lease = await config.models.VideoLease.commit(req.params.lease, {
...req.body,
expiration: moment().add(req.body.duration, 'seconds').toISOString(),
});
} else {
throw new Err(400, null, 'You can only update a lease you created');
}
Expand Down
132 changes: 66 additions & 66 deletions api/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</template>

<script setup lang='ts'>
import { ref, computed, defineProps, onMounted } from 'vue'
import { ref, computed, onMounted } from 'vue'
import type { ComputedRef } from 'vue';
import type { MissionLog } from '../../../../types.ts';
import {
Expand Down
Loading

0 comments on commit f37ae1e

Please sign in to comment.