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
15 changes: 13 additions & 2 deletions packages/api/docs/src/paths/archive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,27 @@ archives:
- bearerHttpAuthentication: []
tags:
- archives
- unimplemented
operationId: post-archives
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- name
properties:
name:
type: string
type:
$ref: "../models/archive_type.yaml#/archiveType"
description: >-
Defaults to `person` if omitted.
type: string
default: person
enum:
- person
- group
- organization
responses:
"200":
description: The created archive
Expand All @@ -97,6 +106,8 @@ archives:
$ref: "../models/archive.yaml#/archive"
"400":
$ref: "../errors.yaml#/400"
"401":
$ref: "../errors.yaml#/401"
"500":
$ref: "../errors.yaml#/500"
archives/{id}:
Expand Down
25 changes: 25 additions & 0 deletions packages/api/src/archive/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,44 @@ import {
verifyAdminAuthentication,
extractUserIsAdminFromAuthToken,
extractUserEmailFromAuthToken,
extractIp,
} from "../../middleware/index.js";
import {
validateArchiveIdFromParams,
validateBodyFromAuthentication,
validateSearchQuery,
validatePatchArchiveBody,
validateGetSharedFoldersQuery,
validateCreateArchiveRequest,
} from "../validators.js";
import { archiveService } from "../service/index.js";
import { validatePaginationParameters } from "../../validators/shared.js";
import { ArchiveType } from "../models.js";

export const archiveController = Router();

archiveController.post(
"/",
verifyUserAuthentication,
extractIp,
async (req: Request, res: Response, next: NextFunction) => {
try {
validateCreateArchiveRequest(req.body);
const archive = await archiveService.createArchive({
emailFromAuthToken: req.body.emailFromAuthToken,
userSubjectFromAuthToken: req.body.userSubjectFromAuthToken,
ip: req.body.ip,
userAgent: req.get("User-Agent"),
name: req.body.name,
type: req.body.type ?? ArchiveType.Person,
});
res.status(HTTP_STATUS.SUCCESSFUL.OK).json({ data: archive });
} catch (err) {
next(err);
}
},
);

archiveController.get(
"/",
extractUserIsAdminFromAuthToken,
Expand Down
Loading
Loading