u
This commit is contained in:
@@ -8,6 +8,8 @@ import { clearCachedUser } from '../middleware/auth.js';
|
||||
import { initCompanyVfs } from '../../tools/vfs.js';
|
||||
import { executeCompanyImport } from '../../services/companyImport.js';
|
||||
|
||||
// #region Helpers
|
||||
|
||||
const uploadZip = multer({
|
||||
storage: multer.memoryStorage(),
|
||||
limits: { fileSize: 100 * 1024 * 1024 }, // 100 MB
|
||||
@@ -85,6 +87,8 @@ function companyErrorStatus(error) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* Registers company CRUD routes (requires auth middleware).
|
||||
* @param {import('express').Application} app - Express app
|
||||
@@ -184,6 +188,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /company
|
||||
|
||||
app.get(`${basePath}/company`, async (req, res) => {
|
||||
try {
|
||||
const companies = await db.listCompanies(req.user.id);
|
||||
@@ -194,6 +200,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region POST /company
|
||||
|
||||
app.post(`${basePath}/company`, async (req, res) => {
|
||||
const body = parseCompanyBody(req.body);
|
||||
if (body.error) {
|
||||
@@ -218,6 +228,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /company/history:
|
||||
@@ -333,6 +345,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /company/history
|
||||
|
||||
app.get(`${basePath}/company/history`, async (req, res) => {
|
||||
try {
|
||||
requireSelectedCompany(req);
|
||||
@@ -360,6 +374,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region POST /company/history
|
||||
|
||||
app.post(`${basePath}/company/history`, async (req, res) => {
|
||||
try {
|
||||
requireSelectedCompany(req);
|
||||
@@ -382,6 +400,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /company/import:
|
||||
@@ -446,6 +466,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /company/import
|
||||
|
||||
app.post(
|
||||
`${basePath}/company/import`,
|
||||
uploadCompanyImportFile,
|
||||
@@ -578,6 +600,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
);
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /company/{id}:
|
||||
@@ -679,6 +703,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region PUT /company/:id
|
||||
|
||||
app.put(`${basePath}/company/:id`, async (req, res) => {
|
||||
const parsedId = parseCompanyId(req.params.id);
|
||||
if (parsedId.error) {
|
||||
@@ -700,6 +726,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region DELETE /company/:id
|
||||
|
||||
app.delete(`${basePath}/company/:id`, async (req, res) => {
|
||||
const parsedId = parseCompanyId(req.params.id);
|
||||
if (parsedId.error) {
|
||||
@@ -714,4 +744,6 @@ export function register(app, basePath = '') {
|
||||
res.status(500).json({ error: 'Failed to delete company' });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user