src/api/v2/projects/assettypes/asset.types.routes.tsmodifiedimport express from "express";
import { Authorities } from "../../../auth/authorities.types";
import { hasRolesOrProjectAccess } from "../../../../middleware/authorisation";
import {
listAssetTypes,
getAssetType,
createAssetType,
} from "./asset.types.controller";
import {
validateAssetTypeIdParam,
validateCreateRequest,
validateListAssetTypesRequest,
} from "./asset.types.validator";
const router = express.Router({ mergeParams: true });
/**
* @swagger
* /api/v2/projects/{projectId}/asset-types:
* get:
* summary: List all asset types for a project.
* tags: [Asset Types]
* description: Returns the list of asset types for the given project.
* parameters:
* - in: path
* name: projectId
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: List of asset types.
* content:
* application/json:
* schema:
* type: array
* items:
* $ref: "#/components/schemas/AssetType"
* 400:
* description: Invalid request.
* 401:
* description: Unauthorized.
* 404:
* description: Project not found.
* 500:
* description: Server error.
*/
router.get("", validateListAssetTypesRequest, hasRolesOrProjectAccess([Authorities.INTERNAL_ROLE], [Authorities.PROJECT_VIEW]), listAssetTypes);
/**
* @swagger
* /api/v2/projects/{projectId}/asset-types/{assetTypeId}:
* get:
* summary: Get an asset type by ID.
* tags: [Asset Types]
* parameters:
* - in: path
* name: projectId
* required: true
* schema:
* type: string
* format: uuid
* - in: path
* name: assetTypeId
* required: true
* schema:
* type: string
* format: uuid
* responses:
* 200:
* description: Asset type details.
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/AssetType"
* 400:
* description: Invalid request.
* 401:
* description: Unauthorized.
* 404:
* description: Not found.
* 500:
* description: Server error.
*/
router.get("/:assetTypeId", validateAssetTypeIdParam, hasRolesOrProjectAccess([Authorities.INTERNAL_ROLE], [Authorities.PROJECT_VIEW]), getAssetType);
/**
* @swagger
* /api/v2/projects/{projectId}/asset-types:
* post:
* summary: Create an asset type.
* tags: [Asset Types]
* parameters:
* - in: path
* name: projectId
* required: true
* schema:
* type: string
* format: uuid
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* required: [name]
* properties:
* name:
* type: string
* description: Name of the asset type.
* description:
* type: string
* nullable: true
* description: Optional description of the asset type.
* example:
* name: "Pump"
* description: "Mechanical pumps and related equipment"
* responses:
* 201:
* description: Asset type created.
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/AssetType"
* 400:
* description: Invalid request.
* 401:
* description: Unauthorized.
* 404:
* description: Project not found.
* 500:
* description: Server error.
*/
router.post("", validateCreateRequest, hasRolesOrProjectAccess([Authorities.INTERNAL_ROLE], [Authorities.PROJECT_EDIT]), createAssetType);
export default router;