|
| 1 | +import Debug from 'debug' |
| 2 | +import { Response } from 'express' |
| 3 | +import { AplCatalogRequest, OpenApiRequestExt } from 'src/otomi-models' |
| 4 | + |
| 5 | +const debug = Debug('otomi:api:v2:catalogs') |
| 6 | + |
| 7 | +/** |
| 8 | + * GET /v2/catalogs/{catalogId} |
| 9 | + * Get a specific catalog |
| 10 | + */ |
| 11 | +export const getAplCatalog = (req: OpenApiRequestExt, res: Response): void => { |
| 12 | + const { catalogId } = req.params |
| 13 | + debug(`getAplCatalog(${catalogId})`) |
| 14 | + const data = req.otomi.getAplCatalog(decodeURIComponent(catalogId)) |
| 15 | + res.json(data) |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * PUT /v2/catalogs/{catalogId} |
| 20 | + * Edit a catalog |
| 21 | + */ |
| 22 | +export const editAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => { |
| 23 | + const { catalogId } = req.params |
| 24 | + debug(`editAplCatalog(${catalogId})`) |
| 25 | + const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest) |
| 26 | + res.json(data) |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * PATCH /v2/catalogs/{catalogId} |
| 31 | + * Partially update a catalog |
| 32 | + */ |
| 33 | +export const patchAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => { |
| 34 | + const { catalogId } = req.params |
| 35 | + debug(`patchAplCatalog(${catalogId})`) |
| 36 | + const data = await req.otomi.editAplCatalog(decodeURIComponent(catalogId), req.body as AplCatalogRequest, true) |
| 37 | + res.json(data) |
| 38 | +} |
| 39 | + |
| 40 | +/** |
| 41 | + * DELETE /v2/catalogs/{catalogId} |
| 42 | + * Delete a catalog |
| 43 | + */ |
| 44 | +export const deleteAplCatalog = async (req: OpenApiRequestExt, res: Response): Promise<void> => { |
| 45 | + const { catalogId } = req.params |
| 46 | + debug(`deleteAplCatalog(${catalogId})`) |
| 47 | + await req.otomi.deleteAplCatalog(decodeURIComponent(catalogId)) |
| 48 | + res.json({}) |
| 49 | +} |
0 commit comments