u
This commit is contained in:
@@ -40,9 +40,97 @@ function companyErrorStatus(error) {
|
||||
*/
|
||||
export function register(app, basePath = '') {
|
||||
/**
|
||||
* @route GET /company
|
||||
* @description Lists companies for the authenticated user.
|
||||
* @returns {Object} 200 - `{ companies }`
|
||||
* @openapi
|
||||
* /company:
|
||||
* get:
|
||||
* tags: [Company]
|
||||
* summary: List companies
|
||||
* description: Lists companies for the authenticated user.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: company/list.md
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Company list
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* companies:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Company'
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* post:
|
||||
* tags: [Company]
|
||||
* summary: Create company
|
||||
* description: Creates a company and selects it for the current user.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: company/create.md
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [iso639, name, taxrate, reducedtaxrate]
|
||||
* properties:
|
||||
* iso639:
|
||||
* type: string
|
||||
* name:
|
||||
* type: string
|
||||
* taxrate:
|
||||
* type: number
|
||||
* reducedtaxrate:
|
||||
* type: number
|
||||
* example:
|
||||
* iso639: de
|
||||
* name: Acme GmbH
|
||||
* taxrate: 19
|
||||
* reducedtaxrate: 7
|
||||
* responses:
|
||||
* 201:
|
||||
* description: Created; selected company updated
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* company:
|
||||
* $ref: '#/components/schemas/Company'
|
||||
* user:
|
||||
* $ref: '#/components/schemas/User'
|
||||
* 400:
|
||||
* description: Validation error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 409:
|
||||
* description: Company name not available
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
app.get(`${basePath}/company`, async (req, res) => {
|
||||
try {
|
||||
@@ -54,15 +142,6 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @route POST /company
|
||||
* @description Creates a company.
|
||||
* @body {string} iso639
|
||||
* @body {string} name
|
||||
* @body {number} taxrate
|
||||
* @body {number} reducedtaxrate
|
||||
* @returns {Object} 201 - `{ company }`
|
||||
*/
|
||||
app.post(`${basePath}/company`, async (req, res) => {
|
||||
const body = parseCompanyBody(req.body);
|
||||
if (body.error) {
|
||||
@@ -83,9 +162,105 @@ export function register(app, basePath = '') {
|
||||
});
|
||||
|
||||
/**
|
||||
* @route PUT /company/:id
|
||||
* @description Updates a company.
|
||||
* @returns {Object} 200 - `{ company }`
|
||||
* @openapi
|
||||
* /company/{id}:
|
||||
* put:
|
||||
* tags: [Company]
|
||||
* summary: Update company
|
||||
* description: Updates a company.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: company/update.md
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [iso639, name, taxrate, reducedtaxrate]
|
||||
* properties:
|
||||
* iso639:
|
||||
* type: string
|
||||
* name:
|
||||
* type: string
|
||||
* taxrate:
|
||||
* type: number
|
||||
* reducedtaxrate:
|
||||
* type: number
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Updated
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* company:
|
||||
* $ref: '#/components/schemas/Company'
|
||||
* 400:
|
||||
* description: Validation error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 404:
|
||||
* description: Company not found
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 409:
|
||||
* description: Company name not available
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* delete:
|
||||
* tags: [Company]
|
||||
* summary: Delete company
|
||||
* description: Deletes a company.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: company/delete.md
|
||||
* parameters:
|
||||
* - in: path
|
||||
* name: id
|
||||
* required: true
|
||||
* schema:
|
||||
* type: integer
|
||||
* responses:
|
||||
* 204:
|
||||
* description: Deleted
|
||||
* 400:
|
||||
* description: Invalid id
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 401:
|
||||
* description: Unauthorized
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
* 500:
|
||||
* description: Server error
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* $ref: '#/components/schemas/Error'
|
||||
*/
|
||||
app.put(`${basePath}/company/:id`, async (req, res) => {
|
||||
const parsedId = parseCompanyId(req.params.id);
|
||||
@@ -108,11 +283,6 @@ export function register(app, basePath = '') {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @route DELETE /company/:id
|
||||
* @description Deletes a company.
|
||||
* @returns {Object} 204 - No content
|
||||
*/
|
||||
app.delete(`${basePath}/company/:id`, async (req, res) => {
|
||||
const parsedId = parseCompanyId(req.params.id);
|
||||
if (parsedId.error) {
|
||||
|
||||
Reference in New Issue
Block a user