ncrudify
Version:
Configurable CRUD module for NestJS and Mongoose.
254 lines • 9.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrudifyRoutes = void 0;
const common_1 = require("@nestjs/common");
const crudify_routesdecorator_1 = require("./crudify.routesdecorator");
var CrudifyRoutes;
(function (CrudifyRoutes) {
function routes(options) {
return [
RouteFindAll(options),
RouteCount(options),
RouteRestore(options),
RouteFindOne(options),
RouteCreate(options),
RouteCreateBulk(options),
RoutePatchBulk(options),
RouteRestoreBulk(options),
RoutePatch(options),
RoutePut(options),
RouteDeleteBulk(options),
RouteDelete(options),
RouteDeleteSoft(options),
];
}
CrudifyRoutes.routes = routes;
function RouteFindAll(options) {
const methodName = "findAll";
return {
methodName,
httpMethod: common_1.Get,
path: "/",
parameters: [{ index: 0, decorator: (0, common_1.Query)(), type: Object }],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteCount(options) {
const methodName = "count";
return {
methodName,
httpMethod: common_1.Get,
path: "/count",
parameters: [],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteFindOne(options) {
const methodName = "findOne";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Get,
path: "/:id",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteCreate(options) {
const methodName = "create";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Post,
path: "/",
parameters: [
{
index: 0,
decorator: (0, common_1.Body)(),
type: options.model.cdto || options.model.type,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteCreateBulk(options) {
const methodName = "createBulk";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Post,
path: "/bulk",
parameters: [
{
index: 0,
decorator: (0, common_1.Body)(),
type: [options.model.cdto || options.model.type],
description: `Array of ${name} resources to create`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RoutePatch(options) {
const methodName = "update";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Patch,
path: "/:id",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
{
index: 1,
decorator: (0, common_1.Body)(),
type: options.model.udto || options.model.type,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RoutePatchBulk(options) {
const methodName = "updateBulk";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Patch,
path: "/bulk",
parameters: [
{
index: 0,
decorator: (0, common_1.Body)(),
type: Object,
description: `Object containing filter and data to update multiple ${name} resources`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RoutePut(options) {
const methodName = "put";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Put,
path: "/:id",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
{
index: 1,
decorator: (0, common_1.Body)(),
type: options.model.udto || options.model.type,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteDelete(options) {
const methodName = "delete";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Delete,
path: "/:id",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteDeleteBulk(options) {
const methodName = "deleteBulk";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Delete,
path: "/bulk",
parameters: [
{
index: 0,
decorator: (0, common_1.Body)(),
type: Object,
description: `Object containing filter and data to delete multiple ${name} resources`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteDeleteSoft(options) {
const methodName = "deleteSoft";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Delete,
path: "/:id/soft",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteRestore(options) {
const methodName = "restore";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Delete,
path: "/:id/restore",
parameters: [
{
index: 0,
decorator: (0, common_1.Param)("id"),
type: String,
description: `ID of the ${name} resource`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
function RouteRestoreBulk(options) {
const methodName = "restoreBulk";
const name = options.model.type.name.toLowerCase();
return {
methodName,
httpMethod: common_1.Patch,
path: "/bulk/restore",
parameters: [
{
index: 0,
decorator: (0, common_1.Body)(),
type: Object,
description: `Object containing filter to restore multiple ${name} resources`,
},
],
decorators: crudify_routesdecorator_1.CrudifyRoutesDecorator.getDecorators(options, methodName),
};
}
})(CrudifyRoutes || (exports.CrudifyRoutes = CrudifyRoutes = {}));
//# sourceMappingURL=crudify.routes.js.map