Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api/docs/src/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ paths:
$ref: "./paths/mfa_management.yaml#/mfa-method-with-id"
/accounts:
$ref: "./paths/account.yaml#/account"
/accounts/{id}/storage-adjustment:
$ref: "./paths/account.yaml#/storage-adjustment"
/share-links:
$ref: "./paths/share_link.yaml#/share-link"
/share-links/{shareLinkId}:
Expand Down
57 changes: 57 additions & 0 deletions packages/api/docs/src/paths/account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,60 @@ account:
$ref: "../errors.yaml#/400"
"500":
$ref: "../errors.yaml#/500"
storage-adjustment:
post:
parameters:
- name: id
in: path
required: true
schema:
type: string
summary: Adjust the storage available to an account. Requires admin authentication
operationId: storageAdjustment
security:
- bearerHttpAuthentication: []
tags:
- storage
- admin
requestBody:
content:
application/json:
schema:
type: object
required: [storageAmount]
properties:
storageAmount:
description: The amount of storage to add to the account, expressed as an integer number of GBs (this could be negative)
type: integer
responses:
"200":
description: >
The account's updated storage values
content:
application/json:
schema:
type: object
properties:
data:
type: object
required: [storageTotal, storageUsed]
properties:
newStorageTotal:
description: The total amount of storage now available to the account expressed in GBs
type: number
adjustmentSize:
description: The amount by which the account's storage total was changed
type: number
createdAt:
description: To time at which the storage adjustment occurred
type: string
format: date-time

"400":
$ref: "../errors.yaml#/400"
"401":
$ref: "../errors.yaml#/401"
"404":
$ref: "../errors.yaml#/404"
"500":
$ref: "../errors.yaml#/500"
Empty file.
35 changes: 32 additions & 3 deletions packages/api/src/account/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import { Router } from "express";
import type { Request, Response, NextFunction } from "express";
import { HTTP_STATUS } from "@pdc/http-status-codes";

import { extractIp, verifyUserAuthentication } from "../../middleware";
import {
extractIp,
verifyUserAuthentication,
verifyAdminAuthentication,
} from "../../middleware";
import { isValidationError } from "../../validators/validator_util";

import {
validateUpdateTagsRequest,
validateBodyFromAuthentication,
validateLeaveArchiveParams,
validateLeaveArchiveRequest,
validateCreateStorageAdjustmentRequest,
validateCreateStorageAdjustmentParams,
} from "../validators";
import { accountService } from "../service";
import { accountService, createStorageAdjustment } from "../service";
import type { LeaveArchiveRequest } from "../models";

export const accountController = Router();
Expand Down Expand Up @@ -77,3 +82,27 @@ accountController.delete(
}
},
);
accountController.post(
"/:accountId/storage-adjustments",
verifyAdminAuthentication,
async (req: Request, res: Response, next: NextFunction) => {
try {
validateCreateStorageAdjustmentRequest(req.body);
validateCreateStorageAdjustmentParams(req.params);
const result = await createStorageAdjustment(
req.params.accountId,
req.body,
);

res.status(HTTP_STATUS.SUCCESSFUL.OK).json(result);
} catch (err) {
if (isValidationError(err)) {
res
.status(HTTP_STATUS.CLIENT_ERROR.BAD_REQUEST)
.json({ error: err.message });
return;
}
next(err);
}
},
);
Loading