UNPKG

json-api-nestjs

Version:
55 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.patchRelationship = patchRelationship; const swagger_1 = require("@nestjs/swagger"); const zod_openapi_1 = require("@anatine/zod-openapi"); const types_1 = require("../../types"); const utils_1 = require("../utils"); const zod_1 = require("../../zod"); function patchRelationship(controller, descriptor, entity, mapEntity, methodName) { const entityName = entity.name; const { relations, primaryColumnType } = (0, utils_1.getEntityMapProps)(mapEntity, entity); (0, swagger_1.ApiOperation)({ summary: `Update list of relation for resource "${entityName}"`, operationId: `${controller.constructor.name}_${methodName}`, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiParam)({ name: 'id', required: true, type: primaryColumnType === types_1.TypeField.number ? 'integer' : 'string', description: `ID of resource "${entityName}"`, })(controller, methodName, descriptor); (0, swagger_1.ApiParam)({ name: 'relName', required: true, type: 'string', enum: relations, description: `Relation name of resource "${entityName}"`, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiBody)({ description: `Json api schema for update "${entityName}" item`, schema: (0, zod_openapi_1.generateSchema)(zod_1.zodPatchRelationship), required: true, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiResponse)({ status: 200, schema: utils_1.schemaTypeForRelation, description: `Item/s of relation for "${entityName}" has been updated`, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiResponse)({ status: 400, description: 'Wrong url parameters', schema: utils_1.errorSchema, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiResponse)({ status: 422, description: 'Incorrect type for relation', schema: utils_1.errorSchema, })(controller.prototype, methodName, descriptor); (0, swagger_1.ApiResponse)({ status: 404, description: 'Resource not found ', schema: utils_1.errorSchema, })(controller.prototype, methodName, descriptor); } //# sourceMappingURL=patch-relationship.js.map