Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
[key]: {
...baseBodyArg,
index: parsedBody.index,
},
},
this.target,
name,
);
/* istanbul ignore else */
if (isEqual(override, 'createManyBase')) {
const paramTypes = R.getRouteArgsTypes(this.targetProto, name);
const metatype = paramTypes[parsedBody.index];
const types = [String, Boolean, Number, Array, Object];
const toCopy =
isIn(metatype, types) || /* istanbul ignore next */ isNil(metatype);
/* istanbul ignore else */
if (toCopy) {
const baseParamTypes = R.getRouteArgsTypes(this.targetProto, override);
const baseMetatype = baseParamTypes[1];
paramTypes.splice(parsedBody.index, 1, baseMetatype);
R.setRouteArgsTypes(paramTypes, this.targetProto, name);
}
}
}
}
private setRouteArgsTypes(name: BaseRouteName) {
if (isEqual(name, 'createManyBase')) {
const bulkDto = Validation.createBulkDto(this.options);
R.setRouteArgsTypes([Object, bulkDto], this.targetProto, name);
} else if (isIn(name, ['createOneBase', 'updateOneBase', 'replaceOneBase'])) {
const action = this.routeNameAction(name);
const dto = this.options.dto[action] || this.modelType;
R.setRouteArgsTypes([Object, dto], this.targetProto, name);
} else {
R.setRouteArgsTypes([Object], this.targetProto, name);
}
}
private setRouteArgs(name: BaseRouteName) {
let rest = {};
const routes: BaseRouteName[] = [
'createManyBase',
'createOneBase',
'updateOneBase',
'replaceOneBase',
];
if (isIn(name, routes)) {
const action = this.routeNameAction(name);
const hasDto = !isNil(this.options.dto[action]);
const { UPDATE, CREATE } = CrudValidationGroups;
const groupEnum = isIn(name, ['updateOneBase', 'replaceOneBase']) ? UPDATE : CREATE;
const group = !hasDto ? groupEnum : undefined;
rest = R.setBodyArg(1, [Validation.getValidationPipe(this.options, group)]);
}
R.setRouteArgs({ ...R.setParsedRequestArg(0), ...rest }, this.target, name);
}
overrideParsedBodyDecorator(override, name) {
const allowed = [
'createManyBase',
'createOneBase',
'updateOneBase',
'replaceOneBase',
];
const withBody = util_1.isIn(override, allowed);
const parsedBody = reflection_helper_1.R.getParsedBody(this.targetProto[name]);
if (withBody && parsedBody) {
const baseKey = `${route_paramtypes_enum_1.RouteParamtypes.BODY}:1`;
const key = `${route_paramtypes_enum_1.RouteParamtypes.BODY}:${parsedBody.index}`;
const baseRouteArgs = reflection_helper_1.R.getRouteArgs(this.target, override);
const routeArgs = reflection_helper_1.R.getRouteArgs(this.target, name);
const baseBodyArg = baseRouteArgs[baseKey];
reflection_helper_1.R.setRouteArgs(Object.assign({}, routeArgs, { [key]: Object.assign({}, baseBodyArg, { index: parsedBody.index }) }), this.target, name);
if (util_1.isEqual(override, 'createManyBase')) {
const paramTypes = reflection_helper_1.R.getRouteArgsTypes(this.targetProto, name);
const metatype = paramTypes[parsedBody.index];
const types = [String, Boolean, Number, Array, Object];
const toCopy = util_1.isIn(metatype, types) || util_1.isNil(metatype);
if (toCopy) {
const baseParamTypes = reflection_helper_1.R.getRouteArgsTypes(this.targetProto, override);
const baseMetatype = baseParamTypes[1];
setSwaggerPathParams(name) {
const metadata = swagger_helper_1.Swagger.getParams(this.targetProto[name]);
const withoutPrimary = [
'createManyBase',
'createOneBase',
'getManyBase',
];
const params = util_1.isIn(name, withoutPrimary)
? util_1.objKeys(this.options.params).reduce((a, c) => this.options.params[c].primary ? a : Object.assign({}, a, { [c]: this.options.params[c] }), {})
: this.options.params;
const pathParamsMeta = swagger_helper_1.Swagger.createPathParasmMeta(params);
swagger_helper_1.Swagger.setParams([...metadata, ...pathParamsMeta], this.targetProto[name]);
}
setSwaggerQueryParams(name) {
private setSwaggerPathParams(name: BaseRouteName) {
const metadata = Swagger.getParams(this.targetProto[name]);
const withoutPrimary: BaseRouteName[] = [
'createManyBase',
'createOneBase',
'getManyBase',
];
const params = isIn(name, withoutPrimary)
? objKeys(this.options.params).reduce(
(a, c) =>
this.options.params[c].primary ? a : { ...a, [c]: this.options.params[c] },
{},
)
: this.options.params;
const pathParamsMeta = Swagger.createPathParasmMeta(params);
Swagger.setParams([...metadata, ...pathParamsMeta], this.targetProto[name]);
}
private setRouteArgs(name: BaseRouteName) {
let rest = {};
const routes: BaseRouteName[] = [
'createManyBase',
'createOneBase',
'updateOneBase',
'replaceOneBase',
];
if (isIn(name, routes)) {
const action = this.routeNameAction(name);
const hasDto = !isNil(this.options.dto[action]);
const { UPDATE, CREATE } = CrudValidationGroups;
const groupEnum = isIn(name, ['updateOneBase', 'replaceOneBase']) ? UPDATE : CREATE;
const group = !hasDto ? groupEnum : undefined;
rest = R.setBodyArg(1, [Validation.getValidationPipe(this.options, group)]);
}
R.setRouteArgs({ ...R.setParsedRequestArg(0), ...rest }, this.target, name);
}
'replaceOneBase',
];
const withBody = util_1.isIn(override, allowed);
const parsedBody = reflection_helper_1.R.getParsedBody(this.targetProto[name]);
if (withBody && parsedBody) {
const baseKey = `${route_paramtypes_enum_1.RouteParamtypes.BODY}:1`;
const key = `${route_paramtypes_enum_1.RouteParamtypes.BODY}:${parsedBody.index}`;
const baseRouteArgs = reflection_helper_1.R.getRouteArgs(this.target, override);
const routeArgs = reflection_helper_1.R.getRouteArgs(this.target, name);
const baseBodyArg = baseRouteArgs[baseKey];
reflection_helper_1.R.setRouteArgs(Object.assign({}, routeArgs, { [key]: Object.assign({}, baseBodyArg, { index: parsedBody.index }) }), this.target, name);
if (util_1.isEqual(override, 'createManyBase')) {
const paramTypes = reflection_helper_1.R.getRouteArgsTypes(this.targetProto, name);
const metatype = paramTypes[parsedBody.index];
const types = [String, Boolean, Number, Array, Object];
const toCopy = util_1.isIn(metatype, types) || util_1.isNil(metatype);
if (toCopy) {
const baseParamTypes = reflection_helper_1.R.getRouteArgsTypes(this.targetProto, override);
const baseMetatype = baseParamTypes[1];
paramTypes.splice(parsedBody.index, 1, baseMetatype);
reflection_helper_1.R.setRouteArgsTypes(paramTypes, this.targetProto, name);
}
}
}
}
getPrimaryParam() {
setRouteArgs(name) {
let rest = {};
const toValidate = [
'createManyBase',
'createOneBase',
'updateOneBase',
'replaceOneBase',
];
if (util_1.isIn(name, toValidate)) {
const group = util_1.isEqual(name, 'updateOneBase') || util_1.isEqual(name, 'replaceOneBase')
? enums_1.CrudValidationGroups.UPDATE
: enums_1.CrudValidationGroups.CREATE;
rest = reflection_helper_1.R.setBodyArg(1, [validation_helper_1.Validation.getValidationPipe(this.options, group)]);
}
reflection_helper_1.R.setRouteArgs(Object.assign({}, reflection_helper_1.R.setParsedRequestArg(0), rest), this.target, name);
}
setRouteArgsTypes(name) {
private overrideParsedBodyDecorator(override: BaseRouteName, name: string) {
const allowed = [
'createManyBase',
'createOneBase',
'updateOneBase',
'replaceOneBase',
] as BaseRouteName[];
const withBody = isIn(override, allowed);
const parsedBody = R.getParsedBody(this.targetProto[name]);
if (withBody && parsedBody) {
const baseKey = `${RouteParamtypes.BODY}:1`;
const key = `${RouteParamtypes.BODY}:${parsedBody.index}`;
const baseRouteArgs = R.getRouteArgs(this.target, override);
const routeArgs = R.getRouteArgs(this.target, name);
const baseBodyArg = baseRouteArgs[baseKey];
R.setRouteArgs(
{
...routeArgs,
[key]: {
...baseBodyArg,
index: parsedBody.index,
},
},