u
This commit is contained in:
@@ -2,6 +2,8 @@ import express from 'express';
|
||||
import * as db from '../../db/brand.js';
|
||||
import { emit } from '../sse.js';
|
||||
|
||||
// #region Helpers
|
||||
|
||||
const AVIF_BODY_LIMIT = 10 * 1024 * 1024;
|
||||
|
||||
function requireSelectedCompany(req) {
|
||||
@@ -35,6 +37,8 @@ function emitBrandSignal(req, brandId = null) {
|
||||
emit('brand', { companyId, data: { sender: typeof clientId === 'string' ? clientId : '', brandId } });
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* Registers brand routes for the authenticated user's selected company.
|
||||
* @param {import('express').Application} app
|
||||
@@ -120,6 +124,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region GET /brand
|
||||
|
||||
app.get(`${basePath}/brand`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -169,6 +175,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /brand:
|
||||
@@ -246,6 +254,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /brand
|
||||
|
||||
app.post(`${basePath}/brand`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -268,6 +278,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /brand/{id}:
|
||||
@@ -363,6 +375,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region PATCH /brand/:id
|
||||
|
||||
app.patch(`${basePath}/brand/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -390,6 +404,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /brand/{id}:
|
||||
@@ -444,6 +460,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region DELETE /brand/:id
|
||||
|
||||
app.delete(`${basePath}/brand/:id`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -466,6 +484,8 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /brand/{id}/image:
|
||||
@@ -615,6 +635,8 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
// #region POST /brand/:id/image
|
||||
|
||||
app.post(
|
||||
`${basePath}/brand/:id/image`,
|
||||
express.raw({ type: ['image/avif', 'image/webp', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
|
||||
@@ -646,6 +668,10 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
);
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region DELETE /brand/:id/image
|
||||
|
||||
app.delete(`${basePath}/brand/:id/image`, async (req, res) => {
|
||||
const selected = requireSelectedCompany(req);
|
||||
if (selected.error) {
|
||||
@@ -667,4 +693,6 @@ export function register(app, basePath = '') {
|
||||
res.status(status).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user